Skip to content

Commit fbf05de

Browse files
committedAug 8, 2018
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
},

‎lib/Error.js ‎src/Error.js

File renamed without changes.

‎lib/index.js ‎src/index.js

File renamed without changes.

‎lib/options.js ‎src/options.js

File renamed without changes.

‎lib/options.json ‎src/options.json

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.

‎test/loader.test.js

+5-78
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,21 @@
1-
'use strict'
2-
3-
const webpack = require('./helpers/compiler')
4-
const { loader } = require('./helpers/compilation')
5-
const { copyFile, deleteFile } = require('./helpers/fs')
1+
const { webpack } = require('@webpack-utilities/test')
62

73
describe('Loader', () => {
84
test('Default', () => {
95
const config = {
106
loader: {
7+
test: /\.css$/,
118
options: {
129
plugins: []
1310
}
1411
}
1512
}
1613

1714
return webpack('css/index.js', config).then((stats) => {
18-
const src = loader(stats).src
19-
20-
expect(src).toEqual('module.exports = "a { color: black }\\n"')
21-
expect(src).toMatchSnapshot()
22-
})
23-
})
24-
25-
describe('Watching', () => {
26-
describe('Dependencies', () => {
27-
const files = {
28-
css: 'watch/index.css',
29-
error: 'watch/error.css',
30-
changed: 'watch/import.css'
31-
}
32-
33-
beforeEach(() => copyFile(files.css, files.changed))
34-
35-
afterEach(() => deleteFile(files.changed))
36-
37-
test('Error', () => {
38-
const config = {
39-
loader: {
40-
options: {
41-
plugins: [
42-
require('postcss-import')
43-
]
44-
}
45-
}
46-
}
47-
48-
const steps = [
49-
(stats) => {
50-
const { err, src } = loader(stats)
51-
52-
expect(src).toMatchSnapshot()
53-
expect(err.length).toEqual(0)
54-
55-
return copyFile(files.error, files.changed)
56-
},
57-
(stats) => {
58-
const { err, src } = loader(stats)
59-
60-
expect(src).toMatchSnapshot()
61-
expect(err.length).toEqual(1)
62-
63-
return copyFile(files.css, files.changed)
64-
},
65-
(stats, close) => {
66-
const { err, src } = loader(stats)
67-
68-
expect(src).toMatchSnapshot()
69-
expect(src).toEqual('module.exports = "a { color: black }\\n"')
70-
expect(err.length).toEqual(0)
71-
72-
return close()
73-
}
74-
]
75-
76-
let step = 0
77-
78-
const options = {
79-
watch (err, stats, close) {
80-
if (err) {
81-
throw err
82-
}
83-
84-
steps[step](stats, close)
85-
86-
step++
87-
}
88-
}
15+
const { source } = stats.toJson().modules[1]
8916

90-
return webpack('watch/index.js', config, options)
91-
})
17+
expect(source).toEqual('module.exports = "a { color: black }\\n"')
18+
expect(source).toMatchSnapshot()
9219
})
9320
})
9421
})

‎test/options/config.test.js

