proby 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/run.js +45 -3
- package/lib/worker.d.ts +2 -0
- package/lib/worker.js +29 -0
- package/package.json +5 -4
package/lib/run.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import assert from "@rcompat/assert";
|
|
1
2
|
import color from "@rcompat/cli/color";
|
|
2
3
|
import print from "@rcompat/cli/print";
|
|
3
4
|
import repository from "@rcompat/test/repository";
|
|
5
|
+
import { Worker } from "node:worker_threads";
|
|
4
6
|
const extensions = [".spec.ts", ".spec.js"];
|
|
5
7
|
const base_scalars = ["boolean", "number", "string", "symbol"];
|
|
6
8
|
function stringify_scalar(value) {
|
|
@@ -34,6 +36,42 @@ function stringify(value) {
|
|
|
34
36
|
}
|
|
35
37
|
return String(value);
|
|
36
38
|
}
|
|
39
|
+
async function run_in_worker(spec, env) {
|
|
40
|
+
const env_module = assert.shape((await import(env.path)).default, {
|
|
41
|
+
globals: "function",
|
|
42
|
+
setup: "function?",
|
|
43
|
+
teardown: "function?",
|
|
44
|
+
});
|
|
45
|
+
const context = await env_module.setup?.();
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const worker = new Worker(new URL("./worker.js", import.meta.url), {
|
|
48
|
+
workerData: {
|
|
49
|
+
spec: spec.path,
|
|
50
|
+
env: env.path,
|
|
51
|
+
context,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
worker.on("message", ({ results }) => {
|
|
55
|
+
const failed = results.filter((r) => !r.passed);
|
|
56
|
+
for (const result of results) {
|
|
57
|
+
print(result.passed ? color.green("o") : color.red("x"));
|
|
58
|
+
}
|
|
59
|
+
if (failed.length > 0) {
|
|
60
|
+
print("\n");
|
|
61
|
+
for (const result of failed) {
|
|
62
|
+
print(`${spec.debase(spec.directory)} ${color.red(result.name)}\n`);
|
|
63
|
+
print(` expected ${stringify(result.expected)}\n`);
|
|
64
|
+
print(` actual ${stringify(result.actual)}\n`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
worker.on("error", reject);
|
|
69
|
+
worker.on("exit", async () => {
|
|
70
|
+
await env_module.teardown?.(context);
|
|
71
|
+
resolve();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
37
75
|
export default async (root, subrepo) => {
|
|
38
76
|
const files = await root.list({
|
|
39
77
|
recursive: true,
|
|
@@ -41,13 +79,17 @@ export default async (root, subrepo) => {
|
|
|
41
79
|
});
|
|
42
80
|
if (files.length === 0)
|
|
43
81
|
return;
|
|
82
|
+
if (subrepo !== undefined)
|
|
83
|
+
print(`${color.blue(subrepo)}\n`);
|
|
44
84
|
for (const file of files) {
|
|
85
|
+
const env_file = await file.sibling(file.name.replace(/\.spec\.(ts|js)$/, ".env.ts")).or(() => null);
|
|
86
|
+
if (env_file !== null) {
|
|
87
|
+
await run_in_worker(file, env_file);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
45
90
|
repository.suite(file);
|
|
46
91
|
await file.import();
|
|
47
92
|
}
|
|
48
|
-
if (subrepo !== undefined) {
|
|
49
|
-
print(`${color.blue(subrepo)}\n`);
|
|
50
|
-
}
|
|
51
93
|
for (const suite of repository.next()) {
|
|
52
94
|
const failed = [];
|
|
53
95
|
for await (const test of suite.run()) {
|
package/lib/worker.d.ts
ADDED
package/lib/worker.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import assert from "@rcompat/assert";
|
|
2
|
+
import fs from "@rcompat/fs";
|
|
3
|
+
import repository from "@rcompat/test/repository";
|
|
4
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
5
|
+
const { spec, env, context } = workerData;
|
|
6
|
+
const env_module = assert.shape((await import(env)).default, {
|
|
7
|
+
globals: "function",
|
|
8
|
+
setup: "function?",
|
|
9
|
+
teardown: "function?",
|
|
10
|
+
});
|
|
11
|
+
Object.assign(globalThis, env_module.globals(context));
|
|
12
|
+
repository.suite(fs.ref(spec));
|
|
13
|
+
await import(spec);
|
|
14
|
+
const results = [];
|
|
15
|
+
for (const suite of repository.next()) {
|
|
16
|
+
for await (const test of suite.run()) {
|
|
17
|
+
for (const result of test.results) {
|
|
18
|
+
results.push({
|
|
19
|
+
name: test.name,
|
|
20
|
+
passed: result.passed,
|
|
21
|
+
expected: result.expected,
|
|
22
|
+
actual: result.actual,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
await suite.end();
|
|
27
|
+
}
|
|
28
|
+
parentPort.postMessage({ results });
|
|
29
|
+
//# sourceMappingURL=worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proby",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Standard library test runner",
|
|
5
5
|
"bugs": "https://github.com/rcompat/rcompat/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
"directory": "packages/proby"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@rcompat/
|
|
20
|
-
"@rcompat/fs": "^0.25.
|
|
19
|
+
"@rcompat/assert": "^0.6.1",
|
|
20
|
+
"@rcompat/fs": "^0.25.3",
|
|
21
|
+
"@rcompat/cli": "^0.15.0"
|
|
21
22
|
},
|
|
22
23
|
"peerDependencies": {
|
|
23
|
-
"@rcompat/test": "^0.
|
|
24
|
+
"@rcompat/test": "^0.9.0"
|
|
24
25
|
},
|
|
25
26
|
"peerDependenciesMeta": {
|
|
26
27
|
"@rcompat/test": {
|