Skip to content

Commit cbf2a6d

Browse files
test: update
1 parent 55cc10d commit cbf2a6d

File tree

5 files changed

+35
-49
lines changed

5 files changed

+35
-49
lines changed

test/e2e/__snapshots__/entry.test.js.snap.webpack4

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ Array [
2222

2323
exports[`entry should work with dynamic entry: page errors 1`] = `Array []`;
2424

25-
exports[`entry should work with empty: console messages 1`] = `
26-
Array [
27-
"[HMR] Waiting for update signal from WDS...",
28-
"Hey.",
29-
"[webpack-dev-server] Hot Module Replacement enabled.",
30-
"[webpack-dev-server] Live Reloading enabled.",
31-
]
32-
`;
33-
34-
exports[`entry should work with empty: page errors 1`] = `Array []`;
35-
3625
exports[`entry should work with multiple entries #2: console messages 1`] = `
3726
Array [
3827
"[HMR] Waiting for update signal from WDS...",
@@ -44,18 +33,6 @@ Array [
4433

4534
exports[`entry should work with multiple entries #2: page errors 1`] = `Array []`;
4635

47-
exports[`entry should work with multiple entries and "dependOn": console messages 1`] = `
48-
Array [
49-
"[HMR] Waiting for update signal from WDS...",
50-
"Bar.",
51-
"[webpack-dev-server] Hot Module Replacement enabled.",
52-
"[webpack-dev-server] Live Reloading enabled.",
53-
"Hey.",
54-
]
55-
`;
56-
57-
exports[`entry should work with multiple entries and "dependOn": page errors 1`] = `Array []`;
58-
5936
exports[`entry should work with multiple entries: console messages 1`] = `
6037
Array [
6138
"[HMR] Waiting for update signal from WDS...",
@@ -67,17 +44,6 @@ Array [
6744

6845
exports[`entry should work with multiple entries: page errors 1`] = `Array []`;
6946

70-
exports[`entry should work with object entry: console messages 1`] = `
71-
Array [
72-
"[HMR] Waiting for update signal from WDS...",
73-
"Hey.",
74-
"[webpack-dev-server] Hot Module Replacement enabled.",
75-
"[webpack-dev-server] Live Reloading enabled.",
76-
]
77-
`;
78-
79-
exports[`entry should work with object entry: page errors 1`] = `Array []`;
80-
8147
exports[`entry should work with single array entry: console messages 1`] = `
8248
Array [
8349
"[HMR] Waiting for update signal from WDS...",

test/e2e/entry.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ describe('entry', () => {
357357
});
358358
await page.addScriptTag({ url: `http://127.0.0.1:${port}/runtime.js` });
359359
await page.addScriptTag({ url: `http://127.0.0.1:${port}/foo.js` });
360+
await page.waitForFunction(() => window.fooChunkLoaded);
360361

361362
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
362363
'console messages'
@@ -426,6 +427,7 @@ describe('entry', () => {
426427
});
427428
await page.addScriptTag({ url: `http://127.0.0.1:${port}/runtime.js` });
428429
await page.addScriptTag({ url: `http://127.0.0.1:${port}/bar.js` });
430+
await page.waitForFunction(() => window.barChunkLoaded);
429431

430432
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
431433
'console messages'
@@ -452,7 +454,7 @@ describe('entry', () => {
452454
const compiler = webpack({
453455
...config,
454456
entry: {
455-
main: {
457+
foo: {
456458
import: entryFirst,
457459
dependOn: 'bar',
458460
},
@@ -494,7 +496,8 @@ describe('entry', () => {
494496
waitUntil: 'networkidle0',
495497
});
496498
await page.addScriptTag({ url: `http://127.0.0.1:${port}/bar.js` });
497-
await page.addScriptTag({ url: `http://127.0.0.1:${port}/main.js` });
499+
await page.addScriptTag({ url: `http://127.0.0.1:${port}/foo.js` });
500+
await page.waitForFunction(() => window.fooChunkLoaded);
498501

499502
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
500503
'console messages'

test/fixtures/client-config/bar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
'use strict';
22

33
console.log('Bar.');
4+
5+
window.barChunkLoaded = true;

test/fixtures/client-config/foo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
'use strict';
22

33
console.log('Hey.');
4+
5+
window.fooChunkLoaded = true;

test/fixtures/client-config/webpack.config.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,36 @@ module.exports = {
2626
{
2727
apply(compiler) {
2828
const pluginName = 'html-generator-plugin-test';
29+
const filename = 'test.html';
2930

3031
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
31-
const { RawSource } = compiler.webpack.sources;
32+
if (compiler.webpack) {
33+
const { RawSource } = compiler.webpack.sources;
3234

33-
compilation.hooks.processAssets.tap(
34-
{
35-
name: pluginName,
36-
stage:
37-
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
38-
},
39-
() => {
40-
const filename = 'test.html';
41-
const source = new RawSource(HTMLContent);
35+
compilation.hooks.processAssets.tap(
36+
{
37+
name: pluginName,
38+
stage:
39+
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
40+
},
41+
() => {
42+
const source = new RawSource(HTMLContent);
4243

43-
compilation.emitAsset(filename, source);
44-
}
45-
);
44+
compilation.emitAsset(filename, source);
45+
}
46+
);
47+
} else {
48+
compilation.hooks.additionalAssets.tap(pluginName, () => {
49+
compilation.emitAsset(filename, {
50+
source() {
51+
return HTMLContent;
52+
},
53+
size() {
54+
return HTMLContent.length;
55+
},
56+
});
57+
});
58+
}
4659
});
4760
},
4861
},

0 commit comments

Comments
 (0)