+35-22
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
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('Options', () => {
74
test('Config - {Object}', () => {
85
const config = {
9-
loader: {}
6+
loader: {
7+
test: /\.css$/
8+
}
109
}
1110

1211
return webpack('css/index.js', config).then((stats) => {
13-
const src = loader(stats).src
12+
const { source } = stats.toJson().modules[1]
13+
14+
expect(source).toEqual(
15+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
16+
)
1417

15-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
16-
expect(src).toMatchSnapshot()
18+
expect(source).toMatchSnapshot()
1719
})
1820
})
1921

2022
test('Config - Path - {String}', () => {
2123
const config = {
2224
loader: {
25+
test: /\.css$/,
2326
options: {
2427
config: { path: 'test/fixtures/config/postcss.config.js' }
2528
}
2629
}
2730
}
2831

2932
return webpack('css/index.js', config).then((stats) => {
30-
const src = loader(stats).src
33+
const { source } = stats.toJson().modules[1]
3134

32-
expect(src).toEqual('module.exports = "a { color: black }\\n"')
33-
expect(src).toMatchSnapshot()
35+
expect(source).toEqual('module.exports = "a { color: black }\\n"')
36+
expect(source).toMatchSnapshot()
3437
})
3538
})
3639

3740
test('Config - Context - {Object}', () => {
3841
const config = {
3942
loader: {
43+
test: /\.css$/,
4044
options: {
4145
config: {
4246
path: 'test/fixtures/config/postcss.config.js',
@@ -47,16 +51,20 @@ describe('Options', () => {
4751
}
4852

4953
return webpack('css/index.js', config).then((stats) => {
50-
const src = loader(stats).src
54+
const { source } = stats.toJson().modules[1]
5155

52-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
53-
expect(src).toMatchSnapshot()
56+
expect(source).toEqual(
57+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
58+
)
59+
60+
expect(source).toMatchSnapshot()
5461
})
5562
})
5663

5764
test('Config - Context - {Object} - with ident', () => {
5865
const config = {
5966
loader: {
67+
test: /\.css$/,
6068
options: {
6169
ident: 'postcss',
6270
config: {
@@ -68,16 +76,20 @@ describe('Options', () => {
6876
}
6977

7078
return webpack('css/index.js', config).then((stats) => {
71-
const src = loader(stats).src
79+
const { source } = stats.toJson().modules[1]
80+
81+
expect(source).toEqual(
82+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
83+
)
7284

73-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
74-
expect(src).toMatchSnapshot()
85+
expect(source).toMatchSnapshot()
7586
})
7687
})
7788

78-
test('Pass loader object to config context', () => {
89+
test('Config – Context – Loader {Object}', () => {
7990
const config = {
8091
loader: {
92+
test: /\.css$/,
8193
options: {
8294
config: {
8395
path: 'test/fixtures/config/context/postcss.config.js'
@@ -87,11 +99,12 @@ describe('Options', () => {
8799
}
88100

89101
return webpack('css/index.js', config).then((stats) => {
90-
const assets = stats.compilation.assets
91-
const expectedAssetName = 'asset.txt'
102+
const { assets } = stats.compilation
103+
104+
const asset = 'asset.txt'
92105

93-
expect(expectedAssetName in assets).toBeTruthy()
94-
expect(assets[expectedAssetName].source()).toBe('123')
106+
expect(asset in assets).toBeTruthy()
107+
expect(assets[asset].source()).toBe('123')
95108
})
96109
})
97110
})

‎test/options/exec.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
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('Options', () => {
74
test('Exec - {Boolean}', () => {
@@ -15,10 +12,13 @@ describe('Options', () => {
1512
}
1613

1714
return webpack('jss/exec/index.js', config).then((stats) => {
18-
const src = loader(stats).src
15+
const { source } = stats.toJson().modules[1]
16+
17+
expect(source).toEqual(
18+
'module.exports = "a {\\n color: green\\n}"'
19+
)
1920

20-
expect(src).toEqual('module.exports = "a {\\n color: green\\n}"')
21-
expect(src).toMatchSnapshot()
21+
expect(source).toMatchSnapshot()
2222
})
2323
})
2424

@@ -32,9 +32,9 @@ describe('Options', () => {
3232
}
3333

3434
return webpack('jss/index.js', config).then((stats) => {
35-
const src = loader(stats).src
35+
const { source } = stats.toJson().modules[1]
3636

37-
expect(src).toMatchSnapshot()
37+
expect(source).toMatchSnapshot()
3838
})
3939
})
4040
})

‎test/options/parser.test.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
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('Options', () => {
74
test('Parser - {String}', () => {
85
const config = {
96
loader: {
7+
test: /\.sss$/,
108
options: {
119
parser: 'sugarss'
1210
}
1311
}
1412
}
1513

1614
return webpack('sss/index.js', config).then((stats) => {
17-
const src = loader(stats).src
15+
const { source } = stats.toJson().modules[1]
1816

19-
expect(src).toEqual('module.exports = "a {\\n color: black\\n}\\n"')
20-
expect(src).toMatchSnapshot()
17+
expect(source).toEqual('module.exports = "a {\\n color: black\\n}\\n"')
18+
expect(source).toMatchSnapshot()
2119
})
2220
})
2321

2422
test('Parser - {Object}', () => {
2523
const config = {
2624
loader: {
25+
test: /\.sss$/,
2726
options: {
2827
ident: 'postcss',
2928
parser: require('sugarss')
@@ -32,10 +31,10 @@ describe('Options', () => {
3231
}
3332

3433
return webpack('sss/index.js', config).then((stats) => {
35-
const src = loader(stats).src
34+
const { source } = stats.toJson().modules[1]
3635

37-
expect(src).toEqual('module.exports = "a {\\n color: black\\n}\\n"')
38-
expect(src).toMatchSnapshot()
36+
expect(source).toEqual('module.exports = "a {\\n color: black\\n}\\n"')
37+
expect(source).toMatchSnapshot()
3938
})
4039
})
4140
})

‎test/options/plugins.test.js

+29-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
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('Options', () => {
74
test('Plugins - {Array}', () => {
85
const config = {
96
loader: {
7+
test: /\.css$/,
108
options: {
119
ident: 'postcss',
1210
plugins: [ require('../fixtures/config/plugin')() ]
@@ -15,16 +13,20 @@ describe('Options', () => {
1513
}
1614

1715
return webpack('css/index.js', config).then((stats) => {
18-
const src = loader(stats).src
16+
const { source } = stats.toJson().modules[1]
17+
18+
expect(source).toEqual(
19+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
20+
)
1921

20-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
21-
expect(src).toMatchSnapshot()
22+
expect(source).toMatchSnapshot()
2223
})
2324
})
2425

2526
test('Plugins - {Object}', () => {
2627
const config = {
2728
loader: {
29+
test: /\.css$/,
2830
options: {
2931
ident: 'postcss',
3032
plugins: require('../fixtures/config/plugin')
@@ -33,16 +35,20 @@ describe('Options', () => {
3335
}
3436

3537
return webpack('css/index.js', config).then((stats) => {
36-
const src = loader(stats).src
38+
const { source } = stats.toJson().modules[1]
39+
40+
expect(source).toEqual(
41+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
42+
)
3743

38-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
39-
expect(src).toMatchSnapshot()
44+
expect(source).toMatchSnapshot()
4045
})
4146
})
4247

4348
test('Plugins - {Function} - {Array}', () => {
4449
const config = {
4550
loader: {
51+
test: /\.css$/,
4652
options: {
4753
ident: 'postcss',
4854
plugins: () => [ require('../fixtures/config/plugin')() ]
@@ -51,16 +57,20 @@ describe('Options', () => {
5157
}
5258

5359
return webpack('css/index.js', config).then((stats) => {
54-
const src = loader(stats).src
60+
const { source } = stats.toJson().modules[1]
5561

56-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
57-
expect(src).toMatchSnapshot()
62+
expect(source).toEqual(
63+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
64+
)
65+
66+
expect(source).toMatchSnapshot()
5867
})
5968
})
6069

6170
test('Plugins - {Function} - {Object}', () => {
6271
const config = {
6372
loader: {
73+
test: /\.css$/,
6474
options: {
6575
ident: 'postcss',
6676
plugins: () => require('../fixtures/config/plugin')()
@@ -69,10 +79,13 @@ describe('Options', () => {
6979
}
7080

7181
return webpack('css/index.js', config).then((stats) => {
72-
const src = loader(stats).src
82+
const { source } = stats.toJson().modules[1]
83+
84+
expect(source).toEqual(
85+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
86+
)
7387

74-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
75-
expect(src).toMatchSnapshot()
88+
expect(source).toMatchSnapshot()
7689
})
7790
})
7891
})

‎test/options/sourceMap.test.js

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
'use strict'
2-
31
const path = require('path')
4-
const webpack = require('../helpers/compiler')
5-
const { loader } = require('../helpers/compilation')
2+
const { webpack } = require('@webpack-utilities/test')
63

74
describe('Options', () => {
85
test('Sourcemap - {Boolean}', () => {
96
const config = {
7+
devtool: 'sourcemap',
108
loader: {
9+
test: /\.css$/,
1110
options: {
1211
sourceMap: true
1312
}
1413
}
1514
}
1615

1716
return webpack('css/index.js', config).then((stats) => {
18-
const src = loader(stats).src
17+
const { source } = stats.toJson().modules[1]
18+
19+
expect(source).toEqual(
20+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
21+
)
1922

20-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"')
21-
expect(src).toMatchSnapshot()
23+
expect(source).toMatchSnapshot()
2224

23-
const map = loader(stats).map
25+
const map = stats.compilation.modules[1]._source._sourceMap
2426

25-
map.file = path.relative(__dirname, map.file)
26-
map.sources = map.sources.map((src) => path.relative(__dirname, src))
27+
map.file = path.posix.relative(__dirname, map.file)
28+
map.sources = map.sources.map(
29+
(src) => path.posix.relative(__dirname, src)
30+
)
2731

2832
expect(map).toMatchSnapshot()
2933
})
@@ -32,17 +36,21 @@ describe('Options', () => {
3236
test('Sourcemap - {String}', () => {
3337
const config = {
3438
loader: {
39+
test: /\.css$/,
3540
options: {
3641
sourceMap: 'inline'
3742
}
3843
}
3944
}
4045

4146
return webpack('css/index.js', config).then((stats) => {
42-
const src = loader(stats).src
47+
const { source } = stats.toJson().modules[1]
48+
49+
expect(source).toEqual(
50+
'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvZml4dHVyZXMvY3NzL3N0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLDJCQUFZLEVBQUUiLCJmaWxlIjoidGVzdC9maXh0dXJlcy9jc3Mvc3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG4iXX0= */"'
51+
)
4352

44-
expect(src).toEqual('module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n\\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvZml4dHVyZXMvY3NzL3N0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLDJCQUFZLEVBQUUiLCJmaWxlIjoidGVzdC9maXh0dXJlcy9jc3Mvc3R5bGUuY3NzIiwic291cmNlc0NvbnRlbnQiOlsiYSB7IGNvbG9yOiBibGFjayB9XG4iXX0= */"')
45-
expect(src).toMatchSnapshot()
53+
expect(source).toMatchSnapshot()
4654
})
4755
})
4856
})

‎test/options/stringifier.test.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
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('Options', () => {
74
test('Stringifier - {String}', () => {
85
const config = {
96
loader: {
7+
test: /\.css$/,
108
options: {
119
stringifier: 'sugarss'
1210
}
1311
}
1412
}
1513

1614
return webpack('css/index.js', config).then((stats) => {
17-
const src = loader(stats).src
15+
const { source } = stats.toJson().modules[1]
1816

19-
expect(src).toEqual('module.exports = "a color: black\\n"')
20-
expect(src).toMatchSnapshot()
17+
expect(source).toEqual('module.exports = "a color: black\\n"')
18+
expect(source).toMatchSnapshot()
2119
})
2220
})
2321

2422
test('Stringifier - {Object}', () => {
2523
const config = {
2624
loader: {
25+
test: /\.css$/,
2726
options: {
2827
ident: 'postcss',
2928
stringifier: require('sugarss')
@@ -32,10 +31,10 @@ describe('Options', () => {
3231
}
3332

3433
return webpack('css/index.js', config).then((stats) => {
35-
const src = loader(stats).src
34+
const { source } = stats.toJson().modules[1]
3635

37-
expect(src).toEqual('module.exports = "a color: black\\n"')
38-
expect(src).toMatchSnapshot()
36+
expect(source).toEqual('module.exports = "a color: black\\n"')
37+
expect(source).toMatchSnapshot()
3938
})
4039
})
4140
})

‎test/options/syntax.test.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
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('Options', () => {
74
test('Syntax - {String}', () => {
85
const config = {
96
loader: {
7+
test: /\.sss$/,
108
options: {
119
syntax: 'sugarss'
1210
}
1311
}
1412
}
1513

1614
return webpack('sss/index.js', config).then((stats) => {
17-
const src = loader(stats).src
15+
const { source } = stats.toJson().modules[1]
1816

19-
expect(src).toEqual('module.exports = "a\\n color: black\\n"')
20-
expect(src).toMatchSnapshot()
17+
expect(source).toEqual('module.exports = "a\\n color: black\\n"')
18+
expect(source).toMatchSnapshot()
2119
})
2220
})
2321

2422
test('Syntax - {Object}', () => {
2523
const config = {
2624
loader: {
25+
test: /\.sss$/,
2726
options: {
2827
ident: 'postcss',
2928
syntax: require('sugarss')
@@ -32,10 +31,10 @@ describe('Options', () => {
3231
}
3332

3433
return webpack('sss/index.js', config).then((stats) => {
35-
const src = loader(stats).src
34+
const { source } = stats.toJson().modules[1]
3635

37-
expect(src).toEqual('module.exports = "a\\n color: black\\n"')
38-
expect(src).toMatchSnapshot()
36+
expect(source).toEqual('module.exports = "a\\n color: black\\n"')
37+
expect(source).toMatchSnapshot()
3938
})
4039
})
4140
})

0 commit comments

Comments
 (0)
Please sign in to comment.