proby 0.6.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/bin.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import color from "@rcompat/cli/color";
3
3
  import print from "@rcompat/cli/print";
4
- import root from "@rcompat/fs/project/root";
4
+ import fs from "@rcompat/fs";
5
5
  import run from "./run.js";
6
- const $root = await root();
7
- const spec_json = $root.join("spec.json");
6
+ const root = await fs.project.root();
7
+ const spec_json = root.join("spec.json");
8
8
  if (await spec_json.exists()) {
9
9
  // console.log(`spec.json exists, reading`);
10
10
  }
@@ -18,14 +18,16 @@ const type = await (async (base) => {
18
18
  if (await base.join("src").exists()) {
19
19
  return "repo";
20
20
  }
21
- })($root);
21
+ })(root);
22
22
  if (type === "monorepo") {
23
- for (const repo of await $root.join("packages").list()) {
23
+ for (const repo of await root.join("packages").list({
24
+ filter: info => info.kind === "directory",
25
+ })) {
24
26
  await run(repo.join("src"), repo.name);
25
27
  }
26
28
  }
27
29
  else if (type === "repo") {
28
- await run($root.join("src"));
30
+ await run(root.join("src"));
29
31
  }
30
32
  else {
31
33
  print(`${color.red("src")} or ${color.red("packages")} not found\n`);
package/lib/run.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type FileRef from "@rcompat/fs/FileRef";
1
+ import type { FileRef } from "@rcompat/fs";
2
2
  declare const _default: (root: FileRef, subrepo?: string) => Promise<void>;
3
3
  export default _default;
4
4
  //# sourceMappingURL=run.d.ts.map
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,20 +35,50 @@ 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,
40
- filter: file => extensions.some(extension => file.path.endsWith(extension)),
67
+ filter: info => extensions.some(extension => info.path.endsWith(extension)),
41
68
  });
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()) {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=worker.d.ts.map
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.6.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.13.0",
20
- "@rcompat/fs": "^0.24.0"
19
+ "@rcompat/cli": "^0.15.0",
20
+ "@rcompat/fs": "^0.25.3"
21
21
  },
22
22
  "peerDependencies": {
23
- "@rcompat/test": "^0.7.0"
23
+ "@rcompat/test": "^0.8.3"
24
24
  },
25
25
  "peerDependenciesMeta": {
26
26
  "@rcompat/test": {