Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/many-avocados-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@typescript/vfs": patch
---

Use System's getDirectories if it's provided when constructing Host
13 changes: 9 additions & 4 deletions packages/ts-twoslasher/test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ expect.extend({ toMatchFile })
// To add a test, create a file in the fixtures folder and it will will run through
// as though it was the codeblock.

const defaultCompilerOptions = {
// avoid extra annotations from @types/node
types: []
}

describe("with fixtures", () => {
// Add all codefixes
const fixturesFolder = join(__dirname, "fixtures")
Expand All @@ -27,7 +32,7 @@ describe("with fixtures", () => {

const file = readFileSync(fixture, "utf8")

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

const file = readFileSync(fixture, "utf8")

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

const file = readFileSync(fixture, "utf8")

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

let thrown = false
try {
twoslasher(file, extname(fixtureName).substr(1))
twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions })
} catch (err) {
thrown = true
if (err instanceof Error) expect(err.message).toMatchFile(result)
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-vfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ export function createVirtualCompilerHost(sys: System, compilerOptions: Compiler
getCanonicalFileName: fileName => fileName,
getDefaultLibFileName: () => "/" + ts.getDefaultLibFileName(compilerOptions), // '/lib.d.ts',
// getDefaultLibLocation: () => '/',
getDirectories: () => [],
Comment thread
jakebailey marked this conversation as resolved.
getNewLine: () => sys.newLine,
getSourceFile: (fileName, languageVersionOrOptions) => {
return (
Expand Down
14 changes: 14 additions & 0 deletions packages/typescript-vfs/test/fsbacked.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ it("can import files in the virtual fs", () => {

expect(errs.map(e => e.messageText)).toEqual([])
})

it("searches node_modules/@types", () => {
const compilerOpts: ts.CompilerOptions = { target: ts.ScriptTarget.ES2016, esModuleInterop: true }
const monorepoRoot = __dirname

const fsMap = new Map<string, string>()
fsMap.set("index.ts", "it('found @types/jest', () => undefined)")

const system = createFSBackedSystem(fsMap, monorepoRoot, ts)
const env = createVirtualTypeScriptEnvironment(system, ["index.ts"], ts, compilerOpts)

const semDiags = env.languageService.getSemanticDiagnostics("index.ts")
expect(semDiags.length).toBe(0)
})