This repository was archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathintegration.spec.js
More file actions
150 lines (118 loc) · 4.5 KB
/
integration.spec.js
File metadata and controls
150 lines (118 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"use strict";
const output = require('../src/output');
const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('../src/friendly-errors-plugin');
const MemoryFileSystem = require('memory-fs');
const path = require('path');
const webpackPromise = function (config, globalPlugins) {
const compiler = webpack(config);
compiler.outputFileSystem = new MemoryFileSystem();
if (Array.isArray(globalPlugins)) {
globalPlugins.forEach(p => compiler.apply(p));
}
return new Promise((resolve, reject) => {
compiler.run(err => {
if (err) {
reject(err)
}
resolve()
});
});
};
async function executeAndGetLogs(fixture, globalPlugins) {
try {
output.capture();
await webpackPromise(require(fixture), globalPlugins);
return output.capturedMessages;
} finally {
output.endCapture()
}
}
it('integration : success', async() => {
const logs = await executeAndGetLogs('./fixtures/success/webpack.config')
expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/);
});
it('integration : module-errors', async() => {
const logs = await executeAndGetLogs('./fixtures/module-errors/webpack.config.js');
expect(logs).toEqual([
'ERROR Failed to compile with 2 errors',
'',
'These dependencies were not found in node_modules:',
'',
'* ./non-existing in ./test/fixtures/module-errors/index.js',
'* not-found in ./test/fixtures/module-errors/index.js',
'',
'Did you forget to run npm install --save for them?'
]);
});
function filename(filePath) {
return path.join(__dirname, path.normalize(filePath))
}
it('integration : should display eslint warnings', async() => {
const logs = await executeAndGetLogs('./fixtures/eslint-warnings/webpack.config.js');
expect(logs.join('\n')).toEqual(
`WARNING Compiled with 2 warnings
${filename('fixtures/eslint-warnings/index.js')}
3:7 warning 'unused' is assigned a value but never used no-unused-vars
4:7 warning 'unused2' is assigned a value but never used no-unused-vars
✖ 2 problems (0 errors, 2 warnings)
${filename('fixtures/eslint-warnings/module.js')}
1:7 warning 'unused' is assigned a value but never used no-unused-vars
✖ 1 problem (0 errors, 1 warning)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.`
)
});
it('integration : babel syntax error', async() => {
const logs = await executeAndGetLogs('./fixtures/babel-syntax/webpack.config');
expect(logs).toEqual([
'ERROR Failed to compile with 1 errors',
'',
'error in ./test/fixtures/babel-syntax/index.js',
'',
`Syntax Error: Unexpected token (5:11)
3 |${' '}
4 | render() {
> 5 | return <div>
| ^
6 | }
7 | }`,
''
]);
});
it('integration : webpack multi compiler : success', async() => {
// We apply the plugin directly to the compiler when targeting multi-compiler
let globalPlugins = [new FriendlyErrorsWebpackPlugin()];
const logs = await executeAndGetLogs('./fixtures/multi-compiler-success/webpack.config', globalPlugins);
expect(logs.join('\n')).toMatch(/DONE Compiled successfully in (.\d*)ms/)
});
it('integration : webpack multi compiler : module-errors', async() => {
// We apply the plugin directly to the compiler when targeting multi-compiler
let globalPlugins = [new FriendlyErrorsWebpackPlugin()];
const logs = await executeAndGetLogs('./fixtures/multi-compiler-module-errors/webpack.config', globalPlugins);
expect(logs).toEqual([
'ERROR Failed to compile with 2 errors',
'',
'These dependencies were not found in node_modules:',
'',
'* ./non-existing in ./test/fixtures/multi-compiler-module-errors/index.js',
'* not-found in ./test/fixtures/multi-compiler-module-errors/index2.js',
'',
'Did you forget to run npm install --save for them?'
]);
});
it('integration : missing loader', async() => {
// We apply the plugin directly to the compiler when targeting multi-compiler
let globalPlugins = [new FriendlyErrorsWebpackPlugin()];
const logs = await executeAndGetLogs('./fixtures/module-missing-loader-error/webpack.config', globalPlugins);
expect(logs).toEqual([
'ERROR Failed to compile with 1 errors',
'',
'This dependency was not found in node_modules:',
'',
'* missing-loader in ./test/fixtures/module-missing-loader-error/index.js',
'',
'Install the missing loader with: npm install --save missing-loader'
]);
});