Skip to content

Commit

Permalink
Match @types/node to TS version for each run of npm test:types (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdaily-stripe authored Oct 1, 2024
1 parent 165ac00 commit a3dfb93
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions tests/types/scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs';
import 'zx/globals';

const VERSIONS = [
'next',
'beta',
'latest',
'5.2',
Expand All @@ -19,19 +20,6 @@ const VERSIONS = [
'4.2.4',
'4.1.6',
'4.0.6',
'3.9.10',
'3.8.3',
'3.7.4',
'3.6.3',
'3.5.1',
'3.4.4',
'3.3.3',
'3.2.1',

// Attempting to test on 3.1.1 currently fails. I believe it is not a
// fundamental incompatibility with the types, just some tsconfig.json changes
// that are needed. Skipping for now
// '3.1.1',
];

const TYPE_TESTS_DIR = `${__dirname}/..`;
Expand All @@ -48,13 +36,15 @@ await $`yarn init -sy`;
for (const version of VERSIONS) {
console.log(`--- Testing with TypeScript version ${version}`);
await $`yarn add -s --no-progress typescript@${version}`;
await $`yarn run tsc --strict --noEmit src/valid.ts`;

// TypeScript versions >= 3.9.0 support [@ts-expect-error][0], which lets us
// write tests for types that we expect to cause errors
//
// [0]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments
if (version >= '3.9.0') {
await $`yarn run tsc --strict --noEmit src/invalid.ts`;
}
// Definitely Typed only supports TS versions 2 years in the past.
// To make this check more stable, install @types/node to match
// the version we are testing.
const tag = ['next', 'beta', 'latest'].includes(version)
? 'latest'
: `ts${version.substring(0, 3)}`;
await $`yarn add -s --no-progress @types/node@${tag}`;

await $`yarn run tsc --strict --noEmit src/valid.ts`;
await $`yarn run tsc --strict --noEmit src/invalid.ts`;
}

0 comments on commit a3dfb93

Please sign in to comment.