Skip to content

Commit 7717637

Browse files
committed
add some tests
1 parent 551a129 commit 7717637

File tree

3 files changed

+134
-18
lines changed

3 files changed

+134
-18
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@
121121
"test-entries-basic": "zx tests/commonjs.mjs",
122122
"test-entries-content": "zx tests/commonjs-entries-content.mjs",
123123
"test-entries-standalone": "run-s init test-entries",
124+
"test-compat-tools": "run-p test-compat-tool test-targets-parser",
125+
"test-compat-tool": "zx tests/compat-tool.mjs",
124126
"test-targets-parser": "zx tests/targets-parser.mjs",
125-
"test": "run-s init test-lint bundle test-unit test-promises test-observables test-entries test-targets-parser check",
127+
"test": "run-s init test-lint bundle test-unit test-promises test-observables test-entries test-compat-tools check",
126128
"ci-karma": "run-s init bundle test-unit-karma",
127-
"ci-tests": "run-s init bundle test-unit-node test-promises test-observables test-entries test-targets-parser",
129+
"ci-tests": "run-s init bundle test-unit-node test-promises test-observables test-entries test-compat-tools",
128130
"clean-dependencies": "node scripts/clean-dependencies.mjs",
129131
"refresh": "npm run clean-dependencies && npm it",
130132
"downloads": "zx scripts/downloads-by-versions.mjs",

tests/compat-tool.mjs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { deepStrictEqual } from 'assert';
2+
const compat = require('core-js-compat/compat');
3+
4+
deepStrictEqual(compat({
5+
modules: [
6+
'core-js/es/math',
7+
'es.array.at',
8+
/^es\.reflect/,
9+
],
10+
exclude: [
11+
'es.reflect.prevent-extensions',
12+
],
13+
targets: 'firefox 27',
14+
}), {
15+
list: [
16+
'es.array.at',
17+
'es.math.clz32',
18+
'es.math.expm1',
19+
'es.math.to-string-tag',
20+
'es.reflect.apply',
21+
'es.reflect.construct',
22+
'es.reflect.define-property',
23+
'es.reflect.delete-property',
24+
'es.reflect.get',
25+
'es.reflect.get-own-property-descriptor',
26+
'es.reflect.get-prototype-of',
27+
'es.reflect.has',
28+
'es.reflect.is-extensible',
29+
'es.reflect.own-keys',
30+
'es.reflect.set',
31+
'es.reflect.set-prototype-of',
32+
'es.reflect.to-string-tag',
33+
],
34+
targets: {
35+
'es.array.at': { firefox: '27' },
36+
'es.math.clz32': { firefox: '27' },
37+
'es.math.expm1': { firefox: '27' },
38+
'es.math.to-string-tag': { firefox: '27' },
39+
'es.reflect.apply': { firefox: '27' },
40+
'es.reflect.construct': { firefox: '27' },
41+
'es.reflect.define-property': { firefox: '27' },
42+
'es.reflect.delete-property': { firefox: '27' },
43+
'es.reflect.get': { firefox: '27' },
44+
'es.reflect.get-own-property-descriptor': { firefox: '27' },
45+
'es.reflect.get-prototype-of': { firefox: '27' },
46+
'es.reflect.has': { firefox: '27' },
47+
'es.reflect.is-extensible': { firefox: '27' },
48+
'es.reflect.own-keys': { firefox: '27' },
49+
'es.reflect.set': { firefox: '27' },
50+
'es.reflect.set-prototype-of': { firefox: '27' },
51+
'es.reflect.to-string-tag': { firefox: '27' },
52+
},
53+
}, 'basic');
54+
55+
deepStrictEqual(compat({
56+
modules: [
57+
/^es\.math\.a/,
58+
/^es\.math\.c/,
59+
],
60+
exclude: 'es.math.asinh',
61+
}), {
62+
list: [
63+
'es.math.acosh',
64+
'es.math.atanh',
65+
'es.math.cbrt',
66+
'es.math.clz32',
67+
'es.math.cosh',
68+
],
69+
targets: {
70+
'es.math.acosh': {},
71+
'es.math.atanh': {},
72+
'es.math.cbrt': {},
73+
'es.math.clz32': {},
74+
'es.math.cosh': {},
75+
},
76+
}, 'no target');
77+
78+
deepStrictEqual(compat({
79+
modules: /^es\.math\.a/,
80+
}), {
81+
list: [
82+
'es.math.acosh',
83+
'es.math.asinh',
84+
'es.math.atanh',
85+
],
86+
targets: {
87+
'es.math.acosh': {},
88+
'es.math.asinh': {},
89+
'es.math.atanh': {},
90+
},
91+
}, 'no exclude');
92+
93+
deepStrictEqual(
94+
compat({ targets: { chrome: 93 } }),
95+
compat({ modules: 'core-js', targets: { chrome: 93 } }),
96+
'no modules',
97+
);
98+
99+
deepStrictEqual(compat({
100+
modules: 'core-js/es/math',
101+
targets: {
102+
chrome: 40,
103+
firefox: 27,
104+
},
105+
}), {
106+
list: [
107+
'es.math.acosh',
108+
'es.math.clz32',
109+
'es.math.expm1',
110+
'es.math.hypot',
111+
'es.math.to-string-tag',
112+
],
113+
targets: {
114+
'es.math.acosh': { chrome: '40' },
115+
'es.math.clz32': { firefox: '27' },
116+
'es.math.expm1': { firefox: '27' },
117+
'es.math.hypot': { chrome: '40' },
118+
'es.math.to-string-tag': { chrome: '40', firefox: '27' },
119+
},
120+
}, 'some targets');
121+
122+
console.log(chalk.green('compat tool tested'));

