1namespace ts.tscWatch { 2 describe("unittests:: tsbuildWatch:: watchMode:: projectsBuilding", () => { 3 function pkgs<T>(cb: (index: number) => T, count: number, startIndex?: number): T[] { 4 const result: T[] = []; 5 for (let index = startIndex || 0; count > 0; index++, count--) { 6 result.push(cb(index)); 7 } 8 return result; 9 } 10 function createPkgReference(index: number) { 11 return { path: `./pkg${index}` }; 12 } 13 function pkgFiles(index: number): File[] { 14 return [ 15 { 16 path: `${projectRoot}/pkg${index}/index.ts`, 17 content: `export const pkg${index} = ${index};` 18 }, 19 { 20 path: `${projectRoot}/pkg${index}/tsconfig.json`, 21 content: JSON.stringify({ 22 compilerOptions: { composite: true }, 23 references: index === 0 ? 24 undefined : 25 [{ path: `../pkg0` }] 26 }) 27 } 28 ]; 29 } 30 function solution(maxPkgs: number): File { 31 return { 32 path: `${projectRoot}/tsconfig.json`, 33 content: JSON.stringify({ 34 references: pkgs(createPkgReference, maxPkgs), 35 files: [], 36 }) 37 }; 38 } 39 function checkBuildPkg(startIndex: number, count: number): TscWatchCompileChange { 40 return { 41 caption: `build ${pkgs(index => `pkg${index}`, count, startIndex).join(",")}`, 42 change: noop, 43 timeouts: checkSingleTimeoutQueueLengthAndRun, 44 }; 45 } 46 verifyTscWatch({ 47 scenario: "projectsBuilding", 48 subScenario: `when there are 3 projects in a solution`, 49 commandLineArgs: ["-b", "-w", "-v"], 50 sys: () => createWatchedSystem( 51 [libFile, ...flatMap(pkgs(pkgFiles, 3), identity), solution(3)], 52 { currentDirectory: projectRoot } 53 ), 54 changes: [ 55 { 56 caption: "dts doesn't change", 57 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `const someConst2 = 10;`), 58 timeouts: checkSingleTimeoutQueueLengthAndRun, // Build pkg0 and update timestamps 59 }, 60 noopChange, 61 { 62 caption: "dts change", 63 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst = 10;`), 64 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 65 }, 66 checkBuildPkg(1, 2), 67 noopChange, 68 ] 69 }); 70 verifyTscWatch({ 71 scenario: "projectsBuilding", 72 subScenario: `when there are 5 projects in a solution`, 73 commandLineArgs: ["-b", "-w", "-v"], 74 sys: () => createWatchedSystem( 75 [libFile, ...flatMap(pkgs(pkgFiles, 5), identity), solution(5)], 76 { currentDirectory: projectRoot } 77 ), 78 changes: [ 79 { 80 caption: "dts doesn't change", 81 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `const someConst2 = 10;`), 82 timeouts: checkSingleTimeoutQueueLengthAndRun, // Build pkg0 and update timestamps 83 }, 84 noopChange, 85 { 86 caption: "dts change", 87 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst = 10;`), 88 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 89 }, 90 checkBuildPkg(1, 4), 91 noopChange, 92 ] 93 }); 94 verifyTscWatch({ 95 scenario: "projectsBuilding", 96 subScenario: `when there are 8 projects in a solution`, 97 commandLineArgs: ["-b", "-w", "-v"], 98 sys: () => createWatchedSystem( 99 [libFile, ...flatMap(pkgs(pkgFiles, 8), identity), solution(8)], 100 { currentDirectory: projectRoot } 101 ), 102 changes: [ 103 { 104 caption: "dts doesn't change", 105 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `const someConst2 = 10;`), 106 timeouts: checkSingleTimeoutQueueLengthAndRun, // Build pkg0 and update timestamps 107 }, 108 noopChange, 109 { 110 caption: "dts change", 111 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst = 10;`), 112 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 113 }, 114 checkBuildPkg(1, 5), 115 checkBuildPkg(6, 2), 116 noopChange, 117 { 118 caption: "dts change2", 119 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst3 = 10;`), 120 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 121 }, 122 checkBuildPkg(1, 5), 123 { 124 caption: "change while building", 125 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `const someConst4 = 10;`), 126 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 127 }, 128 checkBuildPkg(6, 2), 129 noopChange, 130 ] 131 }); 132 verifyTscWatch({ 133 scenario: "projectsBuilding", 134 subScenario: `when there are 23 projects in a solution`, 135 commandLineArgs: ["-b", "-w", "-v"], 136 sys: () => createWatchedSystem( 137 [libFile, ...flatMap(pkgs(pkgFiles, 23), identity), solution(23)], 138 { currentDirectory: projectRoot } 139 ), 140 changes: [ 141 { 142 caption: "dts doesn't change", 143 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `const someConst2 = 10;`), 144 timeouts: checkSingleTimeoutQueueLengthAndRun, // Build pkg0 and update timestamps 145 }, 146 noopChange, 147 { 148 caption: "dts change", 149 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst = 10;`), 150 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 151 }, 152 checkBuildPkg(1, 5), 153 checkBuildPkg(6, 5), 154 checkBuildPkg(11, 5), 155 checkBuildPkg(16, 5), 156 checkBuildPkg(21, 3), 157 noopChange, 158 { 159 caption: "dts change2", 160 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst3 = 10;`), 161 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 162 }, 163 checkBuildPkg(1, 5), 164 checkBuildPkg(6, 5), 165 { 166 caption: "change while building", 167 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `const someConst4 = 10;`), 168 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 169 }, 170 checkBuildPkg(11, 5), 171 { 172 caption: "change while building: dts changes", 173 change: sys => sys.appendFile(`${projectRoot}/pkg0/index.ts`, `export const someConst5 = 10;`), 174 timeouts: checkSingleTimeoutQueueLengthAndRun // Build pkg0 175 }, 176 checkBuildPkg(1, 5), 177 checkBuildPkg(6, 5), 178 checkBuildPkg(11, 5), 179 checkBuildPkg(16, 5), 180 checkBuildPkg(21, 3), 181 noopChange, 182 ] 183 }); 184 }); 185}