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

Commit 2230320

Browse files
Merge pull request #90 from weilinzung/mini-css-extra-test
New updates with Webpack 4 & Add mini-css-extract-plugin test
2 parents e02907b + 141998c commit 2230320

File tree

12 files changed

+1463
-1080
lines changed

12 files changed

+1463
-1080
lines changed

package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,28 @@
3333
},
3434
"devDependencies": {
3535
"babel-core": "^6.23.1",
36-
"babel-eslint": "^7.1.1",
37-
"babel-loader": "^6.3.0",
38-
"babel-plugin-transform-async-to-generator": "^6.22.0",
36+
"babel-eslint": "^10.0.1",
37+
"babel-loader": "^7.1.4",
38+
"babel-plugin-transform-async-to-generator": "^6.24.1",
3939
"babel-preset-react": "^6.23.0",
40+
"css-loader": "^2.1.1",
4041
"eslint": "^5.16.0",
41-
"eslint-loader": "^1.6.1",
42-
"eslint-plugin-node": "^9.0.0",
43-
"expect": "^1.20.2",
42+
"eslint-loader": "^2.1.2",
43+
"eslint-plugin-node": "^9.0.1",
44+
"expect": "^24.8.0",
4445
"jest": "^18.1.0",
4546
"memory-fs": "^0.4.1",
46-
"webpack": "^2.2.1"
47+
"mini-css-extract-plugin": "^0.6.0",
48+
"node-sass": "^4.12.0",
49+
"sass": "^1.20.1",
50+
"sass-loader": "^7.1.0",
51+
"style-loader": "^0.23.1",
52+
"webpack": "^4.31.0"
4753
},
4854
"dependencies": {
4955
"chalk": "^2.4.2",
50-
"error-stack-parser": "^2.0.0",
56+
"error-stack-parser": "^2.0.2",
5157
"string-width": "^2.0.0",
52-
"strip-ansi": "^3"
58+
"strip-ansi": "^5"
5359
}
5460
}

