Skip to content

Commit e3a1f8c

Browse files
test: fix tests failing to import other virtual files
1 parent 4ee7938 commit e3a1f8c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

tests/etc/could-be-type.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ describe('couldBeType', () => {
106106
expect(couldBeType(type, 'B')).toBe(true);
107107
});
108108

109-
it.todo('should support fully-qualified types', () => {
110-
// TODO: This test is disabled because we're failing to import from other files using @typescript/vfs. See env.languageService.getSemanticDiagnostics(fileName) for error message.
109+
it('should support fully-qualified types', () => {
111110
const { sourceFile, typeChecker } = createSourceFileAndTypeChecker(
112111
`
113-
import { A } from "./a";
112+
import { A } from "/a";
114113
class B {}
115114
let a: A;
116115
let b: B;
@@ -123,13 +122,13 @@ describe('couldBeType', () => {
123122

124123
expect(
125124
couldBeType(typeA, 'A', {
126-
name: /"a"/,
125+
name: /"\/a"/,
127126
typeChecker,
128127
}),
129128
).toBe(true);
130129
expect(
131130
couldBeType(typeB, 'B', {
132-
name: /"b"/,
131+
name: /b/,
133132
typeChecker,
134133
}),
135134
).toBe(false);

tests/etc/create-source-file-and-type-checker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export function createSourceFileAndTypeChecker(
1818

1919
const fsMap = tsvfs.createDefaultMapFromNodeModules(compilerOptions, ts);
2020
fsMap.set(fileName, sourceText);
21-
fsMap.set('a.ts', 'export class A {}');
22-
fsMap.set('b.ts', 'export class B {}');
21+
fsMap.set('/a.ts', 'export class A {}');
22+
fsMap.set('/b.ts', 'export class B {}');
2323

2424
const system = tsvfs.createSystem(fsMap);
2525
const env = tsvfs.createVirtualTypeScriptEnvironment(
2626
system,
27-
[fileName, 'a.ts', 'b.ts'],
27+
[fileName, '/a.ts', '/b.ts'],
2828
ts,
2929
compilerOptions,
3030
);
@@ -33,6 +33,11 @@ export function createSourceFileAndTypeChecker(
3333
if (program === undefined) {
3434
throw new Error('Failed to get program');
3535
}
36+
// Note: If you're having trouble with vfs, run the tests with DEBUG=1 for more output.
37+
const fileIssues = env.languageService.getSemanticDiagnostics(fileName);
38+
if (fileIssues.length) {
39+
throw new Error(fileIssues.map(diag => diag.messageText).join());
40+
}
3641

3742
return {
3843
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

0 commit comments

Comments
 (0)