-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathtest.mts
More file actions
42 lines (37 loc) · 1.06 KB
/
test.mts
File metadata and controls
42 lines (37 loc) · 1.06 KB
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
34
35
36
37
38
39
40
41
42
import { spawnSync } from "node:child_process";
type Language = "ruby" | "typescript";
function isTypeScript(file: string): boolean {
return file.endsWith(".mts") || file.endsWith(".ts");
}
function getTarget(files: string[]): Language | undefined {
if (files.some((file) => file.endsWith(".rb"))) {
return "ruby";
} else if (files.some(isTypeScript)) {
return "typescript";
} else {
return undefined;
}
}
function testWith(command: string, args: string[]): void {
const result = spawnSync(command, args, { stdio: "inherit" });
process.exitCode = result.status ?? 1;
}
const input = process.argv.slice(2);
switch (getTarget(input)) {
case "ruby":
testWith("bundle", ["exec", "ruby", "-Ilib:test", ...input]);
break;
case "typescript":
testWith(process.argv0, [
"--no-warnings",
"--test",
"--experimental-test-coverage",
"--test-coverage-exclude=test/**/*.ts",
...input,
]);
break;
default:
console.error(`Unable to determine test target: [${input}]`);
process.exitCode = 1;
break;
}