Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Armando Aguirre Sepulveda committed Jul 10, 2024
1 parent 39f459d commit da2c2e5
Show file tree
Hide file tree
Showing 3 changed files with 987 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/testRunner/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export * from "./unittests/tsserver/partialSemanticServer.js";
export * from "./unittests/tsserver/pasteEdits.js";
export * from "./unittests/tsserver/plugins.js";
export * from "./unittests/tsserver/pluginsAsync.js";
export * from "./unittests/tsserver/projectImportHelpers.js";
export * from "./unittests/tsserver/projectErrors.js";
export * from "./unittests/tsserver/projectReferenceCompileOnSave.js";
export * from "./unittests/tsserver/projectReferenceErrors.js";
Expand Down
76 changes: 76 additions & 0 deletions src/testRunner/unittests/tsserver/projectImportHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as ts from "../../_namespaces/ts.js";
import { jsonToReadableText } from "../helpers.js";
import {
baselineTsserverLogs,
openFilesForSession,
TestSession,
} from "../helpers/tsserver.js";
import {
createServerHost,
} from "../helpers/virtualFileSystemWithWatch.js";

describe("unittests:: tsserver:: projectImportHelpers::", () => {
it("import helpers sucessfully", () => {
const type1 = {
path: "/a/type.ts",
content: `
export type Foo {
bar: number;
};
`
}
const file1 = {
path: "/a/file1.ts",
content: `
import { Foo } from "./type";
const a: Foo = { bar : 1 };
a.bar;
`,
};
const file2 = {
path: "/a/file2.ts",
content: `
import { Foo } from "./type";
const a: Foo = { bar : 2 };
a.bar;
`,
};

const config1 = {
path: "/a/tsconfig.json",
content: jsonToReadableText({
extends: "../tsconfig.json",
compilerOptions: {
importHelpers: true,
},
}),
}

const file3 = {
path: "/file3.js",
content: "console.log('noop');",
};
const config2 = {
path: "/tsconfig.json",
content: jsonToReadableText({
include: ["**/*"],
}),
};

const host = createServerHost([config2, config1, type1, file1, file2, file3]);
const session = new TestSession(host);

openFilesForSession([file3, file1], session);

session.executeCommandSeq<ts.server.protocol.ReferencesRequest>({
command: ts.server.protocol.CommandTypes.References,
arguments: {
file: file1.path,
line: 4,
offset: 3
},
});

baselineTsserverLogs("importHelpers", "import helpers successfully", session);
});
});
Loading

0 comments on commit da2c2e5

Please sign in to comment.