forked from adamlaska/browser-compat-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisit.test.js
More file actions
63 lines (57 loc) · 1.5 KB
/
visit.test.js
File metadata and controls
63 lines (57 loc) · 1.5 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
const assert = require('assert').strict;
const visit = require('./visit');
const { walk } = require('./walk');
describe('visit()', function () {
it('runs the function on all features if no other entry point is specified', function () {
const walker = walk();
visit(visitorPath => {
assert.equal(visitorPath, walker.next().value.path);
});
});
it('skips features not selected by testFn', function () {
const hits = new Set();
const misses = new Set();
visit(
path => {
hits.add(path);
},
{
entryPoint: 'css',
test(path) {
if (path.includes('at-rules')) {
return true;
}
misses.add(path);
return false;
},
},
);
for (const miss in misses) {
assert.ok(!hits.has(miss));
}
});
it('visitorFn can break iteration', function () {
visit(path => {
if (path.startsWith('css')) {
return visit.BREAK;
}
if (path.startsWith('html')) {
assert.fail(
`visitorFn should never be invoked after the css tree. Reached ${path}`,
);
}
});
});
it('visitorFn can skip traversal of children', function () {
visit(path => {
if (path === 'css.at-rules.counter-style') {
return visit.CONTINUE;
}
if (path.startsWith('css.at-rules-counter-style.')) {
assert.fail(
`visitorFn should never reach a child of counter-style. Reached ${path}`,
);
}
});
});
});