Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 11, 2022
1 parent 551a129 commit 7717637
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 18 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@
"test-entries-basic": "zx tests/commonjs.mjs",
"test-entries-content": "zx tests/commonjs-entries-content.mjs",
"test-entries-standalone": "run-s init test-entries",
"test-compat-tools": "run-p test-compat-tool test-targets-parser",
"test-compat-tool": "zx tests/compat-tool.mjs",
"test-targets-parser": "zx tests/targets-parser.mjs",
"test": "run-s init test-lint bundle test-unit test-promises test-observables test-entries test-targets-parser check",
"test": "run-s init test-lint bundle test-unit test-promises test-observables test-entries test-compat-tools check",
"ci-karma": "run-s init bundle test-unit-karma",
"ci-tests": "run-s init bundle test-unit-node test-promises test-observables test-entries test-targets-parser",
"ci-tests": "run-s init bundle test-unit-node test-promises test-observables test-entries test-compat-tools",
"clean-dependencies": "node scripts/clean-dependencies.mjs",
"refresh": "npm run clean-dependencies && npm it",
"downloads": "zx scripts/downloads-by-versions.mjs",
Expand Down
122 changes: 122 additions & 0 deletions tests/compat-tool.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { deepStrictEqual } from 'assert';
const compat = require('core-js-compat/compat');

deepStrictEqual(compat({
modules: [
'core-js/es/math',
'es.array.at',
/^es\.reflect/,
],
exclude: [
'es.reflect.prevent-extensions',
],
targets: 'firefox 27',
}), {
list: [
'es.array.at',
'es.math.clz32',
'es.math.expm1',
'es.math.to-string-tag',
'es.reflect.apply',
'es.reflect.construct',
'es.reflect.define-property',
'es.reflect.delete-property',
'es.reflect.get',
'es.reflect.get-own-property-descriptor',
'es.reflect.get-prototype-of',
'es.reflect.has',
'es.reflect.is-extensible',
'es.reflect.own-keys',
'es.reflect.set',
'es.reflect.set-prototype-of',
'es.reflect.to-string-tag',
],
targets: {
'es.array.at': { firefox: '27' },
'es.math.clz32': { firefox: '27' },
'es.math.expm1': { firefox: '27' },
'es.math.to-string-tag': { firefox: '27' },
'es.reflect.apply': { firefox: '27' },
'es.reflect.construct': { firefox: '27' },
'es.reflect.define-property': { firefox: '27' },
'es.reflect.delete-property': { firefox: '27' },
'es.reflect.get': { firefox: '27' },
'es.reflect.get-own-property-descriptor': { firefox: '27' },
'es.reflect.get-prototype-of': { firefox: '27' },
'es.reflect.has': { firefox: '27' },
'es.reflect.is-extensible': { firefox: '27' },
'es.reflect.own-keys': { firefox: '27' },
'es.reflect.set': { firefox: '27' },
'es.reflect.set-prototype-of': { firefox: '27' },
'es.reflect.to-string-tag': { firefox: '27' },
},
}, 'basic');

deepStrictEqual(compat({
modules: [
/^es\.math\.a/,
/^es\.math\.c/,
],
exclude: 'es.math.asinh',
}), {
list: [
'es.math.acosh',
'es.math.atanh',
'es.math.cbrt',
'es.math.clz32',
'es.math.cosh',
],
targets: {
'es.math.acosh': {},
'es.math.atanh': {},
'es.math.cbrt': {},
'es.math.clz32': {},
'es.math.cosh': {},
},
}, 'no target');

deepStrictEqual(compat({
modules: /^es\.math\.a/,
}), {
list: [
'es.math.acosh',
'es.math.asinh',
'es.math.atanh',
],
targets: {
'es.math.acosh': {},
'es.math.asinh': {},
'es.math.atanh': {},
},
}, 'no exclude');

deepStrictEqual(
compat({ targets: { chrome: 93 } }),
compat({ modules: 'core-js', targets: { chrome: 93 } }),
'no modules',
);

deepStrictEqual(compat({
modules: 'core-js/es/math',
targets: {
chrome: 40,
firefox: 27,
},
}), {
list: [
'es.math.acosh',
'es.math.clz32',
'es.math.expm1',
'es.math.hypot',
'es.math.to-string-tag',
],
targets: {
'es.math.acosh': { chrome: '40' },
'es.math.clz32': { firefox: '27' },
'es.math.expm1': { firefox: '27' },
'es.math.hypot': { chrome: '40' },
'es.math.to-string-tag': { chrome: '40', firefox: '27' },
},
}, 'some targets');

console.log(chalk.green('compat tool tested'));
24 changes: 8 additions & 16 deletions tests/targets-parser.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { deepStrictEqual } from 'assert';
const targetsParser = require('core-js-compat/targets-parser');

// browserslist
deepStrictEqual(targetsParser('ie 11, chrome 56, ios 12.2'), new Map([
['chrome', '56'],
['ie', '11'],
['ios', '12.2-12.5'],
]));
]), 'browserslist');

// targets object
deepStrictEqual(targetsParser({
ie: 11,
chrome: 56,
Expand All @@ -17,16 +15,14 @@ deepStrictEqual(targetsParser({
['chrome', '56'],
['ie', '11'],
['ios', '12.2'],
]));
]), 'targets object');

// targets.browsers
deepStrictEqual(targetsParser({ browsers: 'ie 11, chrome 56, ios_saf 12.2' }), new Map([
['chrome', '56'],
['ie', '11'],
['ios', '12.2-12.5'],
]));
]), 'targets.browsers');

// targets.esmodules
deepStrictEqual(targetsParser({ esmodules: true }), new Map([
['android', '61'],
['chrome', '61'],
Expand All @@ -38,19 +34,16 @@ deepStrictEqual(targetsParser({ esmodules: true }), new Map([
['opera_mobile', '45'],
['safari', '10.1'],
['samsung', '8.0'],
]));
]), 'targets.esmodules');

// targets.node: current
deepStrictEqual(targetsParser({ node: 'current' }), new Map([
['node', String(process.versions.node)],
]));
]), 'targets.node: current');

// targets.node: version
deepStrictEqual(targetsParser({ node: '13.2' }), new Map([
['node', '13.2'],
]));
]), 'targets.node: version');

// normalization
deepStrictEqual(targetsParser({
ie_mob: 11,
chromeandroid: 56,
Expand All @@ -65,9 +58,8 @@ deepStrictEqual(targetsParser({
['ie', '11'],
['ios', '12.2'],
['opera_mobile', '40'],
]));
]), 'normalization');

// mixed
deepStrictEqual(targetsParser({
esmodules: true,
node: 'current',
Expand Down Expand Up @@ -97,6 +89,6 @@ deepStrictEqual(targetsParser({
['opera_mobile', '40'],
['safari', '5.1'],
['samsung', '4'],
]));
]), 'mixed');

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

0 comments on commit 7717637

Please sign in to comment.