proby 0.7.0 → 0.8.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 +33 -2
- package/lib/worker.d.ts +2 -0
- package/lib/worker.js +24 -0
- package/package.json +4 -4
package/lib/run.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import color from "@rcompat/cli/color";
|
|
2
2
|
import print from "@rcompat/cli/print";
|
|
3
3
|
import repository from "@rcompat/test/repository";
|
|
4
|
+
import { Worker } from "node:worker_threads";
|
|
4
5
|
const extensions = [".spec.ts", ".spec.js"];
|
|
5
6
|
const base_scalars = ["boolean", "number", "string", "symbol"];
|
|
6
7
|
function stringify_scalar(value) {
|
|
@@ -34,6 +35,32 @@ function stringify(value) {
|
|
|
34
35
|
}
|
|
35
36
|
return String(value);
|
|
36
37
|
}
|
|
38
|
+
async function run_in_worker(spec, env) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const worker = new Worker(new URL("./worker.js", import.meta.url), {
|
|
41
|
+
workerData: {
|
|
42
|
+
spec: spec.path,
|
|
43
|
+
env: env.path,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
worker.on("message", ({ results }) => {
|
|
47
|
+
const failed = results.filter((r) => !r.passed);
|
|
48
|
+
for (const result of results) {
|
|
49
|
+
print(result.passed ? color.green("o") : color.red("x"));
|
|
50
|
+
}
|
|
51
|
+
if (failed.length > 0) {
|
|
52
|
+
print("\n");
|
|
53
|
+
for (const result of failed) {
|
|
54
|
+
print(`${spec.debase(spec.directory)} ${color.red(result.name)}\n`);
|
|
55
|
+
print(` expected ${stringify(result.expected)}\n`);
|
|
56
|
+
print(` actual ${stringify(result.actual)}\n`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
worker.on("error", reject);
|
|
61
|
+
worker.on("exit", resolve);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
37
64
|
export default async (root, subrepo) => {
|
|
38
65
|
const files = await root.list({
|
|
39
66
|
recursive: true,
|
|
@@ -42,12 +69,16 @@ export default async (root, subrepo) => {
|
|
|
42
69
|
if (files.length === 0)
|
|
43
70
|
return;
|
|
44
71
|
for (const file of files) {
|
|
72
|
+
const env_file = await file.sibling(file.name.replace(/\.spec\.(ts|js)$/, ".env.ts")).or(() => null);
|
|
73
|
+
if (env_file !== null) {
|
|
74
|
+
await run_in_worker(file, env_file);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
45
77
|
repository.suite(file);
|
|
46
78
|
await file.import();
|
|
47
79
|
}
|
|
48
|
-
if (subrepo !== undefined)
|
|
80
|
+
if (subrepo !== undefined)
|
|
49
81
|
print(`${color.blue(subrepo)}\n`);
|
|
50
|
-
}
|
|
51
82
|
for (const suite of repository.next()) {
|
|
52
83
|
const failed = [];
|
|
53
84
|
for await (const test of suite.run()) {
|
package/lib/worker.d.ts
ADDED
package/lib/worker.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from "@rcompat/fs";
|
|
2
|
+
import repository from "@rcompat/test/repository";
|
|
3
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
4
|
+
const { spec, env } = workerData;
|
|
5
|
+
const env_module = await import(env);
|
|
6
|
+
Object.assign(globalThis, env_module.default);
|
|
7
|
+
repository.suite(fs.ref(spec));
|
|
8
|
+
await import(spec);
|
|
9
|
+
const results = [];
|
|
10
|
+
for (const suite of repository.next()) {
|
|
11
|
+
for await (const test of suite.run()) {
|
|
12
|
+
for (const result of test.results) {
|
|
13
|
+
results.push({
|
|
14
|
+
name: test.name,
|
|
15
|
+
passed: result.passed,
|
|
16
|
+
expected: result.expected,
|
|
17
|
+
actual: result.actual,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
await suite.end();
|
|
22
|
+
}
|
|
23
|
+
parentPort.postMessage({ results });
|
|
24
|
+
//# sourceMappingURL=worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proby",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Standard library test runner",
|
|
5
5
|
"bugs": "https://github.com/rcompat/rcompat/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"directory": "packages/proby"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@rcompat/cli": "^0.
|
|
20
|
-
"@rcompat/fs": "^0.25.
|
|
19
|
+
"@rcompat/cli": "^0.15.0",
|
|
20
|
+
"@rcompat/fs": "^0.25.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@rcompat/test": "^0.8.
|
|
23
|
+
"@rcompat/test": "^0.8.3"
|
|
24
24
|
},
|
|
25
25
|
"peerDependenciesMeta": {
|
|
26
26
|
"@rcompat/test": {
|