-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (49 loc) · 1.7 KB
/
index.js
File metadata and controls
56 lines (49 loc) · 1.7 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
50
51
52
53
54
55
56
import { readdirSync } from "node:fs";
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { snapshot, test } from "node:test";
const execFileAsync = promisify(execFile);
// Serialize strings as-is so multiline output is human-readable in snapshots
snapshot.setDefaultSnapshotSerializers([
(value) => (typeof value === "string" ? value : undefined),
]);
// Get all files in tests directory
const files = readdirSync("tests");
// Files to ignore
const ignore = ["index.js", "index.js.snapshot", "main.js", "README.md"];
const testFiles = files.filter((file) => !ignore.includes(file)).sort();
// Throw an error if there is a file that does not end with test.js in the tests directory
for (const file of testFiles) {
if (!file.endsWith(".test.js")) {
throw new Error(`File ${file} does not end with .test.js`);
}
test(file, async (t) => {
// Override Actions environment variables that change `core`’s behavior
const {
GITHUB_OUTPUT,
GITHUB_STATE,
HTTP_PROXY,
HTTPS_PROXY,
http_proxy,
https_proxy,
NO_PROXY,
no_proxy,
NODE_OPTIONS,
NODE_USE_ENV_PROXY,
...env
} = process.env;
const { stderr, stdout } = await execFileAsync("node", [`tests/${file}`], {
env,
});
const trimmedStderr = stderr.replace(/\r?\n$/, "");
const trimmedStdout = stdout.replace(/\r?\n$/, "");
await t.test("stderr", (t) => {
if (trimmedStderr) t.assert.snapshot(trimmedStderr);
else t.assert.strictEqual(trimmedStderr, "");
});
await t.test("stdout", (t) => {
if (trimmedStdout) t.assert.snapshot(trimmedStdout);
else t.assert.strictEqual(trimmedStdout, "");
});
});
}