Skip to content

Commit 6ed8aae

Browse files
committed
Test when node typings dont get added on subsequent update graph because of invalid typing
Test for microsoft#29865
1 parent 8705844 commit 6ed8aae

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/testRunner/unittests/tsserver/typingsInstaller.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,68 @@ namespace ts.projectSystem {
17731773
import * as c from "foo/a/c";
17741774
`, ["foo"], [fooAA, fooAB, fooAC]);
17751775
});
1776+
1777+
it("should handle node core modules", () => {
1778+
const file: TestFSWithWatch.File = {
1779+
path: "/a/b/app.js",
1780+
content: `// @ts-check
1781+
1782+
const net = require("net");
1783+
const stream = require("stream");`
1784+
};
1785+
const nodeTyping: TestFSWithWatch.File = {
1786+
path: `${globalTypingsCacheLocation}/node_modules/node/index.d.ts`,
1787+
content: `
1788+
declare module "net" {
1789+
export type n = number;
1790+
}
1791+
declare module "stream" {
1792+
export type s = string;
1793+
}`,
1794+
};
1795+
1796+
const host = createServerHost([file, libFile]);
1797+
const installer = new (class extends Installer {
1798+
constructor() {
1799+
super(host, { globalTypingsCacheLocation, typesRegistry: createTypesRegistry("node") });
1800+
}
1801+
installWorker(_requestId: number, _args: string[], _cwd: string, cb: TI.RequestCompletedAction) {
1802+
executeCommand(this, host, ["node"], [nodeTyping], cb);
1803+
}
1804+
})();
1805+
const projectService = createProjectService(host, { typingsInstaller: installer });
1806+
projectService.openClientFile(file.path);
1807+
projectService.checkNumberOfProjects({ inferredProjects: 1 });
1808+
1809+
const proj = projectService.inferredProjects[0];
1810+
checkProjectActualFiles(proj, [file.path, libFile.path]);
1811+
installer.installAll(/*expectedCount*/ 1);
1812+
host.checkTimeoutQueueLengthAndRun(2);
1813+
checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]);
1814+
projectService.applyChangesInOpenFiles(
1815+
/*openFiles*/ undefined,
1816+
arrayIterator([{
1817+
fileName: file.path,
1818+
changes: arrayIterator([{
1819+
span: {
1820+
start: file.content.indexOf(`"stream"`) + 2,
1821+
length: 0
1822+
},
1823+
newText: " "
1824+
}])
1825+
}]),
1826+
/*closedFiles*/ undefined
1827+
);
1828+
// Below timeout Updates the typings to empty array because of "s tream" as unsresolved import
1829+
// and schedules the update graph because of this.
1830+
host.checkTimeoutQueueLengthAndRun(2);
1831+
checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]);
1832+
1833+
// Here, since typings doesnt contain node typings and resolution fails and
1834+
// node typings go out of project
1835+
host.checkTimeoutQueueLengthAndRun(2);
1836+
checkProjectActualFiles(proj, [file.path, libFile.path]);
1837+
});
17761838
});
17771839

17781840
describe("unittests:: tsserver:: typingsInstaller:: tsserver:: with inferred Project", () => {

0 commit comments

Comments
 (0)