Skip to content

Commit bd0fa9c

Browse files
test: multi compiler mode
1 parent 2b49ba9 commit bd0fa9c

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed

test/__snapshots__/logging.test.js.snap.webpack4

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,49 @@ Child success:
5252
[./svg.svg] x bytes {main} [built]"
5353
`;
5454

55+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stderr 1`] = `""`;
56+
57+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stdout 1`] = `
58+
"Hash: xxxx
59+
Version: webpack x.x.x
60+
Child
61+
Hash: xxxx
62+
Time: Xms
63+
Built at: x
64+
Asset Size Chunks Chunk Names
65+
bundle.js x KiB main [emitted] main
66+
Entrypoint main = bundle.js
67+
[./broken.js] x bytes {main} [built] [failed] [1 error]
68+
69+
ERROR in ./broken.js 1:3
70+
Module parse failed: Unexpected token (1:3)
71+
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
72+
> 1()2()3()
73+
|
74+
Child
75+
Hash: xxxx
76+
Time: Xms
77+
Built at: x
78+
Asset Size Chunks Chunk Names
79+
bundle.js x KiB main [emitted] main
80+
Entrypoint main = bundle.js
81+
[./warning.js] x bytes {main} [built]
82+
83+
WARNING in Warning
84+
Child
85+
Hash: xxxx
86+
Time: Xms
87+
Built at: x
88+
Asset Size Chunks Chunk Names
89+
bundle.js x KiB main [emitted] main
90+
index.html x bytes [emitted]
91+
svg.svg x KiB [emitted]
92+
Entrypoint main = bundle.js
93+
[./foo.js] x bytes {main} [built]
94+
[./index.html] x bytes {main} [built]
95+
[./svg.svg] x bytes {main} [built]"
96+
`;
97+
5598
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stderr 1`] = `""`;
5699

57100
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stdout 1`] = `

test/__snapshots__/logging.test.js.snap.webpack5

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,38 @@ success:
4545
success (webpack x.x.x) compiled successfully in x ms"
4646
`;
4747

48+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stderr 1`] = `""`;
49+
50+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stdout 1`] = `
51+
"asset bundle.js x bytes [emitted] (name: main)
52+
./broken.js x bytes [built] [code generated] [1 error]
53+
54+
ERROR in ./broken.js 1:3
55+
Module parse failed: Unexpected token (1:3)
56+
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
57+
> 1()2()3()
58+
|
59+
60+
webpack x.x.x compiled with 1 error in x ms
61+
62+
asset bundle.js x bytes [emitted] (name: main)
63+
./warning.js x bytes [built] [code generated]
64+
65+
WARNING in Warning
66+
67+
webpack x.x.x compiled with 1 warning in x ms
68+
69+
asset svg.svg x KiB [emitted] [from: svg.svg] (auxiliary name: main)
70+
asset bundle.js x KiB [emitted] (name: main)
71+
asset index.html x bytes [emitted] [from: index.html] (auxiliary name: main)
72+
runtime modules x bytes x modules
73+
cacheable modules x bytes
74+
./foo.js x bytes [built] [code generated]
75+
./svg.svg x bytes [built] [code generated]
76+
./index.html x bytes [built] [code generated]
77+
webpack x.x.x compiled successfully in x ms"
78+
`;
79+
4880
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stderr 1`] = `""`;
4981

5082
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stdout 1`] = `
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
module.exports = [
6+
{
7+
mode: 'development',
8+
context: path.resolve(__dirname),
9+
entry: './broken.js',
10+
output: {
11+
filename: 'bundle.js',
12+
path: path.resolve(__dirname, '../outputs/one-error-one-warning-one-success/js1'),
13+
publicPath: '/static-one/',
14+
},
15+
infrastructureLogging: {
16+
level: 'none'
17+
},
18+
stats: 'normal'
19+
},
20+
{
21+
mode: 'development',
22+
context: path.resolve(__dirname),
23+
entry: './warning.js',
24+
output: {
25+
filename: 'bundle.js',
26+
path: path.resolve(__dirname, '../outputs/one-error-one-warning-one-success/js2'),
27+
publicPath: '/static-two/',
28+
},
29+
plugins: [
30+
{
31+
apply(compiler) {
32+
compiler.hooks.emit.tapAsync('WarningPlugin', (compilation, done) => {
33+
compilation.warnings.push(new Error('Warning'));
34+
35+
done();
36+
})
37+
},
38+
}
39+
],
40+
infrastructureLogging: {
41+
level: 'none'
42+
},
43+
stats: 'normal'
44+
},
45+
{
46+
mode: 'development',
47+
context: path.resolve(__dirname),
48+
entry: './foo.js',
49+
output: {
50+
filename: 'bundle.js',
51+
path: path.resolve(__dirname, 'js3'),
52+
publicPath: '/static-three/',
53+
},
54+
module: {
55+
rules: [
56+
{
57+
test: /\.(svg|html)$/,
58+
loader: 'file-loader',
59+
options: { name: '[name].[ext]' },
60+
},
61+
],
62+
},
63+
infrastructureLogging: {
64+
level: 'none'
65+
},
66+
},
67+
];

test/logging.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,44 @@ describe('logging', () => {
725725
});
726726
});
727727

728+
it('should logging in multi-compiler and respect the "stats" option from configuration #3', (done) => {
729+
let proc;
730+
731+
try {
732+
proc = execa(runner, [], {
733+
stdio: 'pipe',
734+
env: {
735+
WEBPACK_CONFIG: 'webpack.array.one-error-one-warning-one-no',
736+
},
737+
});
738+
} catch (error) {
739+
throw error;
740+
}
741+
742+
let stdout = '';
743+
let stderr = '';
744+
745+
proc.stdout.on('data', (chunk) => {
746+
stdout += chunk.toString();
747+
748+
if (/compiled-for-tests/gi.test(stdout)) {
749+
proc.stdin.write('|exit|');
750+
}
751+
});
752+
753+
proc.stderr.on('data', (chunk) => {
754+
stderr += chunk.toString();
755+
proc.stdin.write('|exit|');
756+
});
757+
758+
proc.on('exit', () => {
759+
expect(stdoutToSnapshot(stdout)).toMatchSnapshot('stdout');
760+
expect(stderrToSnapshot(stderr)).toMatchSnapshot('stderr');
761+
762+
done();
763+
});
764+
});
765+
728766
it('should logging an error in "watch" method', (done) => {
729767
let proc;
730768

0 commit comments

Comments
 (0)