tests/targets-parser.mjs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { deepStrictEqual } from 'assert';
22
const targetsParser = require('core-js-compat/targets-parser');
33

4-
// browserslist
54
deepStrictEqual(targetsParser('ie 11, chrome 56, ios 12.2'), new Map([
65
['chrome', '56'],
76
['ie', '11'],
87
['ios', '12.2-12.5'],
9-
]));
8+
]), 'browserslist');
109

11-
// targets object
1210
deepStrictEqual(targetsParser({
1311
ie: 11,
1412
chrome: 56,
@@ -17,16 +15,14 @@ deepStrictEqual(targetsParser({
1715
['chrome', '56'],
1816
['ie', '11'],
1917
['ios', '12.2'],
20-
]));
18+
]), 'targets object');
2119

22-
// targets.browsers
2320
deepStrictEqual(targetsParser({ browsers: 'ie 11, chrome 56, ios_saf 12.2' }), new Map([
2421
['chrome', '56'],
2522
['ie', '11'],
2623
['ios', '12.2-12.5'],
27-
]));
24+
]), 'targets.browsers');
2825

29-
// targets.esmodules
3026
deepStrictEqual(targetsParser({ esmodules: true }), new Map([
3127
['android', '61'],
3228
['chrome', '61'],
@@ -38,19 +34,16 @@ deepStrictEqual(targetsParser({ esmodules: true }), new Map([
3834
['opera_mobile', '45'],
3935
['safari', '10.1'],
4036
['samsung', '8.0'],
41-
]));
37+
]), 'targets.esmodules');
4238

43-
// targets.node: current
4439
deepStrictEqual(targetsParser({ node: 'current' }), new Map([
4540
['node', String(process.versions.node)],
46-
]));
41+
]), 'targets.node: current');
4742

48-
// targets.node: version
4943
deepStrictEqual(targetsParser({ node: '13.2' }), new Map([
5044
['node', '13.2'],
51-
]));
45+
]), 'targets.node: version');
5246

53-
// normalization
5447
deepStrictEqual(targetsParser({
5548
ie_mob: 11,
5649
chromeandroid: 56,
@@ -65,9 +58,8 @@ deepStrictEqual(targetsParser({
6558
['ie', '11'],
6659
['ios', '12.2'],
6760
['opera_mobile', '40'],
68-
]));
61+
]), 'normalization');
6962

70-
// mixed
7163
deepStrictEqual(targetsParser({
7264
esmodules: true,
7365
node: 'current',
@@ -97,6 +89,6 @@ deepStrictEqual(targetsParser({
9789
['opera_mobile', '40'],
9890
['safari', '5.1'],
9991
['samsung', '4'],
100-
]));
92+
]), 'mixed');
10193

10294
console.log(chalk.green('targets parser tested'));

0 commit comments

Comments
 (0)