Skip to content

Commit

Permalink
addget-modules-list-for-target-version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 12, 2022
1 parent eff765f commit 1e07b0c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ module.exports = {
{
files: [
'scripts/**',
'tests/*.mjs',
'tests/**/*.mjs',
],
// zx
globals: {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@
"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-compat-tools": "run-p test-compat-tool test-compat-targets-parser test-compat-get-modules-list-for-target-version",
"test-compat-tool": "zx tests/compat-tools/compat.mjs",
"test-compat-targets-parser": "zx tests/compat-tools/targets-parser.mjs",
"test-compat-get-modules-list-for-target-version": "zx tests/compat-tools/get-modules-list-for-target-version.mjs",
"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-compat-tools",
Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/compat-tools/get-modules-list-for-target-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { deepStrictEqual, throws } from 'assert';
import getModulesListForTargetVersion from 'core-js-compat/get-modules-list-for-target-version.js';

const modules = require('core-js-compat/modules');
const modulesByVersions = require('../../packages/core-js-compat/modules-by-versions');

const modules30 = modulesByVersions['3.0'];
const filter = new Set([...modules30, ...modulesByVersions['3.1']]);
const modules31 = modules.filter(it => filter.has(it));

deepStrictEqual(getModulesListForTargetVersion(3), modules30, 'num 3'); // TODO: Make it throw in core-js@4
deepStrictEqual(getModulesListForTargetVersion('3'), modules30, '3'); // TODO: Make it throw in core-js@4
deepStrictEqual(getModulesListForTargetVersion('3.0'), modules30, '3.0');
deepStrictEqual(getModulesListForTargetVersion('3.0.0'), modules30, '3.0.0');
deepStrictEqual(getModulesListForTargetVersion('3.0.1'), modules30, '3.0.1');
deepStrictEqual(getModulesListForTargetVersion('3.0.0-alpha.1'), modules30, '3.0.0-alpha.1');
deepStrictEqual(getModulesListForTargetVersion('3.1'), modules31, '3.1');
deepStrictEqual(getModulesListForTargetVersion('3.1.0'), modules31, '3.1.0');
deepStrictEqual(getModulesListForTargetVersion('3.1.1'), modules31, '3.1.1');

throws(() => getModulesListForTargetVersion('2.0'), RangeError, '2.0');
throws(() => getModulesListForTargetVersion('4.0'), RangeError, '4.0');
throws(() => getModulesListForTargetVersion('x'), TypeError, 'x');
throws(() => getModulesListForTargetVersion('*'), TypeError, '*');
throws(() => getModulesListForTargetVersion(), TypeError, 'no arg');

console.log(chalk.green('get-modules-list-for-target-version tested'));
File renamed without changes.
1 change: 0 additions & 1 deletion tests/compat/deno-runner.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console -- output */
import './tests.js';

var tests = globalThis.tests;
Expand Down

0 comments on commit 1e07b0c

Please sign in to comment.