|
1 | | -import { AsyncTest, Expect, Setup, Timeout } from "alsatian"; |
| 1 | +import { AsyncTest, Expect, Setup, TestCase, Timeout } from "alsatian"; |
2 | 2 | import { fork } from "child_process"; |
3 | 3 | import * as fs from "fs"; |
4 | 4 | import * as path from "path"; |
5 | 5 |
|
6 | 6 | export class CompilerWatchModeTest { |
7 | 7 |
|
8 | | - private singleFilePath: string; |
9 | | - private singleFilePathOut: string; |
10 | | - |
| 8 | + @TestCase(["-w", path.join(__dirname, "./testfiles/watch.ts")], |
| 9 | + path.join(__dirname, "./testfiles/watch.ts")) |
| 10 | + @TestCase(["-w", "-p", path.join(__dirname, "./projects/watchmode/")], |
| 11 | + path.join(__dirname, "./projects/watchmode/watch.ts")) |
11 | 12 | @AsyncTest("Watch single File") |
12 | | - @Timeout(10000) |
13 | | - public async testSingle(): Promise<void> { |
14 | | - // spawn watcher in different thread, that way we can just terminate it after test are completed |
| 13 | + @Timeout(16000) |
| 14 | + public async testSingle(args: string[], fileToChange: string): Promise<void> { |
| 15 | + fileToChange = fileToChange; |
| 16 | + const fileToChangeOut = fileToChange.replace(".ts", ".lua"); |
| 17 | + |
15 | 18 | const child = fork(path.join(__dirname, "watcher_proccess.ts")); |
16 | | - child.send(["-w", this.singleFilePath]); |
| 19 | + child.send(args); |
17 | 20 |
|
18 | | - await this.waitForFileExists(this.singleFilePathOut, 4000) |
| 21 | + await this.waitForFileExists(fileToChangeOut, 9000) |
19 | 22 | .catch(err => console.error(err)); |
20 | 23 |
|
21 | | - Expect(fs.existsSync(this.singleFilePathOut)).toBe(true); |
| 24 | + Expect(fs.existsSync(fileToChangeOut)).toBe(true); |
22 | 25 |
|
23 | | - const initialResultLua = fs.readFileSync(this.singleFilePathOut); |
24 | | - const originalTS = fs.readFileSync(this.singleFilePath); |
| 26 | + const initialResultLua = fs.readFileSync(fileToChangeOut); |
| 27 | + const originalTS = fs.readFileSync(fileToChange); |
25 | 28 |
|
26 | | - fs.unlinkSync(this.singleFilePathOut); |
| 29 | + fs.unlinkSync(fileToChangeOut); |
27 | 30 |
|
28 | | - fs.writeFileSync(this.singleFilePath, "class MyTest2 {}"); |
| 31 | + fs.writeFileSync(fileToChange, "class MyTest2 {}"); |
29 | 32 |
|
30 | | - await this.waitForFileExists(this.singleFilePathOut) |
| 33 | + await this.waitForFileExists(fileToChangeOut, 5000) |
31 | 34 | .catch(err => console.error(err)); |
32 | 35 |
|
33 | | - const updatedResultLua = fs.readFileSync(this.singleFilePathOut).toString(); |
| 36 | + const updatedResultLua = fs.readFileSync(fileToChangeOut).toString(); |
34 | 37 |
|
35 | 38 | Expect(initialResultLua).not.toEqual(updatedResultLua); |
36 | 39 |
|
37 | | - fs.writeFileSync(this.singleFilePath, originalTS); |
| 40 | + fs.writeFileSync(fileToChange, originalTS); |
38 | 41 |
|
39 | | - fs.unlinkSync(this.singleFilePathOut); |
| 42 | + fs.unlinkSync(fileToChangeOut); |
40 | 43 |
|
41 | 44 | child.kill(); |
42 | 45 | } |
43 | 46 |
|
44 | | - @Setup |
45 | | - private setup(): void { |
46 | | - this.singleFilePath = path.join(__dirname, "./testfiles/watch_single.ts"); |
47 | | - this.singleFilePathOut = path.join(__dirname, "./testfiles/watch_single.lua"); |
48 | | - } |
49 | | - |
50 | 47 | private waitForFileExists(filepath: string, timeout: number = 3000): Promise<void> { |
51 | 48 | const interval = 200; |
52 | 49 | return new Promise((resolve, reject) => { |
|
0 commit comments