-
-
Notifications
You must be signed in to change notification settings - Fork 688
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (66 loc) · 2.02 KB
/
index.js
File metadata and controls
75 lines (66 loc) · 2.02 KB
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
import path from "path";
import fs from "fs";
import { createRequire } from "module";
import asc from "../../dist/asc.js";
import loader from "../../lib/loader/index.js";
const require = createRequire(import.meta.url);
const args = process.argv.slice(2);
/** @type {Uint8Array} */
let binary;
const { error, stderr } = await asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--exportStart", "_start", ...args], {
writeFile(name, contents) {
if (name === "output.wasm") {
binary = contents;
} else if (name !== "output.wasm.map") {
throw Error("Unexpected output file: " + name);
}
}
});
if (error) {
console.error(error);
console.error(stderr.toString());
process.exit(1);
}
const jsonPath = path.join(process.cwd(), "expected.json");
const stderrString = stderr.toString();
if (fs.existsSync(jsonPath) && stderrString) {
const actualRes = JSON.parse(stderrString);
const actual = actualRes.options;
const expected = require(jsonPath).options;
let errored = false;
for (let name of Object.getOwnPropertyNames(expected)) {
if (actual[name] !== expected[name]) {
// If object check just first level
if (typeof actual[name] === 'object' && typeof expected[name] === 'object') {
let error = false;
for (let field of Object.getOwnPropertyNames(actual[name])) {
if (actual[name][field] !== expected[name][field]) {
error = true;
break;
}
}
if (!error) {
continue;
}
}
console.error(name + ": " + actual[name] + " expected " + expected[name]);
errored = true;
}
}
if (errored) {
process.exit(1);
}
process.exit(0);
}
if (!binary) {
console.error("No binary was generated for the asconfig test in " + process.cwd());
process.exit(1);
}
const theModule = loader.instantiateSync(binary);
try {
theModule.exports._start();
} catch (err) {
console.error("The wasm module _start() function failed in " + process.cwd());
console.error(err);
process.exit(1);
}