-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
retest.mjs
executable file
·80 lines (63 loc) · 1.99 KB
/
retest.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
import path from "path";
import fs from "fs";
import { JSDOM } from "jsdom";
import { pathToFileURL } from "url";
import { glob } from "glob";
let args = process.argv.slice(2);
let options = {
"--with-dom": "--with-dom",
};
let allowedSuffixes = [".res.js", ".res.mjs", ".bs.js", ".js", ".mjs", ".cjs"];
let firstFile = args.filter((item) => !options[item])[0];
let buildsOutOfSource =
firstFile.startsWith("lib/") || firstFile.startsWith("./lib/");
let outputDirectoryRegExp = /^(\.\/)?lib\/(\w+?)\//;
let suffix = allowedSuffixes.find((suffix) => firstFile.endsWith(suffix));
let outputDirectoryPrefix;
if (buildsOutOfSource) {
let match = firstFile.match(outputDirectoryRegExp);
if (match) {
outputDirectoryPrefix = "/lib/" + match[2];
} else {
outputDirectoryPrefix = "";
}
} else {
outputDirectoryPrefix = "";
}
if (suffix == null) {
console.error("Unsupported file extension");
process.exit(1);
}
let { autoBoot, runTests } = await import(
`..${outputDirectoryPrefix}/src/Test${suffix}`
);
autoBoot.contents = false;
if (args.includes(options["--with-dom"])) {
var jsdom = new JSDOM("<!DOCTYPE html>", {
url: "about://blank",
});
Object.defineProperties(
globalThis,
Object.fromEntries(
Object.entries(Object.getOwnPropertyDescriptors(jsdom.window)).filter(
([key, _value]) => !globalThis.hasOwnProperty(key)
)
)
);
globalThis.jsdom = jsdom;
}
if (fs.existsSync(path.join(process.cwd(), "retest.env.js"))) {
await import(pathToFileURL(path.join(process.cwd(), "retest.env.js")).href);
}
let globsOrNames = args.filter((item) => !options[item]);
if (globsOrNames.some((item) => item.includes("*"))) {
globsOrNames = await Promise.all(
globsOrNames.map((globOrName) => glob(globOrName))
).then((arrays) => [...new Set([].concat(...arrays))]);
}
let modules = globsOrNames.map(
(file) => pathToFileURL(path.resolve(process.cwd(), file)).href
);
await Promise.all(modules.map((item) => import(item)));
runTests();