• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace ts {
2    describe("unittests:: tsbuild - output file paths", () => {
3        const noChangeProject: TscIncremental = {
4            buildKind: BuildKind.NoChangeRun,
5            modifyFs: noop,
6            subScenario: "Normal build without change, that does not block emit on error to show files that get emitted",
7            commandLineArgs: ["-p", "/src/tsconfig.json"],
8        };
9        const incrementalScenarios: TscIncremental[] = [
10            noChangeRun,
11            noChangeProject,
12        ];
13
14        function verify(input: Pick<VerifyTsBuildInput, "subScenario" | "fs" | "incrementalScenarios">, expectedOuptutNames: readonly string[]) {
15            verifyTscSerializedIncrementalEdits({
16                scenario: "outputPaths",
17                commandLineArgs: ["--b", "/src/tsconfig.json", "-v"],
18                ...input
19            });
20
21            it("verify getOutputFileNames", () => {
22                const sys = new fakes.System(input.fs().makeReadonly(), { executingFilePath: "/lib/tsc" }) as TscCompileSystem;
23                ;
24                assert.deepEqual(
25                    getOutputFileNames(
26                        parseConfigFileWithSystem("/src/tsconfig.json", {}, {}, sys, noop)!,
27                        "/src/src/index.ts",
28                        /*ignoreCase*/ false
29                    ),
30                    expectedOuptutNames
31                );
32            });
33        }
34
35        verify({
36            subScenario: "when rootDir is not specified",
37            fs: () => loadProjectFromFiles({
38                "/src/src/index.ts": "export const x = 10;",
39                "/src/tsconfig.json": JSON.stringify({
40                    compilerOptions: {
41                        outDir: "dist"
42                    }
43                })
44            }),
45            incrementalScenarios,
46        }, ["/src/dist/index.js"]);
47
48        verify({
49            subScenario: "when rootDir is not specified and is composite",
50            fs: () => loadProjectFromFiles({
51                "/src/src/index.ts": "export const x = 10;",
52                "/src/tsconfig.json": JSON.stringify({
53                    compilerOptions: {
54                        outDir: "dist",
55                        composite: true
56                    }
57                })
58            }),
59            incrementalScenarios: [
60                noChangeRun,
61                {
62                    ...noChangeProject,
63                    cleanBuildDiscrepancies: () => {
64                        const map = new Map<string, CleanBuildDescrepancy>();
65                        map.set("/src/dist/tsconfig.tsbuildinfo", CleanBuildDescrepancy.CleanFileTextDifferent); // tsbuildinfo will have -p setting when built using -p vs no build happens incrementally because of no change.
66                        return map;
67                    }
68                }
69            ],
70        }, ["/src/dist/src/index.js", "/src/dist/src/index.d.ts"]);
71
72        verify({
73            subScenario: "when rootDir is specified",
74            fs: () => loadProjectFromFiles({
75                "/src/src/index.ts": "export const x = 10;",
76                "/src/tsconfig.json": JSON.stringify({
77                    compilerOptions: {
78                        outDir: "dist",
79                        rootDir: "src"
80                    }
81                })
82            }),
83            incrementalScenarios,
84        }, ["/src/dist/index.js"]);
85
86        verify({
87            subScenario: "when rootDir is specified but not all files belong to rootDir",
88            fs: () => loadProjectFromFiles({
89                "/src/src/index.ts": "export const x = 10;",
90                "/src/types/type.ts": "export type t = string;",
91                "/src/tsconfig.json": JSON.stringify({
92                    compilerOptions: {
93                        outDir: "dist",
94                        rootDir: "src"
95                    }
96                })
97            }),
98            incrementalScenarios,
99        }, ["/src/dist/index.js"]);
100
101        verify({
102            subScenario: "when rootDir is specified but not all files belong to rootDir and is composite",
103            fs: () => loadProjectFromFiles({
104                "/src/src/index.ts": "export const x = 10;",
105                "/src/types/type.ts": "export type t = string;",
106                "/src/tsconfig.json": JSON.stringify({
107                    compilerOptions: {
108                        outDir: "dist",
109                        rootDir: "src",
110                        composite: true
111                    }
112                })
113            }),
114            incrementalScenarios,
115        }, ["/src/dist/index.js", "/src/dist/index.d.ts"]);
116    });
117}
118