|
| 1 | +import * as ts from "../../_namespaces/ts.js"; |
| 2 | +import { jsonToReadableText } from "../helpers.js"; |
| 3 | +import { |
| 4 | + baselineTsserverLogs, |
| 5 | + openFilesForSession, |
| 6 | + TestSession, |
| 7 | +} from "../helpers/tsserver.js"; |
| 8 | +import { createServerHost } from "../helpers/virtualFileSystemWithWatch.js"; |
| 9 | + |
| 10 | +describe("unittests:: tsserver:: projectImportHelpers::", () => { |
| 11 | + it("import helpers sucessfully", () => { |
| 12 | + const type1 = { |
| 13 | + path: "/a/type.ts", |
| 14 | + content: ` |
| 15 | +export type Foo { |
| 16 | + bar: number; |
| 17 | +};`, |
| 18 | + }; |
| 19 | + const file1 = { |
| 20 | + path: "/a/file1.ts", |
| 21 | + content: ` |
| 22 | +import { Foo } from "./type"; |
| 23 | +const a: Foo = { bar : 1 }; |
| 24 | +a.bar;`, |
| 25 | + }; |
| 26 | + const file2 = { |
| 27 | + path: "/a/file2.ts", |
| 28 | + content: ` |
| 29 | +import { Foo } from "./type"; |
| 30 | +const a: Foo = { bar : 2 }; |
| 31 | +a.bar;`, |
| 32 | + }; |
| 33 | + |
| 34 | + const config1 = { |
| 35 | + path: "/a/tsconfig.json", |
| 36 | + content: jsonToReadableText({ |
| 37 | + extends: "../tsconfig.json", |
| 38 | + compilerOptions: { |
| 39 | + importHelpers: true, |
| 40 | + }, |
| 41 | + }), |
| 42 | + }; |
| 43 | + |
| 44 | + const file3 = { |
| 45 | + path: "/file3.js", |
| 46 | + content: "console.log('noop');", |
| 47 | + }; |
| 48 | + const config2 = { |
| 49 | + path: "/tsconfig.json", |
| 50 | + content: jsonToReadableText({ |
| 51 | + include: ["**/*"], |
| 52 | + }), |
| 53 | + }; |
| 54 | + |
| 55 | + const host = createServerHost([config2, config1, type1, file1, file2, file3]); |
| 56 | + const session = new TestSession(host); |
| 57 | + |
| 58 | + openFilesForSession([file3, file1], session); |
| 59 | + |
| 60 | + session.executeCommandSeq<ts.server.protocol.ReferencesRequest>({ |
| 61 | + command: ts.server.protocol.CommandTypes.References, |
| 62 | + arguments: { |
| 63 | + file: file1.path, |
| 64 | + line: 4, |
| 65 | + offset: 3, |
| 66 | + }, |
| 67 | + }); |
| 68 | + |
| 69 | + baselineTsserverLogs("importHelpers", "import helpers successfully", session); |
| 70 | + }); |
| 71 | +}); |
0 commit comments