Skip to content

Commit 824a7de

Browse files
authored
chore: fix error assertions (#264)
* chore: fix error assertions * organize a bit * remove test
1 parent de0dab0 commit 824a7de

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

test/Errors.test.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,70 @@
11
const { describe, test } = require('node:test')
2-
const { match } = require('node:assert')
2+
const { rejects } = require('node:assert')
33

44
const postcssrc = require('../src/index.js')
55

6-
test('Loading Config - {Error}', () => {
7-
return postcssrc({}, 'test/err').catch(err => {
8-
match(err.message, /^No PostCSS Config found in: (.*)$/)
6+
describe('Loading Config - {Error}', () => {
7+
test('Missing Directory', () => {
8+
return rejects(() => postcssrc({}, 'ghostDir'), {
9+
message: /^No PostCSS Config found in: (.*)$/
10+
})
11+
})
12+
13+
test('TS - Syntax', () => {
14+
return rejects(() => postcssrc({}, 'test/err/ts'), {
15+
message: /^(Transform failed|ParseError)/
16+
})
917
})
1018
})
1119

1220
describe('Loading Plugins - {Error}', () => {
1321
test('Plugin - {Type} - Invalid', () => {
14-
return postcssrc({}, 'test/err/plugins').catch(err => {
15-
match(err.message, /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/)
22+
return rejects(() => postcssrc({}, 'test/err/plugins'), {
23+
message: /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/
1624
})
1725
})
1826

1927
test('Plugin - {Object}', () => {
20-
return postcssrc({}, 'test/err/plugins/object').catch(err => {
21-
match(err.message, /^Loading PostCSS Plugin failed: .*$/m)
28+
return rejects(() => postcssrc({}, 'test/err/plugins/object'), {
29+
message: /^Loading PostCSS Plugin failed: .*$/m
2230
})
2331
})
2432

2533
test('Plugin - {Object} - Options', () => {
26-
return postcssrc({}, 'test/err/plugins/object/options').catch(err => {
27-
match(err.message, /^Loading PostCSS Plugin failed: .*$/m)
34+
return rejects(() => postcssrc({}, 'test/err/plugins/object/options'), {
35+
message: /^Loading PostCSS Plugin failed: .*$/m
2836
})
2937
})
3038

3139
test('Plugin - {Array}', () => {
32-
return postcssrc({}, 'test/err/plugins/array').catch(err => {
33-
match(err.message, /^Cannot find (.*)$/m)
40+
return rejects(() => postcssrc({}, 'test/err/plugins/array'), {
41+
message: /^Cannot find (.*)$/m
3442
})
3543
})
3644

3745
test('Plugin - {Array} - Options', () => {
38-
return postcssrc({}, 'test/err/plugins/array/options').catch(err => {
39-
match(err.message, /^Cannot find (.*)$/m)
46+
return rejects(() => postcssrc({}, 'test/err/plugins/array/options'), {
47+
message: /^Cannot find (.*)$/m
4048
})
4149
})
4250
})
4351

4452
describe('Loading Options - {Error}', () => {
4553
test('Parser - {String}', () => {
46-
return postcssrc({}, 'test/err/options/parser').catch(err => {
47-
match(err.message, /^Loading PostCSS Parser failed: .*$/m)
54+
return rejects(() => postcssrc({}, 'test/err/options/parser'), {
55+
message: /^Loading PostCSS Parser failed: .*$/m
4856
})
4957
})
5058

5159
test('Syntax - {String}', () => {
52-
return postcssrc({}, 'test/err/options/syntax').catch(err => {
53-
match(err.message, /^Loading PostCSS Syntax failed: .*$/m)
60+
return rejects(() => postcssrc({}, 'test/err/options/syntax'), {
61+
message: /^Loading PostCSS Syntax failed: .*$/m
5462
})
5563
})
5664

5765
test('Stringifier - {String}', () => {
58-
return postcssrc({}, 'test/err/options/stringifier').catch(err => {
59-
match(err.message, /^Loading PostCSS Stringifier failed: .*$/m)
66+
return rejects(() => postcssrc({}, 'test/err/options/stringifier'), {
67+
message: /^Loading PostCSS Stringifier failed: .*$/m
6068
})
6169
})
6270
})
63-
64-
test('Loading TS Config - {Error} - Syntax', () => {
65-
return postcssrc({}, 'test/err/ts').catch(err => {
66-
match(err.message, /^(Transform failed|ParseError)/)
67-
})
68-
})

test/rc.test.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,3 @@ test('.postcssrc - {Object} - Process SSS', () => {
5454
})
5555
})
5656
})
57-
58-
describe('Load Config Error', () => {
59-
test('no config found error', () => {
60-
return postcssrc({}, 'ghostDir')
61-
.catch(error => {
62-
equal(error.message.startsWith("No PostCSS Config found in:"), true)
63-
})
64-
})
65-
})

0 commit comments

Comments
 (0)