Skip to content

Commit 460bab2

Browse files
authored
Fix failing tests due to newer @tsconfig/bases (#2011)
* extract tsconfig/bases tests to their own file * fix failing tests due to new @tsconfig/bases * fix
1 parent 0bf1366 commit 460bab2

File tree

3 files changed

+118
-83
lines changed

3 files changed

+118
-83
lines changed

src/test/helpers/version-checks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ export const tsSupportsVerbatimModuleSyntax = semver.gte(ts.version, '5.0.0');
4646
// old TS versions.
4747
export const tsSupportsEs2021 = semver.gte(ts.version, '4.3.0');
4848
export const tsSupportsEs2022 = semver.gte(ts.version, '4.6.0');
49+
export const tsSupportsLibEs2023 = semver.gte(ts.version, '5.0.0');

src/test/index.spec.ts

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import { context, ExecutionContext } from './testlib';
22
import * as expect from 'expect';
33
import { join, resolve, sep as pathSep } from 'path';
4-
import semver = require('semver');
5-
import { project as fsProject } from '@TypeStrong/fs-fixture-builder';
64
import {
75
BIN_PATH_JS,
86
CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG,
9-
ctxTmpDirOutsideCheckout,
107
ts,
11-
tsSupportsEs2021,
12-
tsSupportsEs2022,
138
tsSupportsMtsCtsExtensions,
149
tsSupportsStableNodeNextNode16,
1510
} from './helpers';
@@ -571,84 +566,6 @@ test.suite('ts-node', (test) => {
571566
expect(r.stderr).toBe('');
572567
});
573568

574-
test.suite(
575-
'should use implicit @tsconfig/bases config when one is not loaded from disk',
576-
({ contextEach }) => {
577-
const test = contextEach(ctxTmpDirOutsideCheckout);
578-
const libAndTarget =
579-
semver.gte(process.versions.node, '18.0.0') && tsSupportsEs2022
580-
? 'es2022'
581-
: semver.gte(process.versions.node, '16.0.0') && tsSupportsEs2021
582-
? 'es2021'
583-
: 'es2020';
584-
test('implicitly uses @tsconfig/node14, @tsconfig/node16, or @tsconfig/node18 compilerOptions when both TS and node versions support it', async (t) => {
585-
const r1 = await exec(`${BIN_PATH} --showConfig`, {
586-
cwd: t.context.tmpDir,
587-
});
588-
expect(r1.err).toBe(null);
589-
t.like(JSON.parse(r1.stdout), {
590-
compilerOptions: {
591-
target: libAndTarget,
592-
lib: [libAndTarget],
593-
},
594-
});
595-
const r2 = await exec(`${BIN_PATH} -pe 10n`, {
596-
cwd: t.context.tmpDir,
597-
});
598-
expect(r2.err).toBe(null);
599-
expect(r2.stdout).toBe('10n\n');
600-
});
601-
test('implicitly loads @types/node even when not installed within local directory', async (t) => {
602-
const r = await exec(`${BIN_PATH} -pe process.env.foo`, {
603-
cwd: t.context.tmpDir,
604-
env: { ...process.env, foo: 'hello world' },
605-
});
606-
expect(r.err).toBe(null);
607-
expect(r.stdout).toBe('hello world\n');
608-
});
609-
test('implicitly loads local @types/node', async (t) => {
610-
t.context.fixture.readFrom(
611-
join(TEST_DIR, 'local-types-node'),
612-
undefined,
613-
[]
614-
);
615-
t.context.fixture.write();
616-
const r = await exec(`${BIN_PATH} -pe process.env.foo`, {
617-
cwd: t.context.fixture.cwd,
618-
env: { ...process.env, foo: 'hello world' },
619-
});
620-
expect(r.err).not.toBe(null);
621-
expect(r.stderr).toMatch(
622-
"Property 'env' does not exist on type 'LocalNodeTypes_Process'"
623-
);
624-
});
625-
}
626-
);
627-
628-
test.suite(
629-
'should bundle @tsconfig/bases to be used in your own tsconfigs',
630-
(test) => {
631-
// Older TS versions will complain about newer `target` and `lib` options
632-
test.if(tsSupportsEs2022);
633-
const macro = test.macro((nodeVersion: string) => async (t) => {
634-
const config = require(`@tsconfig/${nodeVersion}/tsconfig.json`);
635-
const r = await exec(`${BIN_PATH} --showConfig -e 10n`, {
636-
cwd: join(TEST_DIR, 'tsconfig-bases', nodeVersion),
637-
});
638-
expect(r.err).toBe(null);
639-
t.like(JSON.parse(r.stdout), {
640-
compilerOptions: {
641-
target: config.compilerOptions.target,
642-
lib: config.compilerOptions.lib,
643-
},
644-
});
645-
});
646-
test(`ts-node/node14/tsconfig.json`, macro, 'node14');
647-
test(`ts-node/node16/tsconfig.json`, macro, 'node16');
648-
test(`ts-node/node18/tsconfig.json`, macro, 'node18');
649-
}
650-
);
651-
652569
test.suite('compiler host', (test) => {
653570
test('should execute cli', async () => {
654571
const r = await exec(

src/test/tsconfig-bases.spec.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { join } from 'path';
2+
import { createExec } from './exec-helpers';
3+
import { ctxTmpDirOutsideCheckout } from './helpers/ctx-tmp-dir';
4+
import { ctxTsNode } from './helpers/ctx-ts-node';
5+
import { BIN_PATH, TEST_DIR } from './helpers/paths';
6+
import {
7+
tsSupportsEs2021,
8+
tsSupportsEs2022,
9+
tsSupportsLibEs2023,
10+
} from './helpers/version-checks';
11+
import { context, expect } from './testlib';
12+
import semver = require('semver');
13+
import { testsDirRequire } from './helpers';
14+
15+
const exec = createExec({
16+
cwd: TEST_DIR,
17+
});
18+
19+
const test = context(ctxTsNode);
20+
21+
test.suite(
22+
'should use implicit @tsconfig/bases config when one is not loaded from disk',
23+
({ contextEach }) => {
24+
const test = contextEach(ctxTmpDirOutsideCheckout);
25+
26+
let lib = 'es2020';
27+
let target = 'es2020';
28+
if (semver.gte(process.versions.node, '16.0.0') && tsSupportsEs2021) {
29+
lib = target = 'es2021';
30+
}
31+
if (
32+
semver.gte(process.versions.node, '18.0.0') &&
33+
tsSupportsEs2022 &&
34+
tsSupportsLibEs2023
35+
) {
36+
target = 'es2022';
37+
lib = 'es2023';
38+
}
39+
40+
test('implicitly uses @tsconfig/node14, @tsconfig/node16, or @tsconfig/node18 compilerOptions when both TS and node versions support it', async (t) => {
41+
const r1 = await exec(`${BIN_PATH} --showConfig`, {
42+
cwd: t.context.tmpDir,
43+
});
44+
45+
expect(r1.err).toBe(null);
46+
t.like(JSON.parse(r1.stdout), {
47+
compilerOptions: {
48+
target,
49+
lib: [lib],
50+
},
51+
});
52+
53+
const r2 = await exec(`${BIN_PATH} -pe 10n`, {
54+
cwd: t.context.tmpDir,
55+
});
56+
57+
expect(r2.err).toBe(null);
58+
expect(r2.stdout).toBe('10n\n');
59+
});
60+
61+
test('implicitly loads @types/node even when not installed within local directory', async (t) => {
62+
const r = await exec(`${BIN_PATH} -pe process.env.foo`, {
63+
cwd: t.context.tmpDir,
64+
env: { ...process.env, foo: 'hello world' },
65+
});
66+
67+
expect(r.err).toBe(null);
68+
expect(r.stdout).toBe('hello world\n');
69+
});
70+
71+
test('implicitly loads local @types/node', async (t) => {
72+
t.context.fixture.readFrom(
73+
join(TEST_DIR, 'local-types-node'),
74+
undefined,
75+
[]
76+
);
77+
t.context.fixture.write();
78+
79+
const r = await exec(`${BIN_PATH} -pe process.env.foo`, {
80+
cwd: t.context.fixture.cwd,
81+
env: { ...process.env, foo: 'hello world' },
82+
});
83+
84+
expect(r.err).not.toBe(null);
85+
expect(r.stderr).toMatch(
86+
"Property 'env' does not exist on type 'LocalNodeTypes_Process'"
87+
);
88+
});
89+
}
90+
);
91+
92+
test.suite(
93+
'should bundle @tsconfig/bases to be used in your own tsconfigs',
94+
(test) => {
95+
// Older TS versions will complain about newer `target` and `lib` options
96+
test.if(tsSupportsEs2022 && tsSupportsLibEs2023);
97+
98+
const macro = test.macro((nodeVersion: string) => async (t) => {
99+
const config = testsDirRequire(`@tsconfig/${nodeVersion}/tsconfig.json`);
100+
const r = await exec(`${BIN_PATH} --showConfig -e 10n`, {
101+
cwd: join(TEST_DIR, 'tsconfig-bases', nodeVersion),
102+
});
103+
104+
expect(r.err).toBe(null);
105+
t.like(JSON.parse(r.stdout), {
106+
compilerOptions: {
107+
target: config.compilerOptions.target,
108+
lib: config.compilerOptions.lib,
109+
},
110+
});
111+
});
112+
113+
test(`ts-node/node14/tsconfig.json`, macro, 'node14');
114+
test(`ts-node/node16/tsconfig.json`, macro, 'node16');
115+
test(`ts-node/node18/tsconfig.json`, macro, 'node18');
116+
}
117+
);

0 commit comments

Comments
 (0)