Skip to content

Commit 1554d66

Browse files
test: fix
1 parent 0aea5d7 commit 1554d66

10 files changed

+91
-49
lines changed

src/SyntaxError.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export default class SyntaxError extends Error {
1717
}
1818
}
1919

20-
if (Error.captureStackTrace) {
21-
Error.captureStackTrace(this, this.constructor);
22-
}
20+
Error.captureStackTrace(this, this.constructor);
2321
}
2422
}

test/SyntaxError.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SyntaxError from '../src/SyntaxError';
22

33
import webpack from './helpers/compiler';
4+
import { normalizeErrors } from './helpers/utils';
45

56
describe('SyntaxError', () => {
67
test('basic', () => {
@@ -42,7 +43,9 @@ describe('SyntaxError', () => {
4243
test('integration', async () => {
4344
const stats = await webpack('broken.js');
4445

45-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
46-
expect(stats.compilation.errors).toMatchSnapshot('errors');
46+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
47+
'warnings'
48+
);
49+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
4750
});
4851
});

test/__snapshots__/SyntaxError.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports[`SyntaxError basic 7`] = `
2222

2323
exports[`SyntaxError integration: errors 1`] = `
2424
Array [
25-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
25+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
2626
SyntaxError: Unknown word (2:3)
2727
2828
1 | .some {

test/__snapshots__/import-option.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ exports[`import true from modules: warnings 1`] = `Array []`;
224224

225225
exports[`import true invalid: errors 1`] = `
226226
Array [
227-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
228-
SyntaxError: Unexpected format (1:1)
227+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
228+
SyntaxError: Unexpected format (\`replaced original path\`)
229229
230230
> 1 | @import;
231231
| ^

test/__snapshots__/source-map-option.test.js.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Array [
5151
"names": Array [],
5252
"sourceRoot": "",
5353
"sources": Array [
54-
"/home/evilebottnawi/IdeaProjects/css-loader/test/fixtures/source-map/basic.css",
54+
"/replaced/original/path/",
5555
],
5656
"sourcesContent": Array [
5757
".class {
@@ -84,8 +84,8 @@ Array [
8484
"names": Array [],
8585
"sourceRoot": "",
8686
"sources": Array [
87-
"/folder/test.css",
88-
"/home/evilebottnawi/IdeaProjects/css-loader/test/fixtures/source-map/basic.css",
87+
"/replaced/original/path/",
88+
"/replaced/original/path/",
8989
],
9090
"sourcesContent": Array [
9191
".class { a: b c d; }",
@@ -119,8 +119,8 @@ Array [
119119
"names": Array [],
120120
"sourceRoot": "",
121121
"sources": Array [
122-
"/folder/test.css",
123-
"/home/evilebottnawi/IdeaProjects/css-loader/test/fixtures/source-map/basic.css",
122+
"/replaced/original/path/",
123+
"/replaced/original/path/",
124124
],
125125
"sourcesContent": Array [
126126
".class { a: b c d; }",

test/__snapshots__/validation-errors.test.js.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ exports[`Validation Errors import - true (boolean): warnings 1`] = `Array []`;
1010

1111
exports[`Validation Errors import - true (string): errors 1`] = `
1212
Array [
13-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
13+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
1414
ValidationError: CSS Loader Invalid Options
1515
1616
options.import should be boolean
1717
18-
at validateOptions (/home/evilebottnawi/IdeaProjects/css-loader/node_modules/schema-utils/src/validateOptions.js:32:11)
19-
at Object.loader (/home/evilebottnawi/IdeaProjects/css-loader/src/index.js:30:3)],
18+
at validateOptions (\`replaced original path\`)
19+
at Object.loader (\`replaced original path\`)],
2020
]
2121
`;
2222

@@ -32,13 +32,13 @@ exports[`Validation Errors importLoaders - 1 (number): warnings 1`] = `Array []`
3232

3333
exports[`Validation Errors importLoaders - 1 (string): errors 1`] = `
3434
Array [
35-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
35+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
3636
ValidationError: CSS Loader Invalid Options
3737
3838
options.importLoaders should be number
3939
40-
at validateOptions (/home/evilebottnawi/IdeaProjects/css-loader/node_modules/schema-utils/src/validateOptions.js:32:11)
41-
at Object.loader (/home/evilebottnawi/IdeaProjects/css-loader/src/index.js:30:3)],
40+
at validateOptions (\`replaced original path\`)
41+
at Object.loader (\`replaced original path\`)],
4242
]
4343
`;
4444

@@ -54,27 +54,27 @@ exports[`Validation Errors sourceMap - true (boolean): warnings 1`] = `Array []`
5454

5555
exports[`Validation Errors sourceMap - true (string): errors 1`] = `
5656
Array [
57-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
57+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
5858
ValidationError: CSS Loader Invalid Options
5959
6060
options.sourceMap should be boolean
6161
62-
at validateOptions (/home/evilebottnawi/IdeaProjects/css-loader/node_modules/schema-utils/src/validateOptions.js:32:11)
63-
at Object.loader (/home/evilebottnawi/IdeaProjects/css-loader/src/index.js:30:3)],
62+
at validateOptions (\`replaced original path\`)
63+
at Object.loader (\`replaced original path\`)],
6464
]
6565
`;
6666

6767
exports[`Validation Errors sourceMap - true (string): warnings 1`] = `Array []`;
6868

6969
exports[`Validation Errors unknown option: errors 1`] = `
7070
Array [
71-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
71+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
7272
ValidationError: CSS Loader Invalid Options
7373
7474
options should NOT have additional properties
7575
76-
at validateOptions (/home/evilebottnawi/IdeaProjects/css-loader/node_modules/schema-utils/src/validateOptions.js:32:11)
77-
at Object.loader (/home/evilebottnawi/IdeaProjects/css-loader/src/index.js:30:3)],
76+
at validateOptions (\`replaced original path\`)
77+
at Object.loader (\`replaced original path\`)],
7878
]
7979
`;
8080

@@ -90,13 +90,13 @@ exports[`Validation Errors url - true (boolean): warnings 1`] = `Array []`;
9090

9191
exports[`Validation Errors url - true (string): errors 1`] = `
9292
Array [
93-
[ModuleBuildError: Module build failed (from /home/evilebottnawi/IdeaProjects/css-loader/src/index.js):
93+
[ModuleBuildError: Module build failed (from \`replaced original path\`):
9494
ValidationError: CSS Loader Invalid Options
9595
9696
options.url should be boolean
9797
98-
at validateOptions (/home/evilebottnawi/IdeaProjects/css-loader/node_modules/schema-utils/src/validateOptions.js:32:11)
99-
at Object.loader (/home/evilebottnawi/IdeaProjects/css-loader/src/index.js:30:3)],
98+
at validateOptions (\`replaced original path\`)
99+
at Object.loader (\`replaced original path\`)],
100100
]
101101
`;
102102

test/helpers/utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function normalizeErrors(errors) {
2+
return errors.map((error) => {
3+
// eslint-disable-next-line no-param-reassign
4+
error.message = error.message
5+
.replace(/\(from .*?\)/, '(from `replaced original path`)')
6+
.replace(/at(.*?)\(.*?\)/g, 'at$1(`replaced original path`)');
7+
8+
return error;
9+
});
10+
}
11+
12+
function normalizeModule(module) {
13+
return module.map((m) => {
14+
if (m[3]) {
15+
// eslint-disable-next-line no-param-reassign
16+
m[3].sources = m[3].sources.map(() => '/replaced/original/path/');
17+
}
18+
19+
return m;
20+
});
21+
}
22+
23+
module.exports = { normalizeErrors, normalizeModule };

test/import-option.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import webpack from './helpers/compiler';
22
import evaluated from './helpers/evaluated';
3+
import { normalizeErrors } from './helpers/utils';
34

45
describe('import', () => {
56
describe('true', () => {
@@ -252,8 +253,12 @@ describe('import', () => {
252253
test('invalid', async () => {
253254
const stats = await webpack('import/invalid.css');
254255

255-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
256-
expect(stats.compilation.errors).toMatchSnapshot('errors');
256+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
257+
'warnings'
258+
);
259+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot(
260+
'errors'
261+
);
257262
});
258263
});
259264

test/source-map-option.test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'path';
22

33
import webpack from './helpers/compiler';
44
import evaluated from './helpers/evaluated';
5+
import { normalizeModule } from './helpers/utils';
56

67
describe('sourceMap', () => {
78
const generateRulesWithSourceMap = (enableSourceMap, sourceMap) => {
@@ -40,9 +41,9 @@ describe('sourceMap', () => {
4041
const stats = await webpack('source-map/basic.css', config);
4142
const { modules } = stats.toJson();
4243

43-
expect(evaluated(modules[modules.length - 1].source)).toMatchSnapshot(
44-
'module'
45-
);
44+
expect(
45+
normalizeModule(evaluated(modules[modules.length - 1].source))
46+
).toMatchSnapshot('module');
4647

4748
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
4849
expect(stats.compilation.errors).toMatchSnapshot('errors');
@@ -61,9 +62,9 @@ describe('sourceMap', () => {
6162
const stats = await webpack('source-map/basic.css', config);
6263
const { modules } = stats.toJson();
6364

64-
expect(evaluated(modules[modules.length - 1].source)).toMatchSnapshot(
65-
'module'
66-
);
65+
expect(
66+
normalizeModule(evaluated(modules[modules.length - 1].source))
67+
).toMatchSnapshot('module');
6768

6869
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
6970
expect(stats.compilation.errors).toMatchSnapshot('errors');
@@ -85,9 +86,9 @@ describe('sourceMap', () => {
8586
const stats = await webpack('source-map/basic.css', config);
8687
const { modules } = stats.toJson();
8788

88-
expect(evaluated(modules[modules.length - 1].source)).toMatchSnapshot(
89-
'module'
90-
);
89+
expect(
90+
normalizeModule(evaluated(modules[modules.length - 1].source))
91+
).toMatchSnapshot('module');
9192

9293
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
9394
expect(stats.compilation.errors).toMatchSnapshot('errors');

test/validation-errors.test.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import webpack from './helpers/compiler';
22

3+
import { normalizeErrors } from './helpers/utils';
4+
35
describe('Validation Errors', () => {
46
test('unknown option', async () => {
57
const config = {
@@ -11,8 +13,10 @@ describe('Validation Errors', () => {
1113
};
1214
const stats = await webpack('basic.js', config);
1315

14-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
15-
expect(stats.compilation.errors).toMatchSnapshot('errors');
16+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
17+
'warnings'
18+
);
19+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
1620
});
1721

1822
test('url - true (boolean)', async () => {
@@ -53,8 +57,10 @@ describe('Validation Errors', () => {
5357
};
5458
const stats = await webpack('basic.js', config);
5559

56-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
57-
expect(stats.compilation.errors).toMatchSnapshot('errors');
60+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
61+
'warnings'
62+
);
63+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
5864
});
5965

6066
test('import - true (boolean)', async () => {
@@ -95,8 +101,10 @@ describe('Validation Errors', () => {
95101
};
96102
const stats = await webpack('basic.js', config);
97103

98-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
99-
expect(stats.compilation.errors).toMatchSnapshot('errors');
104+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
105+
'warnings'
106+
);
107+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
100108
});
101109

102110
test('sourceMap - true (boolean)', async () => {
@@ -137,8 +145,10 @@ describe('Validation Errors', () => {
137145
};
138146
const stats = await webpack('basic.js', config);
139147

140-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
141-
expect(stats.compilation.errors).toMatchSnapshot('errors');
148+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
149+
'warnings'
150+
);
151+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
142152
});
143153

144154
test('importLoaders - 0 (number)', async () => {
@@ -179,7 +189,9 @@ describe('Validation Errors', () => {
179189
};
180190
const stats = await webpack('basic.js', config);
181191

182-
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
183-
expect(stats.compilation.errors).toMatchSnapshot('errors');
192+
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
193+
'warnings'
194+
);
195+
expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors');
184196
});
185197
});

0 commit comments

Comments
 (0)