-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
71 lines (55 loc) · 1.93 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
let fs = require('fs')
let postcss = require('postcss')
let plugin = require('./')
function testEqualResult(input, output, opts) {
return postcss([plugin(opts)])
.process(input, { from: undefined })
.then(result => {
expect(result.css).toEqual(output)
expect(result.warnings()).toHaveLength(0)
})
}
function testSkippedCounter(input) {
return postcss([plugin()])
.process(input, { from: undefined })
.then(result => {
let etalon = {
'.skipped-no-overflow': 1,
'.skipped-with-overflow': 1,
}
let targets = Object.keys(etalon)
let counters = {}
result.root.nodes.forEach(rule => {
if (targets.includes(rule.selector)) {
// get all items with Symbol() in key
let symbols = Object.getOwnPropertySymbols(rule);
symbols.forEach(key => {
if (key.description === 'skippedCounter') {
counters[rule.selector] = rule[key]
}
})
}
})
expect(etalon).toMatchObject(counters)
expect(result.warnings()).toHaveLength(0)
})
}
it('if has momentum scroll, do nothing', () => {
let input = fs.readFileSync('./test/has-momentum.in.css', 'utf8')
let output = fs.readFileSync('./test/has-momentum.out.css', 'utf8')
return testEqualResult(input, output)
})
it('custom options (hidden, inherit)', () => {
let input = fs.readFileSync('./test/custom-opts.in.css', 'utf8')
let output = fs.readFileSync('./test/custom-opts.out.css', 'utf8')
return testEqualResult(input, output, ['hidden', 'inherit'])
})
it('if options is not array', () => {
let input = fs.readFileSync('./test/has-momentum.in.css', 'utf8')
let output = fs.readFileSync('./test/has-momentum.out.css', 'utf8')
return testEqualResult(input, output, 'postcss')
})
it('skip if already processed', () => {
let input = fs.readFileSync('./test/has-momentum.in.css', 'utf8')
return testSkippedCounter(input)
})