-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy patherror.js
65 lines (58 loc) · 1.83 KB
/
error.js
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
import test from 'ava'
import tmp from './helpers/tmp.js'
import cli from './helpers/cli.js'
test('multiple input files && --output', (t) => {
return cli(['test/fixtures/*.css', '-o', tmp()]).then(({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(error.toString(), /Input Error: Must use --dir or --replace/)
})
})
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/
)
})
})
test('plugin not found', (t) => {
return cli(['test/fixtures/a.css', '-u', 'postcss-plugin', '-o', tmp()]).then(
({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(
error.toString(),
/Plugin Error: Cannot find package 'postcss-plugin'/
)
}
)
})
test('plugin throws on require', (t) => {
return cli([
'test/fixtures/a.css',
'-u',
'./test/fixtures/_bad-plugin.js',
'-o',
tmp(),
]).then(({ error, code }) => {
t.is(code, 1, 'expected non-zero error code')
t.regex(error.toString(), /Plugin Error \(.*bad-plugin.js\): This fails/)
})
})
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/
)
}
)
})