forked from mdn/browser-compat-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
walk.test.ts
67 lines (57 loc) · 2.01 KB
/
walk.test.ts
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
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */
import assert from 'node:assert/strict';
import bcd from '../index.js';
import walk, { lowLevelWalk } from './walk.js';
describe('lowLevelWalk()', () => {
it('visits every top-level tree', () => {
const expectedPaths = [
'api',
'browsers',
'css',
'html',
'http',
'javascript',
'mathml',
'svg',
'webassembly',
'webdriver',
'webextensions',
];
const steps = Array.from(lowLevelWalk(undefined, undefined, 1));
const paths = steps.map((step) => step.path);
assert.equal(steps.length, expectedPaths.length);
assert.deepEqual(paths, expectedPaths);
});
it('visits every point in the tree', () => {
const paths = Array.from(lowLevelWalk()).map((step) => step.path);
assert.ok(paths.length > 13000);
});
});
describe('walk()', () => {
it('should visit deeply nested features', () => {
const results = Array.from(walk('html')).map((feature) => feature.path);
assert.ok(results.includes('html.elements.a.href.href_top'));
});
it('should walk a single tree', () => {
const results = Array.from(walk('api.Notification'));
assert.equal(results.length, 27);
assert.equal(results[0].path, 'api.Notification');
assert.equal(results[1].path, 'api.Notification.Notification');
});
it('should walk multiple trees', () => {
const results = Array.from(
walk(['api.Notification', 'css.properties.color']),
);
assert.equal(results.length, 28);
assert.equal(results[0].path, 'api.Notification');
assert.equal(results[results.length - 1].path, 'css.properties.color');
});
it('should yield every feature by default', () => {
const featureCountFromString = JSON.stringify(bcd, undefined, 2)
.split('\n')
.filter((line) => line.includes('__compat')).length;
const featureCountFromWalk = Array.from(walk()).length;
assert.equal(featureCountFromString, featureCountFromWalk);
});
});