-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-tests.ts
33 lines (28 loc) · 1005 Bytes
/
run-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Inspired by https://github.com/olov/ng-annotate/blob/c45120972445ba5027ba96688a7ef175a7a83338/run-tests.js
import * as diff from "diff";
import { readFileSync } from "fs";
import * as glob from "glob";
import * as ts from "typescript";
import { runNgAnnotate } from "./ts-ng-annotate-main";
function test(fileNames: string[]): void {
runNgAnnotate(fileNames, {}, (fileName, actual) => {
const expected = readFileSync(getExpectedFileName(fileName)).toString();
if (expected !== actual) {
const patch = diff.createPatch(fileName, expected, actual);
process.stderr.write(patch);
process.exit(-1);
}
});
}
function getExpectedFileName(fileName: string) {
if (/\.annotated\.ts$/.test(fileName)) {
return fileName;
} else {
return fileName.slice(0, -3) + ".annotated.ts";
}
}
function main(): void {
test(glob.sync("./tests/!(*.annotated).ts"));
test(glob.sync("./tests/*.annotated.ts"));
}
main();