waforth/test-web.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-04-14 08:53:53 +02:00
#!/usr/bin/env node
/* eslint-env node */
2022-07-06 19:33:18 +02:00
/* eslint @typescript-eslint/no-var-requires:0 */
2022-04-14 08:53:53 +02:00
const esbuild = require("esbuild");
const path = require("path");
const { wasmTextPlugin } = require("./scripts/esbuild/wasm-text");
const Mocha = require("mocha");
let watch = false;
for (const arg of process.argv.slice(2)) {
switch (arg) {
case "--watch":
watch = true;
break;
}
}
function runTests() {
const mocha = new Mocha();
delete require.cache[path.join(__dirname, "build", "tests.js")];
mocha.addFile("build/tests.js");
mocha.run((failures) => (process.exitCode = failures ? 1 : 0));
}
let buildConfig = {
bundle: true,
logLevel: "warning",
2022-04-17 09:28:53 +02:00
entryPoints: [path.join(__dirname, "src", "web", "tests", "tests.node")],
2022-04-14 08:53:53 +02:00
target: "node17",
outdir: path.join(__dirname, "build"),
external: ["fs", "stream", "util", "events", "path"],
minify: false,
loader: {
".wasm": "binary",
".f": "text",
2022-05-27 19:43:34 +02:00
".fr": "text",
".fth": "text",
2022-04-14 08:53:53 +02:00
},
sourcemap: true,
plugins: [wasmTextPlugin({ debug: true })],
2022-04-14 08:53:53 +02:00
...(watch
? {
watch: {
2022-04-14 18:20:09 +02:00
async onRebuild(error) {
2022-04-14 08:53:53 +02:00
if (error) {
console.error(error);
} else {
runTests();
}
},
},
}
: {}),
};
esbuild.build(buildConfig).then(runTests, (e) => {
console.error(e);
process.exit(1);
});