proby 0.16.1 → 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.
- package/lib/Schema.js +5 -4
- package/lib/bin.js +1 -16
- package/lib/run.js +35 -36
- package/package.json +10 -10
package/lib/Schema.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import is from "@rcompat/is";
|
|
1
2
|
const defaults = {
|
|
2
3
|
monorepo: false,
|
|
3
4
|
packages: "packages",
|
|
4
|
-
include: ["src"],
|
|
5
|
+
include: ["src", "test"],
|
|
5
6
|
};
|
|
6
7
|
export default {
|
|
7
8
|
parse(input = {}) {
|
|
8
9
|
return {
|
|
9
|
-
monorepo:
|
|
10
|
-
packages:
|
|
11
|
-
include:
|
|
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/bin.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import Schema from "#Schema";
|
|
3
3
|
import env from "@rcompat/env";
|
|
4
|
-
import fs from "@rcompat/fs";
|
|
5
4
|
import io from "@rcompat/io";
|
|
6
5
|
import is from "@rcompat/is";
|
|
7
6
|
import runtime from "@rcompat/runtime";
|
|
8
|
-
async function read_conditions(file) {
|
|
9
|
-
const json = await file.json();
|
|
10
|
-
if (json.compilerOptions?.customConditions?.length) {
|
|
11
|
-
return json.compilerOptions.customConditions;
|
|
12
|
-
}
|
|
13
|
-
if (json.extends === undefined) {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
const next = runtime.resolve(json.extends, file.directory.path);
|
|
17
|
-
return read_conditions(fs.ref(next));
|
|
18
|
-
}
|
|
19
7
|
const root = await runtime.projectRoot();
|
|
20
8
|
const ts_config_file = root.join("proby.config.ts");
|
|
21
9
|
const js_config_file = root.join("proby.config.js");
|
|
@@ -25,10 +13,7 @@ const user_config = await ts_config_file.exists()
|
|
|
25
13
|
? (await js_config_file.import("default"))
|
|
26
14
|
: {};
|
|
27
15
|
const { include, packages, monorepo } = Schema.parse(user_config);
|
|
28
|
-
const
|
|
29
|
-
const conditions = await ts_config.exists()
|
|
30
|
-
? await read_conditions(ts_config)
|
|
31
|
-
: [];
|
|
16
|
+
const conditions = await runtime.conditions(root);
|
|
32
17
|
const conditions_flags = conditions
|
|
33
18
|
.map(c => ` --conditions="${c}"`)
|
|
34
19
|
.join("");
|
package/lib/run.js
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import assert from "@rcompat/assert";
|
|
2
|
-
import
|
|
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(
|
|
10
|
-
if (
|
|
9
|
+
function stringify_scalar(x) {
|
|
10
|
+
if (is.null(x))
|
|
11
11
|
return "null";
|
|
12
|
-
if (
|
|
12
|
+
if (is.undefined(x))
|
|
13
13
|
return "undefined";
|
|
14
|
-
const type = typeof
|
|
14
|
+
const type = typeof x;
|
|
15
15
|
if (base_scalars.includes(type))
|
|
16
|
-
return
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
19
|
-
if (
|
|
20
|
-
return `[Function${
|
|
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(
|
|
24
|
-
const scalar = stringify_scalar(
|
|
25
|
-
if (scalar
|
|
22
|
+
function stringify(x) {
|
|
23
|
+
const scalar = stringify_scalar(x);
|
|
24
|
+
if (is.defined(scalar))
|
|
26
25
|
return scalar;
|
|
27
|
-
if (
|
|
26
|
+
if (is.object(x)) {
|
|
28
27
|
try {
|
|
29
|
-
return JSON.stringify(
|
|
28
|
+
return JSON.stringify(x, (_, sub) => {
|
|
30
29
|
const s = stringify_scalar(sub);
|
|
31
|
-
return s
|
|
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(
|
|
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 ?
|
|
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)} ${
|
|
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
|
|
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
|
|
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
|
|
93
|
-
print(`${
|
|
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
|
|
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(
|
|
112
|
+
cli.print(cli.fg.green("o"));
|
|
114
113
|
}
|
|
115
114
|
else {
|
|
116
115
|
failed.push([test, result]);
|
|
117
|
-
print(
|
|
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)} ${
|
|
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.
|
|
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.
|
|
20
|
-
"@rcompat/
|
|
21
|
-
"@rcompat/
|
|
22
|
-
"@rcompat/fs": "^0.
|
|
23
|
-
"@rcompat/io": "^0.
|
|
24
|
-
"@rcompat/
|
|
25
|
-
"@rcompat/
|
|
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.
|
|
28
|
+
"@rcompat/type": "^0.16.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@rcompat/test": "^0.
|
|
31
|
+
"@rcompat/test": "^0.16.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
34
34
|
"@rcompat/test": {
|