-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy patherror.js
More file actions
96 lines (86 loc) · 2.75 KB
/
Copy patherror.js
File metadata and controls
96 lines (86 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import test from 'ava'
import tmp from './helpers/tmp.js'
import cli from './helpers/cli.js'
// ensure that configuration errors are thrown in watch mode as well as normal mode
;[false, true].forEach((watch) => {
const prefix = watch ? 'watch mode: ' : ''
const additionalArgs = watch ? ['--watch'] : []
test(`${prefix}multiple input files && --output`, (t) => {
return cli(['test/fixtures/*.css', '-o', tmp(), ...additionalArgs]).then(
({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(error.toString(), /Input Error: Must use --dir or --replace/)
},
)
})
test(`${prefix}plugin not found`, (t) => {
return cli([
'test/fixtures/a.css',
'-u',
'postcss-plugin',
'-o',
tmp(),
...additionalArgs,
]).then(({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(
error.toString(),
/Plugin Error: Cannot find package 'postcss-plugin'/,
)
})
})
test(`${prefix}plugin throws on require`, (t) => {
return cli([
'test/fixtures/a.css',
'-u',
'./test/fixtures/_bad-plugin.js',
'-o',
tmp(),
...additionalArgs,
]).then(({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(error.toString(), /Plugin Error \(.*bad-plugin.js\): This fails/)
})
})
test(`${prefix}fails on invalid explicit config`, async (t) => {
const output = tmp('output-ignore.css')
const { stderr, code } = await cli([
'test/fixtures/a.css',
'-o',
output,
'--config',
'/foo/bar',
...additionalArgs,
])
t.is(code, 1, 'expected non-zero error code')
t.regex(stderr, /No PostCSS Config found/)
})
})
// These errors cannot occur in watch mode; watch mode does not support stdout
test('multiple input files && writing to stdout', (t) => {
return cli(['test/fixtures/*.css']).then(({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(error.toString(), /Input Error: Must use --dir or --replace/)
})
})
test('--map && writing to stdout', (t) => {
return cli(['test/fixtures/a.css', '--map']).then(({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(
error.toString(),
/Output Error: Cannot output external sourcemaps when writing to STDOUT/,
)
})
})
// Watch mode does not exit on CssSyntaxError, this is tested in ./watch.js
test('CssSyntaxError', (t) => {
return cli(['test/fixtures/a.css', '--parser', 'sugarss', '-o', tmp()]).then(
({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(
error.toString(),
/CssSyntaxError: .*a.css:1:4: Unnecessary curly bracket/,
)
},
)
})