Skip to content

Commit 60f515b

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

23 files changed

+174
-364
lines changed

package.json

Lines changed: 3 additions & 4 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",
20+
"jest": "^23.0.0",
2021
"jsdoc-to-markdown": "^4.0.0",
21-
"memory-fs": "^0.4.0",
2222
"postcss-import": "^11.0.0",
2323
"postcss-js": "^2.0.0",
2424
"standard": "^11.0.0",
2525
"standard-version": "^4.0.0",
2626
"sugarss": "^1.0.0",
27-
"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: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,63 @@
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]
916

10-
const error = () => loader.call({ query: { sourceMap: 1 } })
17+
const error = () => eval(source)
1118

12-
expect(error).toThrow()
13-
expect(error).toThrowErrorMatchingSnapshot()
19+
expect(error).toThrow()
20+
21+
try {
22+
error()
23+
} catch ({ message }) {
24+
message = message
25+
.split('\n')
26+
.slice(1)
27+
.join('\n')
28+
29+
expect(message).toMatchSnapshot()
30+
}
31+
})
1432
})
1533

1634
test('Syntax Error', () => {
1735
const config = {
1836
loader: {
37+
test: /\.css$/,
1938
options: {
2039
parser: 'sugarss'
2140
}
2241
}
2342
}
2443

2544
return webpack('css/index.js', config).then((stats) => {
26-
const error = loader(stats).err
45+
const { source } = stats.toJson().modules[1]
2746

28-
expect(error[0]).toMatchSnapshot()
47+
const error = () => eval(source)
48+
49+
expect(error).toThrow()
50+
51+
try {
52+
error()
53+
} catch ({ message }) {
54+
message = message
55+
.split('\n')
56+
.slice(1)
57+
.join('\n')
58+
59+
expect(message).toMatchSnapshot()
60+
}
2961
})
3062
})
3163
})

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)