forked from postcss/postcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.test.js
58 lines (49 loc) · 1.42 KB
/
result.test.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
let Warning = require('../lib/warning')
let postcss = require('../lib/postcss')
let Result = require('../lib/result')
it('stringifies', () => {
let result = new Result()
result.css = 'a{}'
expect('' + result).toEqual(result.css)
})
it('adds warning', () => {
let warning
let plugin = postcss.plugin('test-plugin', () => {
return (css, res) => {
warning = res.warn('test', { node: css.first })
}
})
let result = postcss([plugin]).process('a{}').sync()
expect(warning).toEqual(new Warning('test', {
plugin: 'test-plugin',
node: result.root.first
}))
expect(result.messages).toEqual([warning])
})
it('allows to override plugin', () => {
let plugin = postcss.plugin('test-plugin', () => {
return (css, res) => {
res.warn('test', { plugin: 'test-plugin#one' })
}
})
let result = postcss([plugin]).process('a{}').sync()
expect(result.messages[0].plugin).toEqual('test-plugin#one')
})
it('allows Root', () => {
let result = new Result()
let root = postcss.parse('a{}')
result.warn('TT', { node: root })
expect(result.messages[0].toString()).toEqual('<css input>:1:1: TT')
})
it('returns only warnings', () => {
let result = new Result()
result.messages = [
{ type: 'warning', text: 'a' },
{ type: 'custom' },
{ type: 'warning', text: 'b' }
]
expect(result.warnings()).toEqual([
{ type: 'warning', text: 'a' },
{ type: 'warning', text: 'b' }
])
})