Skip to content

Commit 1fd7304

Browse files
test: replace helpers with @webpack-utilities/test
1 parent 96b104e commit 1fd7304

23 files changed

+177
-363
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
"schema-utils": "^0.4.0"
1717
},
1818
"devDependencies": {
19-
"jest": "^22.0.0",
19+
"@webpack-utilities/test": "^1.0.0-alpha.0",
2020
"jsdoc-to-markdown": "^4.0.0",
21-
"memory-fs": "^0.4.0",
2221
"postcss-import": "^11.0.0",
2322
"postcss-js": "^2.0.0",
2423
"standard": "^11.0.0",
2524
"standard-version": "^4.0.0",
2625
"sugarss": "^1.0.0",
2726
"util.promisify": "^1.0.0",
28-
"webpack": "^3.0.0"
27+
"webpack": "^4.0.0"
2928
},
3029
"scripts": {
3130
"lint": "standard --env jest",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/Errors.test.js

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
1-
'use strict'
2-
3-
const webpack = require('./helpers/compiler')
4-
const { loader } = require('./helpers/compilation')
1+
const { webpack } = require('@webpack-utilities/test')
52

63
describe('Errors', () => {
74
test('Validation Error', () => {
8-
const loader = require('../lib')
5+
const config = {
6+
loader: {
7+
test: /\.css$/,
8+
options: {
9+
sourceMap: 1
10+
}
11+
}
12+
}
13+
14+
return webpack('css/index.js', config).then((stats) => {
15+
const { source } = stats.toJson().modules[1]
16+
17+
const error = () => eval(source)
918

10-
const error = () => loader.call({ query: { sourceMap: 1 } })
19+
expect(error).toThrow()
1120

12-
expect(error).toThrow()
13-
expect(error).toThrowErrorMatchingSnapshot()
21+
try {
22+
error()
23+
} catch ({ message }) {
24+
message = message
25+
.split('\n')
26+
.slice(1)
27+
.join('\n')
28+
29+
console.log(message)
30+
31+
expect(message).toMatchSnapshot()
32+
}
33+
})
1434
})
1535

1636
test('Syntax Error', () => {
1737
const config = {
1838
loader: {
39+
test: /\.css$/,
1940
options: {
2041
parser: 'sugarss'
2142
}
2243
}
2344
}
2445

2546
return webpack('css/index.js', config).then((stats) => {
26-
const error = loader(stats).err
47+
const { source } = stats.toJson().modules[1]
48+
49+
const error = () => eval(source)
2750

28-
expect(error[0]).toMatchSnapshot()
51+
expect(error).toThrow()
52+
53+
try {
54+
error()
55+
} catch ({ message }) {
56+
message = message
57+
.split('\n')
58+
.slice(1)
59+
.join('\n')
60+
61+
console.log(message)
62+
63+
expect(message).toMatchSnapshot()
64+
}
2965
})
3066
})
3167
})

test/__snapshots__/Errors.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Errors Syntax Error 1`] = `
4-
[ModuleBuildError: Module build failed: Syntax Error
4+
"Syntax Error
55
66
(1:3) Unexpected separator in property
77
88
> 1 | a { color: black }
99
 |  ^
1010
 2 | 
11-
]
11+
"
1212
`;
1313
1414
exports[`Errors Validation Error 1`] = `
15-
"PostCSS Loader Invalid Options
15+
"ValidationError: PostCSS Loader Invalid Options
1616
1717
options.sourceMap should be string,boolean
1818
"
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Loader Default 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;
4-
5-
exports[`Loader Watching Dependencies Error 1`] = `"module.exports = \\"a { color: black }\\\\n\\""`;
6-
7-
exports[`Loader Watching Dependencies Error 2`] = `"throw new Error(\\"Module build failed: Syntax Error \\\\n\\\\n(1:5) Unknown word\\\\n\\\\n\\\\u001b[31m\\\\u001b[1m>\\\\u001b[22m\\\\u001b[39m\\\\u001b[90m 1 | \\\\u001b[39ma \\\\u001b[33m{\\\\u001b[39m color black \\\\u001b[33m}\\\\u001b[39m\\\\n \\\\u001b[90m | \\\\u001b[39m \\\\u001b[31m\\\\u001b[1m^\\\\u001b[22m\\\\u001b[39m\\\\n \\\\u001b[90m 2 | \\\\u001b[39m\\\\n\\");"`;
8-
9-
exports[`Loader Watching Dependencies Error 3`] = `"module.exports = \\"a { color: black }\\\\n\\""`;

test/fixtures/watch/error.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/watch/index.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/watch/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/watch/style.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/helpers/compilation.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

test/helpers/compiler.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

test/helpers/fs.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)