proby 0.16.2 → 0.17.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.
Files changed (3) hide show
  1. package/lib/Schema.js +4 -3
  2. package/lib/run.js +35 -36
  3. package/package.json +10 -10
package/lib/Schema.js CHANGED
@@ -1,3 +1,4 @@
1
+ import is from "@rcompat/is";
1
2
  const defaults = {
2
3
  monorepo: false,
3
4
  packages: "packages",
@@ -6,9 +7,9 @@ const defaults = {
6
7
  export default {
7
8
  parse(input = {}) {
8
9
  return {
9
- monorepo: typeof input.monorepo === "boolean" ? input.monorepo : defaults.monorepo,
10
- packages: typeof input.packages === "string" ? input.packages : defaults.packages,
11
- include: Array.isArray(input.include) && input.include.every((x) => typeof x === "string")
10
+ monorepo: is.boolean(input.monorepo) ? input.monorepo : defaults.monorepo,
11
+ packages: is.string(input.packages) ? input.packages : defaults.packages,
12
+ include: is.array(input.include) && input.include.every(is.string)
12
13
  ? input.include
13
14
  : defaults.include,
14
15
  };
package/lib/run.js CHANGED
@@ -1,41 +1,40 @@
1
1
  import assert from "@rcompat/assert";
2
- import color from "@rcompat/cli/color";
3
- import print from "@rcompat/cli/print";
2
+ import cli from "@rcompat/cli";
4
3
  import fs from "@rcompat/fs";
4
+ import is from "@rcompat/is";
5
5
  import repository from "@rcompat/test/repository";
6
6
  import { Worker } from "node:worker_threads";
7
7
  const extensions = [".spec.ts", ".spec.js"];
8
8
  const base_scalars = ["boolean", "number", "string", "symbol"];
9
- function stringify_scalar(value) {
10
- if (value === null)
9
+ function stringify_scalar(x) {
10
+ if (is.null(x))
11
11
  return "null";
12
- if (value === undefined)
12
+ if (is.undefined(x))
13
13
  return "undefined";
14
- const type = typeof value;
14
+ const type = typeof x;
15
15
  if (base_scalars.includes(type))
16
- return value.toString();
17
- if (typeof value === "bigint")
18
- return value.toString() + "n";
19
- if (typeof value === "function") {
20
- return `[Function${value.name ? `: ${value.name}` : ""}]`;
21
- }
16
+ return x.toString();
17
+ if (is.bigint(x))
18
+ return x.toString() + "n";
19
+ if (is.function(x))
20
+ return `[Function${is.text(x.name) ? `: ${x.name}` : ""}]`;
22
21
  }
23
- function stringify(value) {
24
- const scalar = stringify_scalar(value);
25
- if (scalar !== undefined)
22
+ function stringify(x) {
23
+ const scalar = stringify_scalar(x);
24
+ if (is.defined(scalar))
26
25
  return scalar;
27
- if (typeof value === "object") {
26
+ if (is.object(x)) {
28
27
  try {
29
- return JSON.stringify(value, (_, sub) => {
28
+ return JSON.stringify(x, (_, sub) => {
30
29
  const s = stringify_scalar(sub);
31
- return s !== undefined ? s : sub;
30
+ return is.defined(s) ? s : sub;
32
31
  });
33
32
  }
34
33
  catch {
35
34
  return "[Object (circular or unserializable)]";
36
35
  }
37
36
  }
38
- return String(value);
37
+ return String(x);
39
38
  }
40
39
  async function run_in_worker(spec, env) {
41
40
  const env_module = assert.shape((await import(env.path)).default, {
@@ -56,14 +55,14 @@ async function run_in_worker(spec, env) {
56
55
  worker.on("message", ({ results }) => {
57
56
  const failed = results.filter((r) => !r.passed);
58
57
  for (const result of results) {
59
- print(result.passed ? color.green("o") : color.red("x"));
58
+ cli.print(result.passed ? cli.fg.green("o") : cli.fg.red("x"));
60
59
  }
61
60
  if (failed.length > 0) {
62
- print("\n");
61
+ cli.print("\n");
63
62
  for (const result of failed) {
64
- print(`${spec.debase(spec.directory)} ${color.red(result.name)}\n`);
65
- print(` expected ${stringify(result.expected)}\n`);
66
- print(` actual ${stringify(result.actual)}\n`);
63
+ cli.print(`${spec.debase(spec.directory)} ${cli.fg.red(result.name)}\n`);
64
+ cli.print(` expected ${stringify(result.expected)}\n`);
65
+ cli.print(` actual ${stringify(result.actual)}\n`);
67
66
  }
68
67
  }
69
68
  });
@@ -75,12 +74,12 @@ async function run_in_worker(spec, env) {
75
74
  });
76
75
  }
77
76
  export default async (root, subrepo, target, group) => {
78
- const resolved = target === undefined ? undefined : fs.resolve(target).path;
77
+ const resolved = is.defined(target) ? fs.resolve(target).path : undefined;
79
78
  const files = await root.list({
80
79
  recursive: true,
81
80
  filter: info => {
82
81
  const path = info.path;
83
- if (resolved === undefined)
82
+ if (is.undefined(resolved))
84
83
  return extensions.some(e => path.endsWith(e));
85
84
  if (extensions.some(e => resolved.endsWith(e)))
86
85
  return path.endsWith(resolved);
@@ -89,8 +88,8 @@ export default async (root, subrepo, target, group) => {
89
88
  });
90
89
  if (files.length === 0)
91
90
  return;
92
- if (subrepo !== undefined)
93
- print(`${color.blue(subrepo)}\n`);
91
+ if (is.defined(subrepo))
92
+ cli.print(`${cli.fg.blue(subrepo)}\n`);
94
93
  for (const file of files) {
95
94
  const env_file = await file.sibling(file.name.replace(/\.spec\.(ts|js)$/, ".env.ts")).or(() => null);
96
95
  if (env_file !== null) {
@@ -106,25 +105,25 @@ export default async (root, subrepo, target, group) => {
106
105
  await file.import();
107
106
  const failed = [];
108
107
  for await (const test of suite.run()) {
109
- if (group !== undefined && test.group !== group)
108
+ if (is.defined(group) && test.group !== group)
110
109
  continue;
111
110
  for (const result of test.results) {
112
111
  if (result.passed) {
113
- print(color.green("o"));
112
+ cli.print(cli.fg.green("o"));
114
113
  }
115
114
  else {
116
115
  failed.push([test, result]);
117
- print(color.red("x"));
116
+ cli.print(cli.fg.red("x"));
118
117
  }
119
118
  }
120
119
  }
121
120
  await suite.end();
122
121
  if (failed.length > 0) {
123
- print("\n");
122
+ cli.print("\n");
124
123
  for (const [test, result] of failed) {
125
- print(`${suite.file.debase(root)} ${color.red(test.name)} \n`);
126
- print(` expected ${stringify(result.expected)}\n`);
127
- print(` actual ${stringify(result.actual)}\n`);
124
+ cli.print(`${suite.file.debase(root)} ${cli.fg.red(test.name)} \n`);
125
+ cli.print(` expected ${stringify(result.expected)}\n`);
126
+ cli.print(` actual ${stringify(result.actual)}\n`);
128
127
  }
129
128
  }
130
129
  }
@@ -132,6 +131,6 @@ export default async (root, subrepo, target, group) => {
132
131
  repository.reset();
133
132
  }
134
133
  }
135
- print("\n");
134
+ cli.print("\n");
136
135
  };
137
136
  //# sourceMappingURL=run.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proby",
3
- "version": "0.16.2",
3
+ "version": "0.17.0",
4
4
  "description": "Standard library test runner",
5
5
  "bugs": "https://github.com/rcompat/rcompat/issues",
6
6
  "license": "MIT",
@@ -16,19 +16,19 @@
16
16
  "directory": "packages/proby"
17
17
  },
18
18
  "dependencies": {
19
- "@rcompat/assert": "^0.11.0",
20
- "@rcompat/cli": "^0.21.0",
21
- "@rcompat/env": "^0.20.1",
22
- "@rcompat/fs": "^0.31.0",
23
- "@rcompat/is": "^0.9.0",
24
- "@rcompat/io": "^0.8.0",
25
- "@rcompat/runtime": "^0.14.4"
19
+ "@rcompat/assert": "^0.12.0",
20
+ "@rcompat/env": "^0.21.0",
21
+ "@rcompat/cli": "^0.22.0",
22
+ "@rcompat/fs": "^0.32.0",
23
+ "@rcompat/io": "^0.9.0",
24
+ "@rcompat/is": "^0.10.0",
25
+ "@rcompat/runtime": "^0.15.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@rcompat/type": "^0.15.1"
28
+ "@rcompat/type": "^0.16.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@rcompat/test": "^0.15.0"
31
+ "@rcompat/test": "^0.16.0"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
34
  "@rcompat/test": {