src/transformers/babelSyntax.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ function cleanStackTrace(message) {
1111

1212
function cleanMessage(message) {
1313
return message
14-
// match until the last semicolon followed by a space
15-
// this should match
16-
// linux => "(SyntaxError: )Unexpected token (5:11)"
17-
// windows => "(SyntaxError: C:/projects/index.js: )Unexpected token (5:11)"
18-
.replace(/^Module build failed.*:\s/, 'Syntax Error: ');
14+
// match until the last semicolon followed by a space
15+
// this should match
16+
// linux => "(SyntaxError: )Unexpected token (5:11)"
17+
// windows => "(SyntaxError: C:/projects/index.js: )Unexpected token (5:11)"
18+
.replace(/^Module build failed.*:\s/, 'Syntax Error: ')
19+
// remove mini-css-extract-plugin loader tracing errors
20+
.replace(/^Syntax Error: ModuleBuildError:.*:\s/, '')
21+
// remove babel extra wording
22+
.replace('SyntaxError: ', '');
1923
}
2024

2125
function isBabelSyntaxError(e) {
22-
return e.name === 'ModuleBuildError' &&
26+
return e.name === 'ModuleBuildError' || e.name === 'ModuleBuildError' &&
2327
e.message.indexOf('SyntaxError') >= 0;
2428
}
2529

@@ -35,4 +39,4 @@ function transform(error) {
3539
return error;
3640
}
3741

38-
module.exports = transform;
42+
module.exports = transform;
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const FriendlyErrorsWebpackPlugin = require('../../../index');
22

33
module.exports = {
4+
mode: 'development',
45
entry: __dirname + "/index.js",
56
output: {
67
path: __dirname + "/dist",
@@ -10,12 +11,12 @@ module.exports = {
1011
new FriendlyErrorsWebpackPlugin()
1112
],
1213
module: {
13-
loaders: [
14+
rules: [
1415
{
1516
test: /\.jsx?$/,
16-
loader: 'babel-loader',
17-
exclude: /node_modules/
17+
exclude: /node_modules/,
18+
loader: 'babel-loader',
1819
}
1920
]
20-
}
21+
},
2122
};
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const FriendlyErrorsWebpackPlugin = require('../../../index');
22

33
module.exports = {
4+
mode: 'development',
45
entry: __dirname + "/index.js",
56
output: {
67
path: __dirname + "/dist",
@@ -11,18 +12,18 @@ module.exports = {
1112

1213
],
1314
module: {
14-
loaders: [
15+
rules: [
1516
{
16-
test: /\.js$/,
17-
loader: 'eslint-loader',
1817
enforce: 'pre',
19-
include: __dirname
18+
test: /\.js$/,
19+
loader: 'eslint-loader',
20+
include: __dirname,
2021
},
2122
{
2223
test: /\.jsx?$/,
23-
loader: 'babel-loader',
24-
exclude: /node_modules/
24+
exclude: /node_modules/,
25+
loader: 'babel-loader',
2526
}
2627
]
27-
}
28+
},
2829
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
body {
2+
color: red;
3+
4+
.container {
5+
margin-top: 100px
6+
7+
.test {
8+
vertical-align: middle;
9+
}
10+
}
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// mini-css-extract-plugin test
2+
const FriendlyErrorsWebpackPlugin = require('../../../index');
3+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4+
5+
module.exports = {
6+
entry: __dirname + "/index.scss",
7+
output: {
8+
path: __dirname + "/dist",
9+
},
10+
plugins: [
11+
new FriendlyErrorsWebpackPlugin(),
12+
new MiniCssExtractPlugin({
13+
filename: '[name].css',
14+
chunkFilename: '[id].css',
15+
}),
16+
],
17+
module: {
18+
rules: [
19+
{
20+
test: /\.(s*)css$/,
21+
exclude: /node_modules/,
22+
use: [
23+
MiniCssExtractPlugin.loader,
24+
'style-loader',
25+
'css-loader',
26+
{
27+
loader: 'sass-loader',
28+
options: {
29+
implementation: require('sass'),
30+
}
31+
},
32+
],
33+
}
34+
]
35+
},
36+
};

test/fixtures/multi-compiler-success/webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module.exports = [
22
{
3+
mode: 'development',
34
entry: __dirname + "/index.js",
45
output: {
56
path: __dirname + "/dist",
67
filename: "bundle.js"
78
}
89
},
910
{
11+
mode: 'development',
1012
entry: __dirname + "/index2.js",
1113
output: {
1214
path: __dirname + "/dist",

test/fixtures/success/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const FriendlyErrorsWebpackPlugin = require('../../../index');
22

33
module.exports = {
4+
mode: 'development',
45
entry: __dirname + "/index.js",
56
output: {
67
path: __dirname + "/dist",

test/integration.spec.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ it('integration : module-errors', async() => {
5656
'',
5757
'These relative modules were not found:',
5858
'',
59-
'* ./non-existing in ./test/fixtures/module-errors/index.js',
6059
'* ../non-existing in ./test/fixtures/module-errors/index.js',
60+
'* ./non-existing in ./test/fixtures/module-errors/index.js',
6161
]);
6262
});
6363

@@ -72,12 +72,16 @@ it('integration : should display eslint warnings', async() => {
7272
expect(logs.join('\n')).toEqual(
7373
`WARNING Compiled with 2 warnings
7474
75+
Module Warning (from ./node_modules/eslint-loader/index.js):
76+
7577
${filename('fixtures/eslint-warnings/index.js')}
7678
3:7 warning 'unused' is assigned a value but never used no-unused-vars
7779
4:7 warning 'unused2' is assigned a value but never used no-unused-vars
7880
7981
✖ 2 problems (0 errors, 2 warnings)
8082
83+
Module Warning (from ./node_modules/eslint-loader/index.js):
84+
8185
${filename('fixtures/eslint-warnings/module.js')}
8286
1:7 warning 'unused' is assigned a value but never used no-unused-vars
8387
@@ -110,6 +114,23 @@ it('integration : babel syntax error', async() => {
110114
]);
111115
});
112116

117+
it('integration : mini CSS extract plugin babel error', async() => {
118+
119+
const logs = await executeAndGetLogs('./fixtures/mini-css-extract-babel-syntax/webpack.config');
120+
const clean_logs = logs.toString().replace(/\"/g, ""); //<- double quotes issue with slash
121+
expect(clean_logs).toEqual(
122+
`ERROR Failed to compile with 1 errors,,error in ./test/fixtures/mini-css-extract-babel-syntax/index.scss,,.test {
123+
^
124+
Expected digit.
125+
126+
7 │ .test {
127+
│ ^
128+
129+
stdin 7:4 root stylesheet
130+
in ${filename('fixtures/mini-css-extract-babel-syntax/index.scss')} (line 7, column 4),`
131+
);
132+
});
133+
113134
it('integration : webpack multi compiler : success', async() => {
114135

115136
// We apply the plugin directly to the compiler when targeting multi-compiler

test/unit/plugin/friendlyErrors.spec.js

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const expect = require('expect');
22
const EventEmitter = require('events');
3-
const Stats = require('webpack/lib/Stats');
4-
const MultiStats = require('webpack/lib/MultiStats');
3+
const Stats = require('webpack/lib/Stats')
54
const Module = require('webpack/lib/Module');
65
EventEmitter.prototype.plugin = EventEmitter.prototype.on;
76

@@ -52,53 +51,13 @@ it('friendlyErrors : clearConsole option', () => {
5251
expect(plugin.shouldClearConsole).toBeFalsy()
5352
});
5453

55-
56-
describe('friendlyErrors : multicompiler', () => {
57-
it('supplies the correct max compile time across multiple stats', () => {
58-
const stats1 = successfulCompilationStats({ startTime: 0, endTime: 1000 });
59-
const stats2 = successfulCompilationStats({ startTime: 2, endTime: 2002 });
60-
const multistats = new MultiStats([stats1, stats2]);
61-
62-
const logs = output.captureLogs(() => {
63-
mockCompiler.emit('done', multistats);
64-
});
65-
66-
expect(logs).toEqual([
67-
'DONE Compiled successfully in 2000ms',
68-
''
69-
]);
70-
});
71-
72-
it('supplies the correct recompile time with rebuild', () => {
73-
// Test that rebuilds do not use the prior "max" value when recompiling just one stats object.
74-
// This ensures the user does not get incorrect build times in watch mode.
75-
const stats1 = successfulCompilationStats({ startTime: 0, endTime: 1000 });
76-
const stats2 = successfulCompilationStats({ startTime: 0, endTime: 500 });
77-
const stats2Rebuild = successfulCompilationStats({ startTime: 1020, endTime: 1050 });
78-
79-
const multistats = new MultiStats([stats1, stats2]);
80-
const multistatsRecompile = new MultiStats([stats1, stats2Rebuild]);
81-
82-
const logs = output.captureLogs(() => {
83-
mockCompiler.emit('done', multistats);
84-
mockCompiler.emit('done', multistatsRecompile);
85-
});
86-
87-
expect(logs).toEqual([
88-
'DONE Compiled successfully in 1000ms',
89-
'',
90-
'DONE Compiled successfully in 30ms',
91-
''
92-
]);
93-
});
94-
})
95-
9654
function successfulCompilationStats(opts) {
9755
const options = Object.assign({ startTime: 0, endTime: 100 }, opts);
9856

9957
const compilation = {
10058
errors: [],
101-
warnings: []
59+
warnings: [],
60+
children: []
10261
};
10362
const stats = new Stats(compilation);
10463
stats.startTime = options.startTime;

0 commit comments

Comments
 (0)