Skip to content

Commit fcfb680

Browse files
committed
Improved test & coverage ignore
1 parent ec5f397 commit fcfb680

6 files changed

Lines changed: 28 additions & 25 deletions

File tree

src/Compiler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { LuaLibImportKind, LuaTarget, LuaTranspiler, TranspileError } from "./Tr
1111

1212
export function compile(argv: string[]): void {
1313
const commandLine = parseCommandLine(argv);
14+
/* istanbul ignore if: tested in test/compiler/watchmode.spec with subproccess */
1415
if (commandLine.options.watch) {
1516
watchWithOptions(commandLine.fileNames, commandLine.options);
1617
} else {
1718
compileFilesWithOptions(commandLine.fileNames, commandLine.options);
1819
}
1920
}
2021

22+
/* istanbul ignore next: tested in test/compiler/watchmode.spec with subproccess */
2123
export function watchWithOptions(fileNames: string[], options: CompilerOptions): void {
2224
let host: ts.WatchCompilerHost<ts.SemanticDiagnosticsBuilderProgram>;
2325
let config = false;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"luaTarget": "JIT"
3+
}

test/compiler/testfiles/watch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class MyTest {}

test/compiler/watcher_proccess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { compile } from "../../src/Compiler";
22

33
process.on("message", args => {
44
compile(args);
5-
});
5+
});

test/compiler/watchmode.spec.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,49 @@
1-
import { AsyncTest, Expect, Setup, Timeout } from "alsatian";
1+
import { AsyncTest, Expect, Setup, TestCase, Timeout } from "alsatian";
22
import { fork } from "child_process";
33
import * as fs from "fs";
44
import * as path from "path";
55

66
export class CompilerWatchModeTest {
77

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"))
1112
@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+
1518
const child = fork(path.join(__dirname, "watcher_proccess.ts"));
16-
child.send(["-w", this.singleFilePath]);
19+
child.send(args);
1720

18-
await this.waitForFileExists(this.singleFilePathOut, 4000)
21+
await this.waitForFileExists(fileToChangeOut, 9000)
1922
.catch(err => console.error(err));
2023

21-
Expect(fs.existsSync(this.singleFilePathOut)).toBe(true);
24+
Expect(fs.existsSync(fileToChangeOut)).toBe(true);
2225

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);
2528

26-
fs.unlinkSync(this.singleFilePathOut);
29+
fs.unlinkSync(fileToChangeOut);
2730

28-
fs.writeFileSync(this.singleFilePath, "class MyTest2 {}");
31+
fs.writeFileSync(fileToChange, "class MyTest2 {}");
2932

30-
await this.waitForFileExists(this.singleFilePathOut)
33+
await this.waitForFileExists(fileToChangeOut, 5000)
3134
.catch(err => console.error(err));
3235

33-
const updatedResultLua = fs.readFileSync(this.singleFilePathOut).toString();
36+
const updatedResultLua = fs.readFileSync(fileToChangeOut).toString();
3437

3538
Expect(initialResultLua).not.toEqual(updatedResultLua);
3639

37-
fs.writeFileSync(this.singleFilePath, originalTS);
40+
fs.writeFileSync(fileToChange, originalTS);
3841

39-
fs.unlinkSync(this.singleFilePathOut);
42+
fs.unlinkSync(fileToChangeOut);
4043

4144
child.kill();
4245
}
4346

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-
5047
private waitForFileExists(filepath: string, timeout: number = 3000): Promise<void> {
5148
const interval = 200;
5249
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)