@@ -23,7 +23,7 @@ const webpack = require('webpack');
2323const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
2424const PreloadPlugin = require ( '../' ) ;
2525const OUTPUT_DIR = path . join ( __dirname , 'dist' ) ;
26- // const ExtractTextPlugin = require('extract-text-webpack-plugin');
26+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
2727
2828describe ( 'PreloadPlugin preloads or prefetches async chunks' , function ( ) {
2929 it ( 'adds preload tags to async chunks' , function ( done ) {
@@ -375,62 +375,62 @@ describe('PreloadPlugin filters chunks', function() {
375375 } ) ;
376376} ) ;
377377
378- // describe('PreloadPlugin preloads all assets', function() {
379- // it('adds preload tags', function(done) {
380- // const compiler = webpack({
381- // entry: path.join(__dirname, 'fixtures', 'load-css.js'),
382- // output: {
383- // path: OUTPUT_DIR,
384- // filename: 'bundle.js',
385- // chunkFilename: 'chunk.[chunkhash].js',
386- // publicPath: '/',
387- // },
388- // module: {
389- // rules: [
390- // {
391- // test: /\.css$/,
392- // loader: ExtractTextPlugin.extract({
393- // fallback: 'css-loader',
394- // use: [
395- // {
396- // loader: 'css-loader',
397- // },
398- // ],
399- // }),
400- // },
401- // {
402- // test: /\.woff2?$/,
403- // loader: 'file-loader',
404- // options: {
405- // name: '[name].[ext]',
406- // },
407- // },
408- // ],
409- // },
410- // plugins: [
411- // new ExtractTextPlugin({
412- // filename: 'style.css',
413- // allChunks: true,
414- // }),
415- // new HtmlWebpackPlugin(),
416- // new PreloadPlugin({
417- // rel: 'preload',
418- // include: 'allAssets'
419- // }),
420- // ]
421- // }, function(err, result) {
422- // expect(err).toBeFalsy();
423- // expect(JSON.stringify(result.compilation.errors)).toBe('[]');
424- // const html = result.compilation.assets['index.html'].source();
425- // expect(html).toContain('<link rel="preload" as="script" href="/chunk');
426- // expect(html).toContain('<link rel="preload" as="script" href="/bundle.js"');
427- // expect(html).toContain('<link rel="preload" as="style" href="/style.css"');
428- // expect(html).toContain('<link rel="preload" as="font" crossorigin="crossorigin" href="/font.woff2"');
429- // done();
430- // });
431- // compiler.outputFileSystem = new MemoryFileSystem();
432- // });
433- // });
378+ describe ( 'PreloadPlugin preloads all assets' , function ( ) {
379+ it ( 'adds preload tags' , function ( done ) {
380+ const compiler = webpack ( {
381+ entry : path . join ( __dirname , 'fixtures' , 'load-css.js' ) ,
382+ output : {
383+ path : OUTPUT_DIR ,
384+ filename : 'bundle.js' ,
385+ chunkFilename : 'chunk.[chunkhash].js' ,
386+ publicPath : '/' ,
387+ } ,
388+ module : {
389+ rules : [
390+ {
391+ test : / \. c s s $ / ,
392+ loader : ExtractTextPlugin . extract ( {
393+ fallback : 'css-loader' ,
394+ use : [
395+ {
396+ loader : 'css-loader' ,
397+ } ,
398+ ] ,
399+ } ) ,
400+ } ,
401+ {
402+ test : / \. w o f f 2 ? $ / ,
403+ loader : 'file-loader' ,
404+ options : {
405+ name : '[name].[ext]' ,
406+ } ,
407+ } ,
408+ ] ,
409+ } ,
410+ plugins : [
411+ new ExtractTextPlugin ( {
412+ filename : 'style.css' ,
413+ allChunks : true ,
414+ } ) ,
415+ new HtmlWebpackPlugin ( ) ,
416+ new PreloadPlugin ( {
417+ rel : 'preload' ,
418+ include : 'allAssets'
419+ } ) ,
420+ ]
421+ } , function ( err , result ) {
422+ expect ( err ) . toBeFalsy ( ) ;
423+ expect ( JSON . stringify ( result . compilation . errors ) ) . toBe ( '[]' ) ;
424+ const html = result . compilation . assets [ 'index.html' ] . source ( ) ;
425+ expect ( html ) . toContain ( '<link rel="preload" as="script" href="/chunk' ) ;
426+ expect ( html ) . toContain ( '<link rel="preload" as="script" href="/bundle.js"' ) ;
427+ expect ( html ) . toContain ( '<link rel="preload" as="style" href="/style.css"' ) ;
428+ expect ( html ) . toContain ( '<link rel="preload" as="font" crossorigin="crossorigin" href="/font.woff2"' ) ;
429+ done ( ) ;
430+ } ) ;
431+ compiler . outputFileSystem = new MemoryFileSystem ( ) ;
432+ } ) ;
433+ } ) ;
434434
435435describe ( 'filtering unwanted files' , function ( ) {
436436 it ( 'does not include map files to be preloaded' , function ( done ) {
0 commit comments