Skip to content

Commit 245bfc2

Browse files
committed
Add tests for lockFile3
1 parent 81c9518 commit 245bfc2

3 files changed

Lines changed: 1124 additions & 0 deletions

File tree

src/testRunner/unittests/tsserver/typingsInstaller.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,113 @@ describe("unittests:: tsserver:: typingsInstaller:: General functionality", () =
13721372
host.runPendingInstalls();
13731373
baselineTsserverLogs("typingsInstaller", "non expired cache entry", session);
13741374
});
1375+
1376+
it("expired cache entry (inferred project, should install typings) lockFile3", () => {
1377+
const file1 = {
1378+
path: "/home/src/projects/project/app.js",
1379+
content: "",
1380+
};
1381+
const packageJson = {
1382+
path: "/home/src/projects/project/package.json",
1383+
content: jsonToReadableText({
1384+
name: "test",
1385+
dependencies: {
1386+
jquery: "^3.1.0",
1387+
},
1388+
}),
1389+
};
1390+
const jquery = {
1391+
path: getPathForTypeScriptTypingInstallerCacheTest("node_modules/@types/jquery/index.d.ts"),
1392+
content: "declare const $: { x: number }",
1393+
};
1394+
const cacheConfig = {
1395+
path: getPathForTypeScriptTypingInstallerCacheTest("package.json"),
1396+
content: jsonToReadableText({
1397+
dependencies: {
1398+
"types-registry": "^0.1.317",
1399+
},
1400+
devDependencies: {
1401+
"@types/jquery": "^1.0.0",
1402+
},
1403+
}),
1404+
};
1405+
const cacheLockConfig = {
1406+
path: getPathForTypeScriptTypingInstallerCacheTest("package-lock.json"),
1407+
content: jsonToReadableText({
1408+
packages: {
1409+
"node_modules/@types/jquery": {
1410+
version: "1.0.0",
1411+
},
1412+
},
1413+
}),
1414+
};
1415+
const host = TestServerHost.createServerHost(
1416+
[file1, packageJson, jquery, cacheConfig, cacheLockConfig],
1417+
{ typingsInstallerTypesRegistry: "jquery" },
1418+
);
1419+
const session = new TestSession({
1420+
host,
1421+
useSingleInferredProject: true,
1422+
installAction: [jquery],
1423+
});
1424+
openFilesForSession([file1], session);
1425+
host.runPendingInstalls();
1426+
host.runQueuedTimeoutCallbacks();
1427+
baselineTsserverLogs("typingsInstaller", "expired cache entry lockFile3", session);
1428+
});
1429+
1430+
it("non-expired cache entry (inferred project, should not install typings) lockFile3", () => {
1431+
const file1 = {
1432+
path: "/home/src/projects/project/app.js",
1433+
content: "",
1434+
};
1435+
const packageJson = {
1436+
path: "/home/src/projects/project/package.json",
1437+
content: jsonToReadableText({
1438+
name: "test",
1439+
dependencies: {
1440+
jquery: "^3.1.0",
1441+
},
1442+
}),
1443+
};
1444+
const cacheConfig = {
1445+
path: getPathForTypeScriptTypingInstallerCacheTest("package.json"),
1446+
content: jsonToReadableText({
1447+
dependencies: {
1448+
"types-registry": "^0.1.317",
1449+
},
1450+
devDependencies: {
1451+
"@types/jquery": "^1.3.0",
1452+
},
1453+
}),
1454+
};
1455+
const cacheLockConfig = {
1456+
path: getPathForTypeScriptTypingInstallerCacheTest("package-lock.json"),
1457+
content: jsonToReadableText({
1458+
packages: {
1459+
"node_modules/@types/jquery": {
1460+
version: "1.3.0",
1461+
},
1462+
},
1463+
}),
1464+
};
1465+
const jquery = {
1466+
path: getPathForTypeScriptTypingInstallerCacheTest("node_modules/@types/jquery/index.d.ts"),
1467+
content: "declare const $: { x: number }",
1468+
};
1469+
const host = TestServerHost.createServerHost(
1470+
[file1, packageJson, cacheConfig, cacheLockConfig, jquery],
1471+
{ typingsInstallerTypesRegistry: "jquery" },
1472+
);
1473+
const session = new TestSession({
1474+
host,
1475+
useSingleInferredProject: true,
1476+
installAction: true,
1477+
});
1478+
openFilesForSession([file1], session);
1479+
host.runPendingInstalls();
1480+
baselineTsserverLogs("typingsInstaller", "non expired cache entry lockFile3", session);
1481+
});
13751482
});
13761483

13771484
describe("unittests:: tsserver:: typingsInstaller:: Validate package name:", () => {

0 commit comments

Comments
 (0)