1namespace ts.projectSystem { 2 describe("unittests:: tsserver:: duplicate packages", () => { 3 // Tests that 'moduleSpecifiers.ts' will import from the redirecting file, and not from the file it redirects to, if that can provide a global module specifier. 4 it("works with import fixes", () => { 5 const packageContent = "export const foo: number;"; 6 const packageJsonContent = JSON.stringify({ name: "foo", version: "1.2.3" }); 7 const aFooIndex: File = { path: "/a/node_modules/foo/index.d.ts", content: packageContent }; 8 const aFooPackage: File = { path: "/a/node_modules/foo/package.json", content: packageJsonContent }; 9 const bFooIndex: File = { path: "/b/node_modules/foo/index.d.ts", content: packageContent }; 10 const bFooPackage: File = { path: "/b/node_modules/foo/package.json", content: packageJsonContent }; 11 12 const userContent = 'import("foo");\nfoo'; 13 const aUser: File = { path: "/a/user.ts", content: userContent }; 14 const bUser: File = { path: "/b/user.ts", content: userContent }; 15 const tsconfig: File = { 16 path: "/tsconfig.json", 17 content: "{}", 18 }; 19 20 const host = createServerHost([aFooIndex, aFooPackage, bFooIndex, bFooPackage, aUser, bUser, tsconfig]); 21 const session = createSession(host); 22 23 openFilesForSession([aUser, bUser], session); 24 25 for (const user of [aUser, bUser]) { 26 const response = executeSessionRequest<protocol.CodeFixRequest, protocol.CodeFixResponse>(session, protocol.CommandTypes.GetCodeFixes, { 27 file: user.path, 28 startLine: 2, 29 startOffset: 1, 30 endLine: 2, 31 endOffset: 4, 32 errorCodes: [Diagnostics.Cannot_find_name_0.code], 33 }); 34 assert.deepEqual<readonly protocol.CodeFixAction[] | undefined>(response, [ 35 { 36 description: `Import 'foo' from module "foo"`, 37 fixName: "import", 38 changes: [{ 39 fileName: user.path, 40 textChanges: [{ 41 start: { line: 1, offset: 1 }, 42 end: { line: 1, offset: 1 }, 43 newText: 'import { foo } from "foo";\n\n', 44 }], 45 }], 46 commands: undefined, 47 fixId: undefined, 48 fixAllDescription: undefined 49 }, 50 ]); 51 } 52 }); 53 }); 54} 55