Skip to content

Commit fa66cff

Browse files
committed
Specific tests for some envs
1 parent 16bd140 commit fa66cff

File tree

6 files changed

+65
-29
lines changed

6 files changed

+65
-29
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'core-js/full';
2+
3+
const aitn = AsyncIterator.from([1]);
4+
for await (const v of aitn) {}
5+
6+
const ait1 = aitn.filter((v: number, i: number) => v > 0);
7+
for await (const v of ait1) {}
8+
9+
const ait2 = aitn.flatMap((v: number, i: number) => `${ v }`);
10+
for await (const v of ait2) {}
11+
12+
const ait3 = aitn.map((v: number, i: number) => v * 2);
13+
for await (const v of ait3) {}
14+
15+
const ait4 = aitn.take(10);
16+
for await (const v of ait4) {}
17+
18+
const ait5 = aitn.drop(3);
19+
for await (const v of ait5) {}
20+
21+
declare const itn: Iterator<number>;
22+
const ait6 = itn.toAsync();
23+
for await (const v of ait6) {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["./**/*.ts"],
4+
"exclude": ["./**/*es2018*test.ts"],
5+
"compilerOptions": {
6+
"types": ["@core-js/types"]
7+
}
8+
}

tests/type-definitions/pure/async-iteration.test.ts renamed to tests/type-definitions/pure/proposals/async-iterator-helper.es2018.test.ts

File renamed without changes.

tests/type-definitions/pure/tsconfig.async-iteration.json renamed to tests/type-definitions/pure/tsconfig.es6.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../tsconfig.json",
3-
"include": ["./async-iteration.test.ts"],
3+
"include": ["./**/*.ts"],
4+
"exclude": ["./**/*es2018*test.ts"],
45
"compilerOptions": {
56
"types": ["@core-js/types/pure"]
67
}

tests/type-definitions/pure/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "../tsconfig.json",
33
"include": ["./**/*.ts"],
4-
"exclude": ["async-iteration.test.ts"],
54
"compilerOptions": {
65
"types": ["@core-js/types/pure"]
76
}

tests/type-definitions/runner.mjs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const { mkdir, writeJson } = fs;
55
const TMP_DIR = './tmp/';
66
const ALL_TESTS = process.env.ALL_TYPE_DEFINITIONS_TESTS === '1';
77

