forked from orval-labs/orval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsconfig.test.ts
More file actions
67 lines (58 loc) 路 2.18 KB
/
Copy pathtsconfig.test.ts
File metadata and controls
67 lines (58 loc) 路 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { describe, expect, it } from 'vitest';
import type { Tsconfig } from '../types';
import { getImportExtension } from './tsconfig';
describe('getImportExtension', () => {
it('strips a .ts file extension when no tsconfig is provided', () => {
expect(getImportExtension('.ts')).toBe('');
expect(getImportExtension('.gen.ts')).toBe('.gen');
});
it('preserves non-.ts file extensions when no tsconfig is provided', () => {
expect(getImportExtension('.mjs')).toBe('.mjs');
});
it('keeps the file extension as-is when allowImportingTsExtensions is true', () => {
const tsconfig: Tsconfig = {
compilerOptions: { allowImportingTsExtensions: true },
};
expect(getImportExtension('.gen.ts', tsconfig)).toBe('.gen.ts');
expect(getImportExtension('.ts', tsconfig)).toBe('.ts');
});
it('rewrites .ts to .js when module is NodeNext', () => {
const tsconfig: Tsconfig = {
compilerOptions: { module: 'NodeNext' },
};
expect(getImportExtension('.ts', tsconfig)).toBe('.js');
expect(getImportExtension('.gen.ts', tsconfig)).toBe('.gen.js');
});
it('rewrites .ts to .js when moduleResolution is Node16', () => {
const tsconfig: Tsconfig = {
compilerOptions: { moduleResolution: 'Node16' },
};
expect(getImportExtension('.ts', tsconfig)).toBe('.js');
});
it('matches NodeNext/Node16 case-insensitively', () => {
expect(
getImportExtension('.ts', { compilerOptions: { module: 'nodenext' } }),
).toBe('.js');
expect(
getImportExtension('.ts', {
compilerOptions: { moduleResolution: 'node16' },
}),
).toBe('.js');
});
it('prefers allowImportingTsExtensions over NodeNext rewrites', () => {
const tsconfig: Tsconfig = {
compilerOptions: {
module: 'NodeNext',
allowImportingTsExtensions: true,
},
};
expect(getImportExtension('.gen.ts', tsconfig)).toBe('.gen.ts');
});
it('falls back to stripping .ts for other module settings', () => {
const tsconfig: Tsconfig = {
compilerOptions: { module: 'ESNext' },
};
expect(getImportExtension('.ts', tsconfig)).toBe('');
expect(getImportExtension('.gen.ts', tsconfig)).toBe('.gen');
});
});