Skip to content

Commit 0417fd3

Browse files
committed
Add tests for relative imports (raw, file)
1 parent 67276d2 commit 0417fd3

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Expect an error on the import path
2+
// @ts-expect-error
3+
import type { NoOp } from './resource/custom-lib';
4+
5+
type NoOpBoolean = NoOp<boolean>;
6+
7+
export { NoOpBoolean };

tests/imports/definitions/lib.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { NoOp } from '../resource/custom-lib';
2+
3+
type NoOpString = NoOp<string>;
4+
5+
export { NoOpString };

tests/imports/relative-import.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'path';
2+
import { type AssertTypeSelector, fromFile, fromRaw } from '@tsz/index';
3+
4+
const raw = `
5+
import type { NoOp } from './resource/custom-lib';
6+
7+
type NoOpNumber = NoOp<number>;
8+
9+
export { NoOpNumber };
10+
`;
11+
12+
describe('Relative Import', () => {
13+
let type!: AssertTypeSelector;
14+
15+
describe('Raw', () => {
16+
test('Successfully resolve the relative import from raw code', () => {
17+
type = fromRaw(raw, { baseUrl: __dirname });
18+
19+
type('NoOpNumber').not.equals('NoOp<number>');
20+
type('NoOpNumber').isNumber();
21+
});
22+
});
23+
24+
describe('File', () => {
25+
test('Successfully resolve the relative import from a file', () => {
26+
type = fromFile(path.join(__dirname, 'definitions', 'lib.ts'));
27+
28+
type('NoOpString').not.equals('NoOp<string>');
29+
type('NoOpString').isString();
30+
});
31+
32+
test('Custom base URL', () => {
33+
type = fromFile(path.join(__dirname, 'definitions', 'lib-custom-base.ts'), {
34+
baseUrl: __dirname,
35+
});
36+
37+
type('NoOpBoolean').not.equals('NoOp<boolean>');
38+
type('NoOpBoolean').isBoolean();
39+
});
40+
});
41+
});
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type NoOp<T> = T;
2+
3+
export { NoOp };

0 commit comments

Comments
 (0)