-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathgo-test.js
More file actions
49 lines (43 loc) · 1.51 KB
/
Copy pathgo-test.js
File metadata and controls
49 lines (43 loc) · 1.51 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
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
// Runs `go test ./...` under every directory below test/local/ that contains
// `_test.go` files. Assumes the tsp-spector mock server is already running;
// use `pnpm spector --start`/`--stop` (see spector.js) to manage it.
import { spawnSync } from "child_process";
import { existsSync, readdirSync, statSync } from "fs";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const pkgRoot = resolve(scriptDir, "..");
const testLocal = resolve(pkgRoot, "test", "local");
function findTestDirs(root) {
const dirs = new Set();
if (!existsSync(root)) return [];
const walk = (dir) => {
for (const entry of readdirSync(dir)) {
const p = resolve(dir, entry);
if (statSync(p).isDirectory()) walk(p);
else if (entry.endsWith("_test.go")) dirs.add(dir);
}
};
walk(root);
return [...dirs].sort();
}
const dirs = findTestDirs(testLocal);
console.log(`Discovered ${dirs.length} go test directories under ${testLocal}`);
let failed = false;
for (const dir of dirs) {
console.log(`\n=== go test ./... in ${dir} ===`);
const result = spawnSync("go", ["test", "-run", "^Test", "-v", "./..."], {
cwd: dir,
stdio: "inherit",
});
if (result.status !== 0) {
console.error(`go test failed in ${dir}`);
failed = true;
}
}
if (failed) {
process.exit(1);
}