• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace ts.tscWatch {
2    describe("unittests:: tsbuildWatch:: watchEnvironment:: tsbuild:: watchMode:: with different watch environments", () => {
3        it("watchFile on same file multiple times because file is part of multiple projects", () => {
4            const project = `${TestFSWithWatch.tsbuildProjectsLocation}/myproject`;
5            let maxPkgs = 4;
6            const configPath = `${project}/tsconfig.json`;
7            const typing: File = {
8                path: `${project}/typings/xterm.d.ts`,
9                content: "export const typing = 10;"
10            };
11
12            const allPkgFiles = pkgs(pkgFiles);
13            const system = createWatchedSystem([libFile, typing, ...flatArray(allPkgFiles)], { currentDirectory: project });
14            writePkgReferences(system);
15            const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(system);
16            const host = createSolutionBuilderWithWatchHostForBaseline(sys, cb);
17            const solutionBuilder = createSolutionBuilderWithWatch(host, ["tsconfig.json"], { watch: true, verbose: true });
18            solutionBuilder.build();
19            runWatchBaseline({
20                scenario: "watchEnvironment",
21                subScenario: `same file in multiple projects with single watcher per file`,
22                commandLineArgs: ["--b", "--w"],
23                sys,
24                baseline,
25                oldSnap,
26                getPrograms,
27                changes: [
28                    {
29                        caption: "modify typing file",
30                        change: sys => sys.writeFile(typing.path, `${typing.content}export const typing1 = 10;`),
31                        timeouts: sys => {
32                            sys.checkTimeoutQueueLengthAndRun(1);
33                            checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout(sys);
34                        }
35                    },
36                    {
37                        // Make change
38                        caption: "change pkg references",
39                        change: sys => {
40                            maxPkgs--;
41                            writePkgReferences(sys);
42                        },
43                        timeouts: checkSingleTimeoutQueueLengthAndRun,
44                    },
45                    {
46                        caption: "modify typing file",
47                        change: sys => sys.writeFile(typing.path, typing.content),
48                        timeouts: sys => {
49                            sys.checkTimeoutQueueLengthAndRun(1);
50                            checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout(sys);
51                        }
52                    },
53                    {
54                        // Make change to remove all watches
55                        caption: "change pkg references to remove all watches",
56                        change: sys => {
57                            maxPkgs = 0;
58                            writePkgReferences(sys);
59                        },
60                        timeouts: checkSingleTimeoutQueueLengthAndRun,
61                    },
62                    {
63                        caption: "modify typing file",
64                        change: sys => sys.writeFile(typing.path, `${typing.content}export const typing1 = 10;`),
65                        timeouts: sys => sys.checkTimeoutQueueLength(0),
66                    },
67                ],
68                watchOrSolution: solutionBuilder
69            });
70
71            function flatArray<T>(arr: T[][]): readonly T[] {
72                return flatMap(arr, identity);
73            }
74            function pkgs<T>(cb: (index: number) => T): T[] {
75                const result: T[] = [];
76                for (let index = 0; index < maxPkgs; index++) {
77                    result.push(cb(index));
78                }
79                return result;
80            }
81            function createPkgReference(index: number) {
82                return { path: `./pkg${index}` };
83            }
84            function pkgFiles(index: number): File[] {
85                return [
86                    {
87                        path: `${project}/pkg${index}/index.ts`,
88                        content: `export const pkg${index} = ${index};`
89                    },
90                    {
91                        path: `${project}/pkg${index}/tsconfig.json`,
92                        content: JSON.stringify({
93                            complerOptions: { composite: true },
94                            include: [
95                                "**/*.ts",
96                                "../typings/xterm.d.ts"
97                            ]
98                        })
99                    }
100                ];
101            }
102            function writePkgReferences(system: TestFSWithWatch.TestServerHost) {
103                system.writeFile(configPath, JSON.stringify({
104                    files: [],
105                    include: [],
106                    references: pkgs(createPkgReference)
107                }));
108            }
109        });
110    });
111}
112