|
1 | 1 | import * as ts from "../../_namespaces/ts.js"; |
2 | 2 | import { dedent } from "../../_namespaces/Utils.js"; |
3 | 3 | import { jsonToReadableText } from "../helpers.js"; |
| 4 | +import { getPathForTypeScriptTypingInstallerCacheTest } from "../helpers/contents.js"; |
4 | 5 | import { |
5 | | - compilerOptionsToConfigJson, |
6 | | - getPathForTypeScriptTypingInstallerCacheTest, |
7 | | -} from "../helpers/contents.js"; |
8 | | -import { |
| 6 | + forEachModuleCacheScenario, |
9 | 7 | forEachResolutionCacheLifeTimeScenario, |
| 8 | + forEachTypeReferenceResolutionScenario, |
10 | 9 | ResolutionCacheLifeTimeScenarios, |
11 | 10 | } from "../helpers/resolutionCache.js"; |
12 | 11 | import { |
@@ -627,72 +626,12 @@ export const x = 10;`, |
627 | 626 | }); |
628 | 627 |
|
629 | 628 | describe("unittests:: tsserver:: resolutionCache:: tsserverProjectSystem with project references", () => { |
630 | | - it("sharing across references", () => { |
631 | | - const host = TestServerHost.createServerHost({ |
632 | | - "/users/username/projects/node_modules/moduleX/index.d.ts": "export const x = 10;", |
633 | | - "/users/username/projects/common/tsconfig.json": jsonToReadableText({ |
634 | | - compilerOptions: compilerOptionsToConfigJson({ |
635 | | - composite: true, |
636 | | - traceResolution: true, |
637 | | - }), |
638 | | - }), |
639 | | - "/users/username/projects/common/moduleA.ts": "export const a = 10;", |
640 | | - "/users/username/projects/common/moduleB.ts": dedent` |
641 | | - import { x } from "moduleX"; |
642 | | - export const b = x; |
643 | | - `, |
644 | | - "/users/username/projects/app/tsconfig.json": jsonToReadableText({ |
645 | | - compilerOptions: compilerOptionsToConfigJson({ |
646 | | - composite: true, |
647 | | - traceResolution: true, |
648 | | - }), |
649 | | - references: [{ path: "../common" }], |
650 | | - }), |
651 | | - "/users/username/projects/app/appA.ts": dedent` |
652 | | - import { x } from "moduleX"; |
653 | | - export const y = x; |
654 | | - `, |
655 | | - "/users/username/projects/app/appB.ts": dedent` |
656 | | - import { x } from "../common/moduleB"; |
657 | | - export const y = x; |
658 | | - `, |
| 629 | + forEachModuleCacheScenario(/*forTsserver*/ true, (scenario, getHost) => { |
| 630 | + it(scenario, () => { |
| 631 | + const session = new TestSession(getHost()); |
| 632 | + openFilesForSession(["/home/src/workspaces/project/app/appB.ts"], session); |
| 633 | + baselineTsserverLogs("resolutionCache", scenario, session); |
659 | 634 | }); |
660 | | - const session = new TestSession(host); |
661 | | - openFilesForSession(["/users/username/projects/app/appB.ts"], session); |
662 | | - baselineTsserverLogs("resolutionCache", "sharing across references", session); |
663 | | - }); |
664 | | - |
665 | | - it("not sharing across references", () => { |
666 | | - const host = TestServerHost.createServerHost({ |
667 | | - "/users/username/projects/node_modules/moduleX/index.d.ts": "export const x = 10;", |
668 | | - "/users/username/projects/common/tsconfig.json": jsonToReadableText({ |
669 | | - compilerOptions: { composite: true, traceResolution: true }, |
670 | | - }), |
671 | | - "/users/username/projects/common/moduleA.ts": "export const a = 10;", |
672 | | - "/users/username/projects/common/moduleB.ts": dedent` |
673 | | - import { x } from "moduleX"; |
674 | | - export const b = x; |
675 | | - `, |
676 | | - "/users/username/projects/app/tsconfig.json": jsonToReadableText({ |
677 | | - compilerOptions: { |
678 | | - composite: true, |
679 | | - traceResolution: true, |
680 | | - typeRoots: [], // Just some sample option that is different across the projects |
681 | | - }, |
682 | | - references: [{ path: "../common" }], |
683 | | - }), |
684 | | - "/users/username/projects/app/appA.ts": dedent` |
685 | | - import { x } from "moduleX"; |
686 | | - export const y = x; |
687 | | - `, |
688 | | - "/users/username/projects/app/appB.ts": dedent` |
689 | | - import { x } from "../common/moduleB"; |
690 | | - export const y = x; |
691 | | - `, |
692 | | - }); |
693 | | - const session = new TestSession(host); |
694 | | - openFilesForSession(["/users/username/projects/app/appB.ts"], session); |
695 | | - baselineTsserverLogs("resolutionCache", "not sharing across references", session); |
696 | 635 | }); |
697 | 636 | }); |
698 | 637 |
|
@@ -783,3 +722,72 @@ describe("unittests:: tsserver:: resolutionCache:: resolution lifetime", () => { |
783 | 722 | }), |
784 | 723 | ); |
785 | 724 | }); |
| 725 | + |
| 726 | +describe("unittests:: tsserver:: resolutionCache:: effective typeRoots", () => { |
| 727 | + it("effective type roots affect type reference directives", () => { |
| 728 | + const host = TestServerHost.createServerHost({ |
| 729 | + "/users/username/projects/replay/axios-src/test/module/ts-require/index.js": dedent` |
| 730 | + export const a = 10; |
| 731 | +
|
| 732 | + `, |
| 733 | + "/users/username/projects/replay/axios-src/test/module/ts-require/node_modules/@types/node/index.d.ts": dedent` |
| 734 | + export const x = 10; |
| 735 | + `, |
| 736 | + "/users/username/projects/replay/axios-src/node_modules/@types/responselike/index.d.ts": dedent` |
| 737 | + /// <reference types="node" /> |
| 738 | + export const z = 10; |
| 739 | + `, |
| 740 | + "/users/username/projects/replay/axios-src/test/module/ts/index.js": dedent` |
| 741 | + export const y = 10; |
| 742 | + `, |
| 743 | + "/users/username/projects/replay/axios-src/test/module/ts/node_modules/@types/node/index.d.ts": dedent` |
| 744 | + export const x = 10; |
| 745 | + `, |
| 746 | + }); |
| 747 | + const session = new TestSession({ host, disableAutomaticTypingAcquisition: true }); |
| 748 | + session.executeCommandSeq<ts.server.protocol.SetCompilerOptionsForInferredProjectsRequest>({ |
| 749 | + command: ts.server.protocol.CommandTypes.CompilerOptionsForInferredProjects, |
| 750 | + arguments: { |
| 751 | + options: { traceResolution: true }, |
| 752 | + }, |
| 753 | + }); |
| 754 | + // This will add responselike/index.d.ts and resolve the type ref "node" to "test/module/ts-require/node_modules/@types/node/index.d.ts" because of current directory |
| 755 | + openFilesForSession(["/users/username/projects/replay/axios-src/test/module/ts-require/index.js"], session); |
| 756 | + session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({ // Schedule update |
| 757 | + command: ts.server.protocol.CommandTypes.UpdateOpen, |
| 758 | + arguments: { |
| 759 | + changedFiles: [{ |
| 760 | + fileName: "/users/username/projects/replay/axios-src/test/module/ts-require/index.js", |
| 761 | + textChanges: [{ |
| 762 | + newText: "//comment", |
| 763 | + start: { line: 2, offset: 1 }, |
| 764 | + end: { line: 2, offset: 1 }, |
| 765 | + }], |
| 766 | + }], |
| 767 | + }, |
| 768 | + }); |
| 769 | + // This will also use responselike/index.d.ts and needs to resolve node to "test/module/ts/node_modules/@types/node/index.d.ts" because of current directory |
| 770 | + openFilesForSession(["/users/username/projects/replay/axios-src/test/module/ts/index.js"], session); |
| 771 | + // Should not change any resolutions in inferredProject1 |
| 772 | + session.executeCommandSeq<ts.server.protocol.NavtoRequest>({ |
| 773 | + command: ts.server.protocol.CommandTypes.Navto, |
| 774 | + arguments: { |
| 775 | + searchValue: "a", |
| 776 | + maxResultCount: 256, |
| 777 | + }, |
| 778 | + }); |
| 779 | + baselineTsserverLogs("resolutionCache", "effective type roots affect type reference directives", session); |
| 780 | + }); |
| 781 | + |
| 782 | + forEachTypeReferenceResolutionScenario(/*forTsserver*/ true, (scenario, getHost, edits) => { |
| 783 | + it(scenario, () => { |
| 784 | + const session = new TestSession(getHost()); |
| 785 | + openFilesForSession([ |
| 786 | + "/home/src/workspaces/project/test/module/ts-require/index.ts", |
| 787 | + "/home/src/workspaces/project/test/module/ts/index.ts", |
| 788 | + ], session); |
| 789 | + forEachTscWatchEdit(session, edits(), ts.noop); |
| 790 | + baselineTsserverLogs("resolutionCache", scenario, session); |
| 791 | + }); |
| 792 | + }); |
| 793 | +}); |
0 commit comments