@@ -44,8 +44,8 @@ describe('PreloadPlugin preloads or prefetches async chunks', function() {
4444 expect ( err ) . toBeFalsy ( ) ;
4545 expect ( JSON . stringify ( result . compilation . errors ) ) . toBe ( '[]' ) ;
4646 const html = result . compilation . assets [ 'index.html' ] . source ( ) ;
47- expect ( html ) . toContain ( '<link rel="preload" href="chunk.' ) ;
48- expect ( html ) . not . toContain ( '<link rel="preload" href="bundle.' ) ;
47+ expect ( html ) . toContain ( '<link rel="preload" href="/ chunk.' ) ;
48+ expect ( html ) . not . toContain ( '<link rel="preload" href="/ bundle.' ) ;
4949 done ( ) ;
5050 } ) ;
5151 compiler . outputFileSystem = new MemoryFileSystem ( ) ;
@@ -72,7 +72,33 @@ describe('PreloadPlugin preloads or prefetches async chunks', function() {
7272 expect ( err ) . toBeFalsy ( ) ;
7373 expect ( JSON . stringify ( result . compilation . errors ) ) . toBe ( '[]' ) ;
7474 const html = result . compilation . assets [ 'index.html' ] . source ( ) ;
75- expect ( html ) . toContain ( '<link rel="prefetch" href="chunk.' ) ;
75+ expect ( html ) . toContain ( '<link rel="prefetch" href="/chunk.' ) ;
76+ done ( ) ;
77+ } ) ;
78+ compiler . outputFileSystem = new MemoryFileSystem ( ) ;
79+ } ) ;
80+
81+ it ( 'respects publicPath' , function ( done ) {
82+ const compiler = webpack ( {
83+ entry : {
84+ js : path . join ( __dirname , 'fixtures' , 'file.js' )
85+ } ,
86+ output : {
87+ path : OUTPUT_DIR ,
88+ filename : 'bundle.js' ,
89+ chunkFilename : 'chunk.[chunkhash].js' ,
90+ publicPath : 'http://mycdn.com/' ,
91+ } ,
92+ plugins : [
93+ new HtmlWebpackPlugin ( ) ,
94+ new PreloadPlugin ( )
95+ ]
96+ } , function ( err , result ) {
97+ expect ( err ) . toBeFalsy ( ) ;
98+ expect ( JSON . stringify ( result . compilation . errors ) ) . toBe ( '[]' ) ;
99+ const html = result . compilation . assets [ 'index.html' ] . source ( ) ;
100+ expect ( html ) . toContain ( '<link rel="preload" href="http://mycdn.com/chunk.' ) ;
101+ expect ( html ) . not . toContain ( '<link rel="preload" href="http://mycdn.com/bundle.' ) ;
76102 done ( ) ;
77103 } ) ;
78104 compiler . outputFileSystem = new MemoryFileSystem ( ) ;
@@ -101,8 +127,8 @@ describe('PreloadPlugin preloads normal chunks', function() {
101127 expect ( err ) . toBeFalsy ( ) ;
102128 expect ( JSON . stringify ( result . compilation . errors ) ) . toBe ( '[]' ) ;
103129 const html = result . compilation . assets [ 'index.html' ] . source ( ) ;
104- expect ( html ) . toContain ( '<link rel="preload" href="chunk' ) ;
105- expect ( html ) . toContain ( '<link rel="preload" href="bundle.js"' ) ;
130+ expect ( html ) . toContain ( '<link rel="preload" href="/ chunk' ) ;
131+ expect ( html ) . toContain ( '<link rel="preload" href="/ bundle.js"' ) ;
106132 done ( ) ;
107133 } ) ;
108134 compiler . outputFileSystem = new MemoryFileSystem ( ) ;
@@ -157,8 +183,8 @@ describe('PreloadPlugin filters chunks', function() {
157183 expect ( err ) . toBeFalsy ( ) ;
158184 expect ( JSON . stringify ( result . compilation . errors ) ) . toBe ( '[]' ) ;
159185 const html = result . compilation . assets [ 'index.html' ] . source ( ) ;
160- expect ( html ) . toContain ( '<link rel="preload" href="home' ) ;
161- expect ( html ) . not . toContain ( '<link rel="preload" href="bundle.js"' ) ;
186+ expect ( html ) . toContain ( '<link rel="preload" href="/ home' ) ;
187+ expect ( html ) . not . toContain ( '<link rel="preload" href="/ bundle.js"' ) ;
162188 done ( ) ;
163189 } ) ;
164190 compiler . outputFileSystem = new MemoryFileSystem ( ) ;
0 commit comments