8-
const targets = [
8+
const TARGETS = [
99
'esnext',
1010
'es2022',
1111
'es6',
1212
];
13-
const typeScriptVersions = [
13+
const TYPE_SCRIPT_VERSIONS = [
1414
'5.9',
1515
'5.8',
1616
'5.7',
@@ -20,7 +20,7 @@ const typeScriptVersions = [
2020
// '5.3',
2121
// '5.2',
2222
];
23-
const envs = [
23+
const ENVS = [
2424
null,
2525
'@types/node@24',
2626
'@types/node@20',
@@ -29,14 +29,17 @@ const envs = [
2929
// '@types/node@15', // fails
3030
// '@types/bun@latest', // conflicts with DOM types (TextDecorator, SharedArrayBuffer...)
3131
];
32-
const types = [
32+
const TYPES = [
3333
'global',
3434
'pure',
3535
];
36-
const libs = [
36+
const LIBS = [
3737
'dom',
3838
// null, // fails on web types
3939
];
40+
const TARGET_EXCLUDES = {
41+
'es6': ['**/*es2018*test.ts'],
42+
}
4043

4144
let tested = 0;
4245
let failed = 0;
@@ -49,20 +52,21 @@ function getEnvPath(env) {
4952
async function runTestsOnEnv({ typeScriptVersion, target, type, env, lib }) {
5053
$.verbose = false;
5154
const envLibName = env ? env.substring(0, env.lastIndexOf('@')) : '';
55+
const tsConfigPostfix = TARGET_EXCLUDES[target] ? `.${ target }` : '';
5256
const command = `npx -p typescript@${ typeScriptVersion }${
53-
env ? ` -p ${ env }` : '' } tsc -p ${ type }/tsconfig.json --target ${ target } --lib ${ target }${ lib ? `,${ lib }` : '' }${
57+
env ? ` -p ${ env }` : '' } tsc -p ${ type }/tsconfig${ tsConfigPostfix }.json --target ${ target } --lib ${ target }${ lib ? `,${ lib }` : '' }${
5458
env ? ` --types @core-js/types${ type === 'pure' ? '/pure' : '' },${ envLibName }` : '' }`;
5559
echo(`$ ${ command }`);
5660
try {
5761
tested++;
5862
if (env && lib) {
59-
await $({ cwd: getEnvPath(env) })`npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig.${ type }.json --target ${ target } --lib ${ target },${ lib } --types @core-js/types${ type === 'pure' ? '/pure' : '' },${ envLibName }`.quiet();
63+
await $({ cwd: getEnvPath(env) })`npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig.${ type }${ tsConfigPostfix }.json --target ${ target } --lib ${ target },${ lib } --types @core-js/types${ type === 'pure' ? '/pure' : '' },${ envLibName }`.quiet();
6064
} else if (env) {
61-
await $({ cwd: getEnvPath(env) })`npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig.${ type }.json --target ${ target } --lib ${ target } --types @core-js/types${ type === 'pure' ? '/pure' : '' },${ envLibName }`.quiet();
65+
await $({ cwd: getEnvPath(env) })`npx -p typescript@${ typeScriptVersion } tsc -p ./tsconfig.${ type }${ tsConfigPostfix }.json --target ${ target } --lib ${ target } --types @core-js/types${ type === 'pure' ? '/pure' : '' },${ envLibName }`.quiet();
6266
} else if (lib) {
63-
await $`npx -p typescript@${ typeScriptVersion } tsc -p ${ type }/tsconfig.json --target ${ target } --lib ${ target },${ lib }`.quiet();
67+
await $`npx -p typescript@${ typeScriptVersion } tsc -p ${ type }/tsconfig${ tsConfigPostfix }.json --target ${ target } --lib ${ target },${ lib }`.quiet();
6468
} else {
65-
await $`npx -p typescript@${ typeScriptVersion } tsc -p ${ type }/tsconfig.json --target ${ target } --lib ${ target }`.quiet();
69+
await $`npx -p typescript@${ typeScriptVersion } tsc -p ${ type }/tsconfig${ tsConfigPostfix }.json --target ${ target } --lib ${ target }`.quiet();
6670
}
6771
echo(chalk.green(`$ ${ command }`));
6872
} catch (error) {
@@ -83,11 +87,11 @@ async function runLimited(configs, limit) {
8387
}
8488

8589
const taskConfigs = [];
86-
for (const type of types) {
87-
for (const target of targets) {
88-
for (const typeScriptVersion of typeScriptVersions) {
89-
for (const env of envs) {
90-
for (const lib of libs) {
90+
for (const type of TYPES) {
91+
for (const target of TARGETS) {
92+
for (const typeScriptVersion of TYPE_SCRIPT_VERSIONS) {
93+
for (const env of ENVS) {
94+
for (const lib of LIBS) {
9195
taskConfigs.push({ env, lib, target, type, typeScriptVersion });
9296
}
9397
}
@@ -99,7 +103,7 @@ async function clearTmpDir() {
99103
await $`rm -rf ${ TMP_DIR }`;
100104
}
101105

102-
async function prepareEnvironment(environments, coreJsTypes) {
106+
async function prepareEnvironment(environments, coreJsTypes, targetExcludes) {
103107
await clearTmpDir();
104108
for (const env of environments) {
105109
if (!env) continue;
@@ -111,8 +115,14 @@ async function prepareEnvironment(environments, coreJsTypes) {
111115
await writeJson(path.join(tmpEnvDir, `tsconfig.${ type }.json`), {
112116
extends: '../../tsconfig.json',
113117
include: [`../../${ type }/**/*.ts`],
114-
exclude: [`../../${ type }/async-iteration.test.ts`],
115118
});
119+
for (const [target, patterns] of Object.entries(targetExcludes)) {
120+
await writeJson(path.join(tmpEnvDir, `tsconfig.${ type }.${ target }.json`), {
121+
extends: '../../tsconfig.json',
122+
include: [`../../${ type }/**/*.ts`],
123+
exclude: patterns.map(pattern => `../../${ pattern }`),
124+
});
125+
}
116126
}
117127
}
118128
}
@@ -123,26 +133,21 @@ await $`npx -p typescript@5.9 tsc -p tsconfig.entries.json`;
123133
await $`npx -p typescript@5.9 tsc -p tsconfig.entries.pure.json`;
124134
await $`npx -p typescript@5.9 -p @types/node@24 tsc -p tsconfig.templates.require.json`;
125135

126-
await $`npx -p typescript@5.6 tsc -p pure/tsconfig.async-iteration.json --target es2023 --lib es2023`;
127-
await $`npx -p typescript@5.6 tsc -p pure/tsconfig.async-iteration.json --target esnext --lib esnext`;
128-
await $`npx -p typescript@5.9 tsc -p pure/tsconfig.async-iteration.json --target es2023 --lib es2023`;
129-
await $`npx -p typescript@5.9 tsc -p pure/tsconfig.async-iteration.json --target esnext --lib esnext`;
130-
131136
if (!ALL_TESTS) {
132-
await $`npx -p typescript@5.6 tsc -p pure/tsconfig.json --target es6 --lib es6`;
137+
await $`npx -p typescript@5.6 tsc -p pure/tsconfig.es6.json --target es6 --lib es6`;
133138
await $`npx -p typescript@5.6 tsc -p pure/tsconfig.json --target esnext --lib esnext`;
134-
await $`npx -p typescript@5.6 tsc -p global/tsconfig.json --target es6 --lib es6,dom`;
139+
await $`npx -p typescript@5.6 tsc -p global/tsconfig.es6.json --target es6 --lib es6,dom`;
135140
await $`npx -p typescript@5.6 tsc -p global/tsconfig.json --target esnext --lib esnext,dom`;
136141

137-
await $`npx -p typescript@5.9 tsc -p pure/tsconfig.json --target es6 --lib es6`;
142+
await $`npx -p typescript@5.9 tsc -p pure/tsconfig.es6.json --target es6 --lib es6`;
138143
await $`npx -p typescript@5.9 tsc -p pure/tsconfig.json --target es2023 --lib es2023`;
139144
await $`npx -p typescript@5.9 tsc -p pure/tsconfig.json --target esnext --lib esnext`;
140-
await $`npx -p typescript@5.9 tsc -p global/tsconfig.json --target es6 --lib es6,dom`;
145+
await $`npx -p typescript@5.9 tsc -p global/tsconfig.es6.json --target es6 --lib es6,dom`;
141146
await $`npx -p typescript@5.9 tsc -p global/tsconfig.json --target es2023 --lib es2023,dom`;
142147
await $`npx -p typescript@5.9 tsc -p global/tsconfig.json --target esnext --lib esnext,dom`;
143148
} else {
144149
const numCPUs = os.cpus().length;
145-
await prepareEnvironment(envs, types);
150+
await prepareEnvironment(ENVS, TYPES, TARGET_EXCLUDES);
146151
await runLimited(taskConfigs, Math.max(numCPUs - 1, 1));
147152
await clearTmpDir();
148153
echo(`Tested: ${ chalk.green(tested) }, Failed: ${ chalk.red(failed) }`);

0 commit comments

Comments
 (0)