Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #1510: add test to catch when TS adds new ModuleKinds #1650

Merged
merged 4 commits into from
Feb 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
cspotcode committed Feb 19, 2022
commit f4069c10f29ba094bba8fea58f2f75602f7dfe22
28 changes: 14 additions & 14 deletions src/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1271,31 +1271,31 @@ test('Falls back to transpileOnly when ts compiler returns emitSkipped', async (
test('Detect when typescript adds new ModuleKind values; flag as a failure so we can update our code flagged [MUST_UPDATE_FOR_NEW_MODULEKIND]', async () => {
// We have marked a few places in our code with MUST_UPDATE_FOR_NEW_MODULEKIND to make it easier to update them when TS adds new ModuleKinds
const foundKeys: string[] = [];
function check(value: string, name: string, required: boolean) {
function check(value: number, name: string, required: boolean) {
if (required) expect(ts.ModuleKind[name]).toBe(value);
if (ts.ModuleKind[value] === undefined) {
expect(ts.ModuleKind[name]).toBeUndefined();
} else {
expect(ts.ModuleKind[value]).toBe(name);
foundKeys.push(name, value);
foundKeys.push(name, `${ value }`);
}
}
check('0', 'None', true);
check('1', 'CommonJS', true);
check('2', 'AMD', true);
check('3', 'UMD', true);
check('4', 'System', true);
check('5', 'ES2015', true);
check('6', 'ES2020', false);
check('7', 'ES2022', false);
check(0, 'None', true);
check(1, 'CommonJS', true);
check(2, 'AMD', true);
check(3, 'UMD', true);
check(4, 'System', true);
check(5, 'ES2015', true);
check(6, 'ES2020', false);
check(7, 'ES2022', false);
try {
check('99', 'ESNext', true);
check(99, 'ESNext', true);
} catch {
// the value changed: is `99` now, but was `6` in TS 2.7
check('6', 'ESNext', true);
check(6, 'ESNext', true);
}
check('100', 'Node12', false);
check('199', 'NodeNext', false);
check(100, 'Node12', false);
check(199, 'NodeNext', false);
const actualKeys = Object.keys(ts.ModuleKind);
actualKeys.sort();
foundKeys.sort();