Skip to content

Commit 441338c

Browse files
authored
Host uses getDirectories from System (#3165)
1 parent b5d65fb commit 441338c

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

.changeset/many-avocados-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@typescript/vfs": patch
3+
---
4+
5+
Use System's getDirectories if it's provided when constructing Host

packages/ts-twoslasher/test/fixtures.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ expect.extend({ toMatchFile })
99
// To add a test, create a file in the fixtures folder and it will will run through
1010
// as though it was the codeblock.
1111

12+
const defaultCompilerOptions = {
13+
// avoid extra annotations from @types/node
14+
types: []
15+
}
16+
1217
describe("with fixtures", () => {
1318
// Add all codefixes
1419
const fixturesFolder = join(__dirname, "fixtures")
@@ -27,7 +32,7 @@ describe("with fixtures", () => {
2732

2833
const file = readFileSync(fixture, "utf8")
2934

30-
const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { customTags: ["annotate"] })
35+
const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { customTags: ["annotate"], defaultCompilerOptions })
3136
const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" })
3237
expect(jsonString).toMatchFile(result)
3338
})
@@ -46,7 +51,7 @@ describe("with fixtures", () => {
4651

4752
const file = readFileSync(fixture, "utf8")
4853

49-
const fourslashed = twoslasher(file, extname(fixtureName).substr(1))
54+
const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions })
5055
const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" })
5156
expect(jsonString).toMatchFile(result)
5257
})
@@ -65,7 +70,7 @@ describe("with fixtures", () => {
6570

6671
const file = readFileSync(fixture, "utf8")
6772

68-
const fourslashed = twoslasher(file, extname(fixtureName).substr(1))
73+
const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions })
6974
const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" })
7075
expect(jsonString).toMatchFile(result)
7176
})
@@ -87,7 +92,7 @@ describe("with fixtures", () => {
8792

8893
let thrown = false
8994
try {
90-
twoslasher(file, extname(fixtureName).substr(1))
95+
twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions })
9196
} catch (err) {
9297
thrown = true
9398
if (err instanceof Error) expect(err.message).toMatchFile(result)

packages/typescript-vfs/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ export function createVirtualCompilerHost(sys: System, compilerOptions: Compiler
572572
getCanonicalFileName: fileName => fileName,
573573
getDefaultLibFileName: () => "/" + ts.getDefaultLibFileName(compilerOptions), // '/lib.d.ts',
574574
// getDefaultLibLocation: () => '/',
575-
getDirectories: () => [],
576575
getNewLine: () => sys.newLine,
577576
getSourceFile: (fileName, languageVersionOrOptions) => {
578577
return (

packages/typescript-vfs/test/fsbacked.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@ it("can import files in the virtual fs", () => {
5858

5959
expect(errs.map(e => e.messageText)).toEqual([])
6060
})
61+
62+
it("searches node_modules/@types", () => {
63+
const compilerOpts: ts.CompilerOptions = { target: ts.ScriptTarget.ES2016, esModuleInterop: true }
64+
const monorepoRoot = __dirname
65+
66+
const fsMap = new Map<string, string>()
67+
fsMap.set("index.ts", "it('found @types/jest', () => undefined)")
68+
69+
const system = createFSBackedSystem(fsMap, monorepoRoot, ts)
70+
const env = createVirtualTypeScriptEnvironment(system, ["index.ts"], ts, compilerOpts)
71+
72+
const semDiags = env.languageService.getSemanticDiagnostics("index.ts")
73+
expect(semDiags.length).toBe(0)
74+
})

0 commit comments

Comments
 (0)