Skip to content

Commit 88060dc

Browse files
committed
Test core-js types with environment types
1 parent 689670f commit 88060dc

File tree

4 files changed

+54
-49
lines changed

4 files changed

+54
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ node_modules/
5353
/tests/compat/compat-data.js
5454
/tests/unit-global/index.js
5555
/tests/unit-pure/index.js
56+
/tests/type-definitions/tmp/
5657
/website/templates/
5758
/website/dist/
5859
/website/src/public/

tests/type-definitions/package-lock.json

Lines changed: 1 addition & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"name": "tests/type-definitions",
3-
"devDependencies": {
4-
"@core-js/types": "../../packages/core-js-types/",
5-
"typescript": "^5.9.3"
6-
}
2+
"name": "tests/type-definitions"
73
}

tests/type-definitions/runner.mjs

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os from 'node:os';
2+
import { fs } from 'zx';
23

3-
await $`tsc`;
4-
await $`tsc -p tsconfig.require.json`;
4+
const { mkdir, writeJson } = fs;
5+
const TMP_DIR = './tmp/';
56

67
const targets = [
78
'esnext',
@@ -19,8 +20,10 @@ const envs = [
1920
null,
2021
'@types/node@24',
2122
'@types/node@20',
22-
// '@types/node@18',
23-
'@types/bun@latest',
23+
'@types/node@18',
24+
'@types/node@16',
25+
// '@types/node@15', // fails
26+
// '@types/bun@latest', // fails
2427
];
2528
const types = [
2629
'global',
@@ -31,29 +34,40 @@ const libs = [
3134
'dom',
3235
];
3336

37+
let tested = 0;
38+
let failed = 0;
39+
40+
const getEnvPath = function (env) {
41+
if (!env) return null;
42+
return path.join(TMP_DIR, env.replaceAll('/', '-').replaceAll('@', ''));
43+
};
44+
3445
const runTestsOnEnv = async function ({ typeScriptVersion, target, type, env, lib }) {
3546
$.verbose = false;
36-
const command = `npx -p typescript@${ typeScriptVersion }${ env ? ` -p ${ env }` : '' } tsc -p proposals/${ type }/tsconfig.json --target ${ target }${ lib ? ` --lib ${ lib }` : '' }`;
47+
const envLibName = env ? env.substring(0, env.lastIndexOf('@')) : '';
48+
const command = `npx -p typescript@${ typeScriptVersion }${ env ? ` -p ${ env }` : '' } `
49+
+ `tsc -p proposals/${ type }/tsconfig.json --target ${ target }${ lib ? ` --lib ${ target },${ lib }` : '' }${ env ? ` --types @core-js/types,${ envLibName }` : '' }`;
3750
echo(`$ ${ command }`);
3851
try {
3952
if (env && lib) {
40-
await $`npx -p typescript@${ typeScriptVersion } -p ${ env } tsc -p proposals/${ type }/tsconfig.json --target ${ target } --lib ${ target },${ lib }`.quiet();
53+
await $({ cwd: getEnvPath(env) })`npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig.${ type }.json --target ${ target } --lib ${ target },${ lib } --types @core-js/types,${ envLibName }`.quiet();
4154
} else if (env) {
42-
await $`npx -p typescript@${ typeScriptVersion } -p ${ env } tsc -p proposals/${ type }/tsconfig.json --target ${ target }`.quiet();
55+
await $({ cwd: getEnvPath(env) })`npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig.${ type }.json --target ${ target } --types @core-js/types,${ envLibName }`.quiet();
4356
} else if (lib) {
4457
await $`npx -p typescript@${ typeScriptVersion } tsc -p proposals/${ type }/tsconfig.json --target ${ target } --lib ${ target },${ lib }`.quiet();
4558
} else {
4659
await $`npx -p typescript@${ typeScriptVersion } tsc -p proposals/${ type }/tsconfig.json --target ${ target }`.quiet();
4760
}
4861
echo(chalk.green(`$ ${ command }`));
62+
tested++;
4963
} catch (error) {
64+
tested++;
65+
failed++;
5066
echo(`$ ${ chalk.red(command) }\n ${ error }`);
51-
// eslint-disable-next-line node/no-process-exit -- it's needed here
52-
process.exit(1);
5367
}
5468
};
5569

56-
async function runLimited(configs, limit) {
70+
const runLimited = async function (configs, limit) {
5771
let i = 0;
5872
async function worker() {
5973
while (i < configs.length) {
@@ -62,7 +76,7 @@ async function runLimited(configs, limit) {
6276
}
6377
}
6478
await Promise.all(Array.from({ length: limit }, worker));
65-
}
79+
};
6680

6781
const taskConfigs = [];
6882
for (const type of types) {
@@ -77,8 +91,34 @@ for (const type of types) {
7791
}
7892
}
7993

94+
const clearTmpDir = async function () {
95+
await $`rm -rf ${ TMP_DIR }`;
96+
};
97+
98+
const prepareEnvironment = async function (environments, coreJsTypes) {
99+
await clearTmpDir();
100+
for (const env of environments) {
101+
if (!env) continue;
102+
const tmpEnvDir = getEnvPath(env);
103+
await mkdir(tmpEnvDir, { recursive: true });
104+
await $({ cwd: tmpEnvDir })`npm init -y > /dev/null 2>&1`;
105+
await $({ cwd: tmpEnvDir })`npm install ${ env }`;
106+
for (const type of coreJsTypes) {
107+
await writeJson(path.join(tmpEnvDir, `tsconfig.${ type }.json`), {
108+
extends: '../../tsconfig.json',
109+
include: [`../../proposals/${ type }/*.ts`],
110+
});
111+
}
112+
}
113+
};
114+
115+
await $`npx -p typescript@5.9 tsc`;
116+
await $`npx -p typescript@5.9 -p @types/node@24 tsc -p tsconfig.require.json`;
80117
const numCPUs = os.cpus().length;
118+
await prepareEnvironment(envs, types);
81119
await runLimited(taskConfigs, Math.max(numCPUs - 1, 1));
120+
await clearTmpDir();
121+
echo(`Tested: ${ chalk.green(tested) }, Failed: ${ chalk.red(failed) }`);
82122

83123
// await $`tsc -p proposals/global/tsconfig.esnext.json`;
84124
// await $`tsc -p proposals/global/tsconfig.es2023.json`;

0 commit comments

Comments
 (0)