Skip to content

Commit 8c18db4

Browse files
committed
skip NodeNext tests on incompatible node versions
1 parent 0f1a985 commit 8c18db4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/test/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export const nodeSupportsImportAssertions = semver.gte(
6868
process.version,
6969
'17.1.0'
7070
);
71+
// Node 14.13.0 has a bug where it tries to lex CJS files to discover named exports *before*
72+
// we transform the code.
73+
// In other words, it tries to parse raw TS as CJS and balks at `export const foo =`, expecting to see `exports.foo =`
74+
// This lexing only happens when CJS TS is imported from the ESM loader.
75+
export const nodeSupportsImportingTransformedCjsFromEsm = semver.gte(
76+
process.version,
77+
'14.13.1'
78+
);
7179
/** Supports tsconfig "extends" >= v3.2.0 */
7280
export const tsSupportsTsconfigInheritanceViaNodePackages = semver.gte(
7381
ts.version,

src/test/module-node.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect, context } from './testlib';
22
import {
33
CMD_TS_NODE_WITHOUT_PROJECT_FLAG,
44
isOneOf,
5+
nodeSupportsImportingTransformedCjsFromEsm,
56
resetNodeEnvironment,
67
tsSupportsStableNodeNextNode16,
78
} from './helpers';
@@ -18,7 +19,9 @@ type Test = typeof test;
1819

1920
// Declare one test case for each permutations of project configuration
2021
test.suite('TypeScript module=NodeNext and Node16', (test) => {
21-
test.runIf(tsSupportsStableNodeNextNode16);
22+
test.runIf(
23+
tsSupportsStableNodeNextNode16 && nodeSupportsImportingTransformedCjsFromEsm
24+
);
2225

2326
for (const allowJs of [true, false]) {
2427
for (const typecheckMode of [
@@ -63,6 +66,7 @@ function declareTest(test: Test, testParams: TestParams) {
6366
t.log(stdout);
6467
t.log(stderr);
6568
expect(err).toBe(null);
69+
expect(stdout).toMatch(/done\n$/);
6670
});
6771
}
6872

@@ -216,6 +220,8 @@ function writeFixturesToFilesystem(name: string, testParams: TestParams) {
216220
}
217221
}
218222

223+
indexFile.content += `console.log('done');\n`;
224+
219225
proj.rm();
220226
proj.write();
221227
return proj;

0 commit comments

Comments
 (0)