Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 6746c65

Browse files
committed
Adds a test for include: allAssets
1 parent 64b414c commit 6746c65

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,54 @@ module.exports = ({descriptionPrefix, webpack, HtmlWebpackPlugin}) => {
450450
});
451451
compiler.outputFileSystem = new MemoryFileSystem();
452452
});
453+
454+
// TODO: Is this testing the right thing? We might need a test around, e.g.,
455+
// using a different plugin that adds assets without also creating chunks.
456+
it(`should pull in additional assets when set to 'allAssets'`, function(done) {
457+
const compiler = webpack({
458+
// Use "the" as the prefix for the entry names, to ensure that they're
459+
// sorted after either 0.js or home.js (depending on the webpack version).
460+
entry: {
461+
theFirstEntry: path.join(__dirname, 'fixtures', 'file.js'),
462+
theSecondEntry: path.join(__dirname, 'fixtures', 'vendor.js'),
463+
},
464+
output: {
465+
path: OUTPUT_DIR,
466+
filename: '[name].js',
467+
},
468+
plugins: [
469+
new HtmlWebpackPlugin(),
470+
new PreloadPlugin({
471+
include: 'allAssets',
472+
}),
473+
]
474+
}, function(err, result) {
475+
expect(err).toBeFalsy(err);
476+
expect(result.compilation.errors.length).toBe(0,
477+
result.compilation.errors.join('\n=========\n'));
478+
479+
const html = result.compilation.assets['index.html'].source();
480+
const dom = new JSDOM(html);
481+
482+
const links = dom.window.document.head.querySelectorAll('link');
483+
expect(links.length).toBe(3);
484+
expect(links[0].getAttribute('rel')).toBe('preload');
485+
expect(links[0].getAttribute('as')).toBe('script');
486+
// There's a difference in the output when run in webpack v3 and v4.
487+
// v3 has compilation.chunks[0].files: ['0.js']
488+
// v4 has compilation.chunks[0].files: ['home.js']
489+
expect(['0.js', 'home.js']).toContain(links[0].getAttribute('href'));
490+
expect(links[1].getAttribute('rel')).toBe('preload');
491+
expect(links[1].getAttribute('as')).toBe('script');
492+
expect(links[1].getAttribute('href')).toBe('theFirstEntry.js');
493+
expect(links[2].getAttribute('rel')).toBe('preload');
494+
expect(links[2].getAttribute('as')).toBe('script');
495+
expect(links[2].getAttribute('href')).toBe('theSecondEntry.js');
496+
497+
done();
498+
});
499+
compiler.outputFileSystem = new MemoryFileSystem();
500+
});
453501
});
454502

455503
describe(`${descriptionPrefix} When using an empty config, it`, function() {

0 commit comments

Comments
 (0)