proby 0.8.0 → 0.10.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 CHANGED
@@ -1,3 +1,4 @@
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";
@@ -36,11 +37,18 @@ function stringify(value) {
36
37
  return String(value);
37
38
  }
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?.();
39
46
  return new Promise((resolve, reject) => {
40
47
  const worker = new Worker(new URL("./worker.js", import.meta.url), {
41
48
  workerData: {
42
49
  spec: spec.path,
43
50
  env: env.path,
51
+ context,
44
52
  },
45
53
  });
46
54
  worker.on("message", ({ results }) => {
@@ -58,7 +66,10 @@ async function run_in_worker(spec, env) {
58
66
  }
59
67
  });
60
68
  worker.on("error", reject);
61
- worker.on("exit", resolve);
69
+ worker.on("exit", async () => {
70
+ await env_module.teardown?.(context);
71
+ resolve();
72
+ });
62
73
  });
63
74
  }
64
75
  export default async (root, subrepo) => {
@@ -68,6 +79,8 @@ export default async (root, subrepo) => {
68
79
  });
69
80
  if (files.length === 0)
70
81
  return;
82
+ if (subrepo !== undefined)
83
+ print(`${color.blue(subrepo)}\n`);
71
84
  for (const file of files) {
72
85
  const env_file = await file.sibling(file.name.replace(/\.spec\.(ts|js)$/, ".env.ts")).or(() => null);
73
86
  if (env_file !== null) {
@@ -77,8 +90,6 @@ export default async (root, subrepo) => {
77
90
  repository.suite(file);
78
91
  await file.import();
79
92
  }
80
- if (subrepo !== undefined)
81
- print(`${color.blue(subrepo)}\n`);
82
93
  for (const suite of repository.next()) {
83
94
  const failed = [];
84
95
  for await (const test of suite.run()) {
package/lib/worker.js CHANGED
@@ -1,9 +1,14 @@
1
+ import assert from "@rcompat/assert";
1
2
  import fs from "@rcompat/fs";
2
3
  import repository from "@rcompat/test/repository";
3
4
  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);
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));
7
12
  repository.suite(fs.ref(spec));
8
13
  await import(spec);
9
14
  const results = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proby",
3
- "version": "0.8.0",
3
+ "version": "0.10.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/cli": "^0.15.0",
20
- "@rcompat/fs": "^0.25.3"
19
+ "@rcompat/assert": "^0.6.1",
20
+ "@rcompat/cli": "^0.16.0",
21
+ "@rcompat/fs": "^0.26.0"
21
22
  },
22
23
  "peerDependencies": {
23
- "@rcompat/test": "^0.8.3"
24
+ "@rcompat/test": "^0.10.0"
24
25
  },
25
26
  "peerDependenciesMeta": {
26
27
  "@rcompat/test": {