forked from mdn/browser-compat-data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatistics.test.ts
71 lines (64 loc) · 2.14 KB
/
statistics.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
68
69
70
71
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */
import assert from 'node:assert/strict';
import getStats from './statistics.js';
describe('getStats', () => {
let bcd: any;
beforeEach(() => {
bcd = {
browsers: {
chrome: {},
firefox: {},
safari: {},
},
webextensions: {
feature1: {
__compat: {
support: {
chrome: { version_added: '≤1' },
firefox: { version_added: '1' },
safari: { version_added: null },
},
},
},
},
api: {
feature2: {
__compat: {
support: {
chrome: { version_added: '1' },
firefox: { version_added: null },
safari: { version_added: '1' },
},
},
},
},
};
});
it('should return stats for all browsers when allBrowsers is true', () => {
const stats = getStats('api', true, bcd);
assert.deepEqual(stats, {
total: { all: 3, true: 0, null: 1, range: 0, real: 2 },
chrome: { all: 1, true: 0, null: 0, range: 0, real: 1 },
firefox: { all: 1, true: 0, null: 1, range: 0, real: 0 },
safari: { all: 1, true: 0, null: 0, range: 0, real: 1 },
});
});
it('should return stats for webextensions browsers when folder is "webextensions"', () => {
const stats = getStats('webextensions', false, bcd);
assert.deepEqual(stats, {
total: { all: 7, true: 0, null: 5, range: 1, real: 1 },
chrome: { all: 1, true: 0, null: 0, range: 1, real: 0 },
edge: { all: 1, true: 0, null: 1, range: 0, real: 0 },
firefox: { all: 1, true: 0, null: 0, range: 0, real: 1 },
opera: { all: 1, true: 0, null: 1, range: 0, real: 0 },
safari: { all: 1, true: 0, null: 1, range: 0, real: 0 },
firefox_android: { all: 1, true: 0, null: 1, range: 0, real: 0 },
safari_ios: { all: 1, true: 0, null: 1, range: 0, real: 0 },
});
});
it('should return null when folder does not exist', () => {
const stats = getStats('nonexistent', false, bcd);
assert.equal(stats, null);
});
});