Skip to content

Commit

Permalink
skip NodeNext tests on incompatible node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed May 26, 2022
1 parent 0f1a985 commit 8c18db4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/test/helpers.ts
Expand Up @@ -68,6 +68,14 @@ export const nodeSupportsImportAssertions = semver.gte(
process.version,
'17.1.0'
);
// Node 14.13.0 has a bug where it tries to lex CJS files to discover named exports *before*
// we transform the code.
// In other words, it tries to parse raw TS as CJS and balks at `export const foo =`, expecting to see `exports.foo =`
// This lexing only happens when CJS TS is imported from the ESM loader.
export const nodeSupportsImportingTransformedCjsFromEsm = semver.gte(
process.version,
'14.13.1'
);
/** Supports tsconfig "extends" >= v3.2.0 */
export const tsSupportsTsconfigInheritanceViaNodePackages = semver.gte(
ts.version,
Expand Down
8 changes: 7 additions & 1 deletion src/test/module-node.spec.ts
Expand Up @@ -2,6 +2,7 @@ import { expect, context } from './testlib';
import {
CMD_TS_NODE_WITHOUT_PROJECT_FLAG,
isOneOf,
nodeSupportsImportingTransformedCjsFromEsm,
resetNodeEnvironment,
tsSupportsStableNodeNextNode16,
} from './helpers';
Expand All @@ -18,7 +19,9 @@ type Test = typeof test;

// Declare one test case for each permutations of project configuration
test.suite('TypeScript module=NodeNext and Node16', (test) => {
test.runIf(tsSupportsStableNodeNextNode16);
test.runIf(
tsSupportsStableNodeNextNode16 && nodeSupportsImportingTransformedCjsFromEsm
);

for (const allowJs of [true, false]) {
for (const typecheckMode of [
Expand Down Expand Up @@ -63,6 +66,7 @@ function declareTest(test: Test, testParams: TestParams) {
t.log(stdout);
t.log(stderr);
expect(err).toBe(null);
expect(stdout).toMatch(/done\n$/);
});
}

Expand Down Expand Up @@ -216,6 +220,8 @@ function writeFixturesToFilesystem(name: string, testParams: TestParams) {
}
}

indexFile.content += `console.log('done');\n`;

proj.rm();
proj.write();
return proj;
Expand Down

0 comments on commit 8c18db4

Please sign in to comment.