Skip to content

Commit d90c4f9

Browse files
test: more
1 parent 076b770 commit d90c4f9

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Entrypoint main = bundle.js
5454

5555
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stderr 1`] = `""`;
5656

57+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stderr 2`] = `""`;
58+
5759
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stdout 1`] = `
5860
"Hash: xxxx
5961
Version: webpack x.x.x
@@ -95,6 +97,40 @@ Entrypoint main = bundle.js
9597
[./svg.svg] x bytes {main} [built]"
9698
`;
9799

100+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stdout 2`] = `
101+
"Child
102+
Hash: xxxx
103+
Version: webpack x.x.x
104+
Time: Xms
105+
Built at: x
106+
Asset Size Chunks Chunk Names
107+
bundle.js x KiB main [emitted] main
108+
Entrypoint main = bundle.js
109+
[./broken.js] x bytes {main} [built] [failed] [1 error]
110+
111+
ERROR in ./broken.js 1:3
112+
Module parse failed: Unexpected token (1:3)
113+
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
114+
> 1()2()3()
115+
|
116+
Child
117+
Hash: xxxx
118+
Version: webpack x.x.x
119+
Time: Xms
120+
Built at: x
121+
Asset Size Chunks Chunk Names
122+
bundle.js x KiB main [emitted] main
123+
Entrypoint main = bundle.js
124+
[./warning.js] x bytes {main} [built]
125+
126+
WARNING in Warning
127+
Child
128+
Asset Size Chunks Chunk Names
129+
bundle.js x KiB main [emitted] main
130+
index.html x bytes [emitted]
131+
svg.svg x KiB [emitted]"
132+
`;
133+
98134
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stderr 1`] = `""`;
99135

100136
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ success (webpack x.x.x) compiled successfully in x ms"
4747

4848
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stderr 1`] = `""`;
4949

50+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stderr 2`] = `""`;
51+
5052
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stdout 1`] = `
5153
"asset bundle.js x bytes [emitted] (name: main)
5254
./broken.js x bytes [built] [code generated] [1 error]
@@ -77,6 +79,30 @@ cacheable modules x bytes
7779
webpack x.x.x compiled successfully in x ms"
7880
`;
7981

82+
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration #3: stdout 2`] = `
83+
"asset bundle.js x bytes [emitted] (name: main)
84+
./broken.js x bytes [built] [code generated] [1 error]
85+
86+
ERROR in ./broken.js 1:3
87+
Module parse failed: Unexpected token (1:3)
88+
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
89+
> 1()2()3()
90+
|
91+
92+
webpack x.x.x compiled with 1 error in x ms
93+
94+
asset bundle.js x bytes [emitted] (name: main)
95+
./warning.js x bytes [built] [code generated]
96+
97+
WARNING in Warning
98+
99+
webpack x.x.x compiled with 1 warning in x ms
100+
101+
asset svg.svg x KiB [emitted] [from: svg.svg] (auxiliary name: main)
102+
asset bundle.js x KiB [emitted] (name: main)
103+
asset index.html x bytes [emitted] [from: index.html] (auxiliary name: main)"
104+
`;
105+
80106
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stderr 1`] = `""`;
81107

82108
exports[`logging should logging in multi-compiler and respect the "stats" option from configuration: stdout 1`] = `
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
stats: {
67+
all: false,
68+
assets: true,
69+
}
70+
},
71+
];

test/logging.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,44 @@ describe('logging', () => {
762762
});
763763
});
764764

765+
it('should logging in multi-compiler and respect the "stats" option from configuration #3', (done) => {
766+
let proc;
767+
768+
try {
769+
proc = execa(runner, [], {
770+
stdio: 'pipe',
771+
env: {
772+
WEBPACK_CONFIG: 'webpack.array.one-error-one-warning-one-object',
773+
},
774+
});
775+
} catch (error) {
776+
throw error;
777+
}
778+
779+
let stdout = '';
780+
let stderr = '';
781+
782+
proc.stdout.on('data', (chunk) => {
783+
stdout += chunk.toString();
784+
785+
if (/compiled-for-tests/gi.test(stdout)) {
786+
proc.stdin.write('|exit|');
787+
}
788+
});
789+
790+
proc.stderr.on('data', (chunk) => {
791+
stderr += chunk.toString();
792+
proc.stdin.write('|exit|');
793+
});
794+
795+
proc.on('exit', () => {
796+
expect(stdoutToSnapshot(stdout)).toMatchSnapshot('stdout');
797+
expect(stderrToSnapshot(stderr)).toMatchSnapshot('stderr');
798+
799+
done();
800+
});
801+
});
802+
765803
it('should logging an error in "watch" method', (done) => {
766804
let proc;
767805

0 commit comments

Comments
 (0)