Skip to content

Commit fbf05de

Browse files
test: replace helpers with @webpack-utilities/test (#386)
1 parent daa0da8 commit fbf05de

23 files changed

+180
-368
lines changed

package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "postcss-loader",
33
"version": "2.1.6",
44
"description": "PostCSS loader for webpack",
5-
"main": "lib/index.js",
5+
"main": "src/index.js",
66
"files": [
7-
"lib"
7+
"src"
88
],
99
"engines": {
1010
"node": ">= 6"
@@ -16,21 +16,20 @@
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",
32-
"test": "jest --env=node --verbose --coverage",
33-
"docs": "jsdoc2md lib/index.js > LOADER.md",
31+
"test": "jest --env node --verbose --coverage",
32+
"docs": "jsdoc2md src/*.js > LOADER.md",
3433
"clean": "rm -rf coverage test/outputs",
3534
"release": "standard-version"
3635
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/Errors.test.js

+44-10
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,65 @@
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+
// eslint-disable-next-line
18+
const error = () => eval(source)
1119

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

1635
test('Syntax Error', () => {
1736
const config = {
1837
loader: {
38+
test: /\.css$/,
1939
options: {
2040
parser: 'sugarss'
2141
}
2242
}
2343
}
2444

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

28-
expect(error[0]).toMatchSnapshot()
48+
// eslint-disable-next-line
49+
const error = () => eval(source)
50+
51+
expect(error).toThrow()
52+
53+
try {
54+
error()
55+
} catch (err) {
56+
const message = err.message
57+
.split('\n')
58+
.slice(1)
59+
.join('\n')
60+
61+
expect(message).toMatchSnapshot()
62+
}
2963
})
3064
})
3165
})

test/__snapshots__/Errors.test.js.snap

+3-3
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
"
-6
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

-1
This file was deleted.

test/fixtures/watch/index.css

-1
This file was deleted.

test/fixtures/watch/index.js

-3
This file was deleted.

test/fixtures/watch/style.css

-1
This file was deleted.

test/helpers/compilation.js

-66
This file was deleted.

test/helpers/compiler.js

-63
This file was deleted.

test/helpers/fs.js

-38
This file was deleted.

0 commit comments

Comments
 (0)