1namespace ts.tscWatch { 2 describe("unittests:: tsbuildWatch:: watchMode:: with demo project", () => { 3 const projectLocation = `${TestFSWithWatch.tsbuildProjectsLocation}/demo`; 4 let coreFiles: File[]; 5 let animalFiles: File[]; 6 let zooFiles: File[]; 7 let solutionFile: File; 8 let baseConfig: File; 9 let allFiles: File[]; 10 before(() => { 11 coreFiles = subProjectFiles("core", ["tsconfig.json", "utilities.ts"]); 12 animalFiles = subProjectFiles("animals", ["tsconfig.json", "animal.ts", "dog.ts", "index.ts"]); 13 zooFiles = subProjectFiles("zoo", ["tsconfig.json", "zoo.ts"]); 14 solutionFile = projectFile("tsconfig.json"); 15 baseConfig = projectFile("tsconfig-base.json"); 16 allFiles = [...coreFiles, ...animalFiles, ...zooFiles, solutionFile, baseConfig, { path: libFile.path, content: libContent }]; 17 }); 18 19 after(() => { 20 coreFiles = undefined!; 21 animalFiles = undefined!; 22 zooFiles = undefined!; 23 solutionFile = undefined!; 24 baseConfig = undefined!; 25 allFiles = undefined!; 26 }); 27 28 verifyTscWatch({ 29 scenario: "demo", 30 subScenario: "updates with circular reference", 31 commandLineArgs: ["-b", "-w", "-verbose"], 32 sys: () => { 33 const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation }); 34 sys.writeFile(coreFiles[0].path, coreFiles[0].content.replace( 35 "}", 36 `}, 37 "references": [ 38 { 39 "path": "../zoo" 40 } 41 ]` 42 )); 43 return sys; 44 }, 45 changes: [ 46 { 47 caption: "Fix error", 48 change: sys => sys.writeFile(coreFiles[0].path, coreFiles[0].content), 49 timeouts: sys => { 50 sys.checkTimeoutQueueLengthAndRun(1); // build core 51 sys.checkTimeoutQueueLengthAndRun(1); // build animals, zoo and solution 52 sys.checkTimeoutQueueLength(0); 53 }, 54 } 55 ] 56 }); 57 58 verifyTscWatch({ 59 scenario: "demo", 60 subScenario: "updates with bad reference", 61 commandLineArgs: ["-b", "-w", "-verbose"], 62 sys: () => { 63 const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation }); 64 sys.writeFile(coreFiles[1].path, `import * as A from '../animals'; 65${coreFiles[1].content}`); 66 return sys; 67 }, 68 changes: [ 69 { 70 caption: "Prepend a line", 71 change: sys => sys.writeFile(coreFiles[1].path, ` 72import * as A from '../animals'; 73${coreFiles[1].content}`), 74 // build core 75 timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, 76 } 77 ] 78 }); 79 80 function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] { 81 return fileNames.map(file => projectFile(`${subProject}/${file}`)); 82 } 83 84 function projectFile(fileName: string): File { 85 return TestFSWithWatch.getTsBuildProjectFile("demo", fileName); 86 } 87 }); 88}