as-test 0.2.1 → 0.3.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/.github/workflows/as-test.yml +3 -0
- package/CHANGELOG.md +1 -1
- package/README.md +73 -68
- package/as-test.config.json +7 -10
- package/assembly/__tests__/array.spec.ts +19 -0
- package/assembly/__tests__/math.spec.ts +16 -0
- package/assembly/__tests__/sleep.spec.ts +28 -0
- package/assembly/index.ts +181 -165
- package/assembly/src/expectation.ts +119 -112
- package/assembly/src/log.ts +19 -0
- package/assembly/src/suite.ts +99 -0
- package/assembly/src/tests.ts +10 -0
- package/assembly/tsconfig.json +1 -1
- package/assembly/util/helpers.ts +0 -33
- package/assembly/util/term.ts +55 -0
- package/assets/img/download.png +0 -0
- package/bin/about.js +135 -0
- package/bin/build.js +72 -131
- package/bin/index.js +70 -112
- package/bin/init.js +211 -39
- package/bin/reporter.js +1 -0
- package/bin/run.js +226 -68
- package/bin/types.js +25 -31
- package/bin/util.js +44 -20
- package/cli/build.ts +70 -109
- package/cli/index.ts +148 -159
- package/cli/init.ts +235 -34
- package/cli/reporter.ts +1 -0
- package/cli/run.ts +266 -57
- package/cli/types.ts +6 -11
- package/cli/util.ts +35 -0
- package/package.json +6 -2
- package/run/package.json +27 -0
- package/tests/array.run.js +7 -0
- package/tests/math.run.js +7 -0
- package/tests/sleep.run.js +7 -0
- package/transform/lib/coverage.js +325 -319
- package/transform/lib/index.js +51 -31
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/mock.js +60 -52
- package/transform/lib/mock.js.map +1 -1
- package/transform/package.json +1 -1
- package/transform/src/index.ts +22 -3
- package/transform/src/mock.ts +1 -1
- package/asconfig.json +0 -31
- package/assembly/__tests__/example.spec.ts +0 -79
- package/assembly/reporters/tap.ts +0 -30
- package/assembly/src/group.ts +0 -44
- package/assembly/src/node.ts +0 -13
- package/test.config.json +0 -0
- package/tests/test.tap +0 -14
- package/unision +0 -38
- package/unision.pub +0 -1
- package/utils.ts +0 -1
package/bin/init.js
CHANGED
|
@@ -1,44 +1,216 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { existsSync, writeFileSync } from "fs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { createInterface } from "readline";
|
|
5
|
-
import {
|
|
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
|
-
|
|
5
|
+
import { loadConfig } from "./util.js";
|
|
6
|
+
const TARGETS = ["wasi", "bindings"];
|
|
7
|
+
export async function init(args) {
|
|
8
|
+
const rl = createInterface({
|
|
9
|
+
input: process.stdin,
|
|
10
|
+
output: process.stdout,
|
|
11
|
+
});
|
|
12
|
+
console.log(chalk.bold("as-test init v0.3.0") + "\n");
|
|
13
|
+
console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
|
|
14
|
+
const target = await ask(chalk.dim(" -> "), rl);
|
|
15
|
+
if (!TARGETS.includes(target)) {
|
|
16
|
+
console.log("Invalid target " + target + ". Exiting.");
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
process.stdout.write(`\u001B[1A`);
|
|
20
|
+
process.stdout.write("\x1B[2K");
|
|
21
|
+
process.stdout.write("\x1B[0G");
|
|
22
|
+
console.log("\n" +
|
|
23
|
+
chalk.dim("[2/3]") +
|
|
24
|
+
" attempting to create the following files. Continue? [y/n]\n");
|
|
25
|
+
console.log(chalk.dim(` ├── 📂 assembly/
|
|
26
|
+
│ └── 📂 __tests__/
|
|
27
|
+
│ └── 🧪 example.spec.ts
|
|
28
|
+
├── 📂 build/
|
|
29
|
+
├── 📂 logs/
|
|
30
|
+
├── 📂 tests/
|
|
31
|
+
│ └── 📃 as-test.run.js
|
|
32
|
+
├── ⚙️ as-test.config.json
|
|
33
|
+
└── ⚙️ package.json\n`));
|
|
34
|
+
const cont = (await ask(chalk.dim(" -> "), rl)).toLowerCase().trim();
|
|
35
|
+
if (cont == "n" || cont == "no") {
|
|
36
|
+
console.log("Exiting.");
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
let config = loadConfig(path.join(process.cwd(), "./as-test.config.json"));
|
|
40
|
+
if (target == "wasi" && config.buildOptions.target != "wasi") {
|
|
41
|
+
config.buildOptions.target = "wasi";
|
|
42
|
+
config.runOptions.runtime.name = "wasmtime";
|
|
43
|
+
config.runOptions.runtime.run = "wasmtime <file>";
|
|
44
|
+
}
|
|
45
|
+
else if (target == "bindings" && config.buildOptions.target != "bindings") {
|
|
46
|
+
config.buildOptions.target = "bindings";
|
|
47
|
+
config.runOptions.runtime.name = "node";
|
|
48
|
+
config.runOptions.runtime.run = "node ./tests/<name>.run.js";
|
|
49
|
+
}
|
|
50
|
+
writeFile("./as-test.config.json", JSON.stringify(config, null, 2));
|
|
51
|
+
writeFile("./assembly/__tests__/example.spec.ts", `import {
|
|
52
|
+
describe,
|
|
53
|
+
expect,
|
|
54
|
+
test,
|
|
55
|
+
beforeAll,
|
|
56
|
+
afterAll,
|
|
57
|
+
mockFn,
|
|
58
|
+
log,
|
|
59
|
+
run,
|
|
60
|
+
it
|
|
61
|
+
} from "as-test";
|
|
62
|
+
|
|
63
|
+
beforeAll(() => {
|
|
64
|
+
log("Setting up test environment...");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
afterAll(() => {
|
|
68
|
+
log("Tearing down test environment...");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Mock/override the function console.log
|
|
72
|
+
mockFn<void>("console.log", (data: string): void => {
|
|
73
|
+
console.log("[MOCKED]: " + data + "\\n");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("Should sleep", () => {
|
|
77
|
+
test("1ms", () => {
|
|
78
|
+
const start = Date.now();
|
|
79
|
+
sleep(1);
|
|
80
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(1);
|
|
81
|
+
});
|
|
82
|
+
test("10ms", () => {
|
|
83
|
+
const start = Date.now();
|
|
84
|
+
sleep(10);
|
|
85
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(10);
|
|
86
|
+
});
|
|
87
|
+
test("1s", () => {
|
|
88
|
+
const start = Date.now();
|
|
89
|
+
sleep(1000);
|
|
90
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
|
|
91
|
+
});
|
|
92
|
+
test("5s", () => {
|
|
93
|
+
const start = Date.now();
|
|
94
|
+
log("Sleeping...");
|
|
95
|
+
sleep(5000);
|
|
96
|
+
log("Done!");
|
|
97
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(5000);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("Math operations", () => {
|
|
102
|
+
test("Addition", () => {
|
|
103
|
+
expect(1 + 2).toBe(3);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("Subtraction", () => {
|
|
107
|
+
expect(1 - 2).toBe(-1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("Comparison", () => {
|
|
111
|
+
expect(5).toBeGreaterThan(3);
|
|
112
|
+
expect(2).toBeLessThan(4);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("Type checking", () => {
|
|
116
|
+
expect("hello").toBeString();
|
|
117
|
+
expect(true).toBeBoolean();
|
|
118
|
+
expect(10.5).toBeNumber();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
let myArray: i32[] = [1, 2, 3];
|
|
123
|
+
|
|
124
|
+
describe("Array manipulation", () => {
|
|
125
|
+
test("Array length", () => {
|
|
126
|
+
expect(myArray).toHaveLength(3);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("Array inclusion", () => {
|
|
130
|
+
expect(myArray).toContain(2);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should be empty", () => { });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
run();
|
|
137
|
+
|
|
138
|
+
function sleep(ms: i64): void {
|
|
139
|
+
const target = Date.now() + ms;
|
|
140
|
+
while (target > Date.now()) { }
|
|
141
|
+
}`);
|
|
142
|
+
writeDir("./build/");
|
|
143
|
+
writeDir("./logs/");
|
|
144
|
+
if (target == "bindings") {
|
|
145
|
+
writeFile("./tests/example.run.js", `import { readFileSync } from "fs";
|
|
146
|
+
import { instantiate } from "../build/example.spec.js";
|
|
147
|
+
|
|
148
|
+
const binary = readFileSync("./build/example.spec.wasm");
|
|
149
|
+
const module = new WebAssembly.Module(binary);
|
|
150
|
+
|
|
151
|
+
const exports = instantiate(module, {});`);
|
|
152
|
+
}
|
|
153
|
+
const PKG_PATH = path.join(process.cwd(), "./package.json");
|
|
154
|
+
if (!hasDep(PKG_PATH, "assemblyscript")) {
|
|
155
|
+
console.log(chalk.dim("AssemblyScript is not included in dependencies.\nInstall it with " +
|
|
156
|
+
(process.env.npm_config_user_agent == "yarn"
|
|
157
|
+
? process.env.npm_config_user_agent + " add assemblyscript"
|
|
158
|
+
: process.env.npm_config_user_agent + " install assemblyscript")));
|
|
159
|
+
}
|
|
160
|
+
const pkg = JSON.parse(existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}");
|
|
161
|
+
if (!pkg["scripts"])
|
|
162
|
+
pkg["scripts"] = {};
|
|
163
|
+
if (pkg.scripts["test"])
|
|
164
|
+
process.exit(0);
|
|
165
|
+
if (!pkg.scripts["pretest"]) {
|
|
166
|
+
pkg.scripts["pretest"] = "as-test build";
|
|
167
|
+
pkg.scripts["test"] = "as-test run";
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
pkg.scripts["test"] = "as-test test";
|
|
171
|
+
}
|
|
172
|
+
if (!pkg["devDependencies"])
|
|
173
|
+
pkg["devDependencies"] = {};
|
|
174
|
+
if (!pkg["devDependencies"]["as-test"])
|
|
175
|
+
pkg["devDependencies"]["as-test"] = "^0.3.0";
|
|
176
|
+
if (target == "bindings") {
|
|
177
|
+
pkg["type"] = "module";
|
|
178
|
+
}
|
|
179
|
+
writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
|
|
42
180
|
process.exit(0);
|
|
43
|
-
|
|
181
|
+
}
|
|
182
|
+
function ask(question, face) {
|
|
183
|
+
return new Promise((res, _) => {
|
|
184
|
+
face.question(question, (answer) => {
|
|
185
|
+
res(answer);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function writeFile(pth, data) {
|
|
190
|
+
const fmtPath = path.join(process.cwd(), pth);
|
|
191
|
+
if (existsSync(fmtPath))
|
|
192
|
+
return;
|
|
193
|
+
if (!existsSync(path.dirname(fmtPath)))
|
|
194
|
+
mkdirSync(path.dirname(fmtPath), { recursive: true });
|
|
195
|
+
writeFileSync(fmtPath, data);
|
|
196
|
+
}
|
|
197
|
+
function writeDir(pth) {
|
|
198
|
+
const fmtPath = path.join(process.cwd(), pth);
|
|
199
|
+
if (existsSync(fmtPath))
|
|
200
|
+
return;
|
|
201
|
+
mkdirSync(fmtPath);
|
|
202
|
+
}
|
|
203
|
+
function hasDep(PKG_PATH, dep) {
|
|
204
|
+
const pkg = JSON.parse(existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}");
|
|
205
|
+
if (existsSync(path.join(process.cwd(), "./node_modules/", dep)))
|
|
206
|
+
return true;
|
|
207
|
+
if (pkg.dependencies &&
|
|
208
|
+
!Object.keys(pkg.dependencies).includes(dep) &&
|
|
209
|
+
pkg.devDependencies &&
|
|
210
|
+
!Object.keys(pkg.devDependencies).includes(dep) &&
|
|
211
|
+
pkg.peerDependencies &&
|
|
212
|
+
!Object.keys(pkg.peerDependencies).includes(dep)) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
44
216
|
}
|
package/bin/reporter.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function report() { }
|
package/bin/run.js
CHANGED
|
@@ -1,73 +1,231 @@
|
|
|
1
|
-
import { existsSync, readFileSync, readdirSync } from "fs";
|
|
2
|
-
import { Config } from "./types.js";
|
|
3
1
|
import chalk from "chalk";
|
|
4
2
|
import { exec } from "child_process";
|
|
5
3
|
import { glob } from "glob";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { formatTime, getExec, loadConfig } from "./util.js";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
7
|
+
import { diff } from "typer-diff";
|
|
8
|
+
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
10
9
|
export async function run() {
|
|
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
|
-
config.
|
|
39
|
-
|
|
40
|
-
(config.
|
|
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
|
-
|
|
10
|
+
const reports = [];
|
|
11
|
+
const config = loadConfig(CONFIG_PATH);
|
|
12
|
+
const inputFiles = await glob(config.input);
|
|
13
|
+
console.log(chalk.dim("Running tests using " + config.runOptions.runtime.name + ""));
|
|
14
|
+
const command = config.runOptions.runtime.run.split(" ")[0];
|
|
15
|
+
let execPath = getExec(command);
|
|
16
|
+
if (!execPath) {
|
|
17
|
+
console.log(`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not locate ${command} in PATH variable!`);
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
if (inputFiles.length) {
|
|
21
|
+
console.log(chalk.bold.blueBright(` _____ _____ _____ _____ _____ _____ `));
|
|
22
|
+
console.log(chalk.bold.blueBright(`| _ || __| ___|_ _|| __|| __||_ _|`));
|
|
23
|
+
console.log(chalk.bold.blueBright(`| ||__ ||___| | | | __||__ | | | `));
|
|
24
|
+
console.log(chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `));
|
|
25
|
+
console.log(chalk.dim("\n------------------- v0.3.0 -------------------\n"));
|
|
26
|
+
}
|
|
27
|
+
for (const plugin of Object.keys(config.plugins)) {
|
|
28
|
+
if (!config.plugins[plugin])
|
|
29
|
+
continue;
|
|
30
|
+
console.log(chalk.bgBlueBright(" PLUGIN ") +
|
|
31
|
+
" " +
|
|
32
|
+
chalk.dim("Using " + plugin.slice(0, 1).toUpperCase() + plugin.slice(1)) +
|
|
33
|
+
"\n");
|
|
34
|
+
}
|
|
35
|
+
for (let i = 0; i < inputFiles.length; i++) {
|
|
36
|
+
const file = inputFiles[i];
|
|
37
|
+
const outFile = path.join(config.outDir, file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"));
|
|
38
|
+
let cmd = config.runOptions.runtime.run.replace(command, execPath);
|
|
39
|
+
if (config.buildOptions.target == "bindings") {
|
|
40
|
+
cmd = config.runOptions.runtime.run.replace(command, execPath);
|
|
41
|
+
if (cmd.includes("<name>")) {
|
|
42
|
+
cmd = cmd.replace("<name>", file
|
|
43
|
+
.slice(file.lastIndexOf("/") + 1)
|
|
44
|
+
.replace(".ts", "")
|
|
45
|
+
.replace(".spec", ""));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
cmd = cmd.replace("<file>", outFile
|
|
49
|
+
.replace("build", "tests")
|
|
50
|
+
.replace(".spec", "")
|
|
51
|
+
.replace(".wasm", ".run.js"));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
cmd = cmd.replace("<file>", outFile);
|
|
56
|
+
}
|
|
57
|
+
const report = JSON.parse(await (() => {
|
|
58
|
+
return new Promise((res, _) => {
|
|
59
|
+
let stdout = "";
|
|
60
|
+
const io = exec(cmd);
|
|
61
|
+
io.stdout.pipe(process.stdout);
|
|
62
|
+
io.stderr.pipe(process.stderr);
|
|
63
|
+
io.stdout.on("data", (data) => {
|
|
64
|
+
stdout += readData(data);
|
|
65
|
+
});
|
|
66
|
+
io.stdout.on("close", () => {
|
|
67
|
+
res(stdout);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
})());
|
|
71
|
+
reports.push(report);
|
|
72
|
+
}
|
|
73
|
+
if (config.logs && config.logs != "none") {
|
|
74
|
+
if (!existsSync(path.join(process.cwd(), config.logs))) {
|
|
75
|
+
mkdirSync(path.join(process.cwd(), config.logs));
|
|
76
|
+
}
|
|
77
|
+
writeFileSync(path.join(process.cwd(), config.logs, "test.log.json"), JSON.stringify(reports, null, 2));
|
|
78
|
+
}
|
|
79
|
+
const reporter = new Reporter(reports);
|
|
80
|
+
if (reporter.failed.length) {
|
|
81
|
+
console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
|
|
82
|
+
for (const failed of reporter.failed) {
|
|
83
|
+
console.log(`${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`);
|
|
84
|
+
for (const test of failed.tests) {
|
|
85
|
+
const diffResult = diff(JSON.stringify(test._left), JSON.stringify(test._right));
|
|
86
|
+
let expected = chalk.dim(JSON.stringify(test._left));
|
|
87
|
+
let received = "";
|
|
88
|
+
for (const res of diffResult.diff) {
|
|
89
|
+
switch (res.type) {
|
|
90
|
+
case "correct": {
|
|
91
|
+
received += chalk.dim(res.value);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
case "extra": {
|
|
95
|
+
received += chalk.red.strikethrough(res.value);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
case "missing": {
|
|
99
|
+
received += chalk.bgBlack(res.value);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
case "wrong": {
|
|
103
|
+
received += chalk.bgRed(res.value);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
case "untouched": {
|
|
107
|
+
//received += chalk.bgBlackBright(res.value);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
case "spacer": {
|
|
111
|
+
//received += chalk.bgBlackBright(res.value);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (test.verdict == "fail") {
|
|
117
|
+
console.log(`${chalk.dim("(expected) ->")} ${expected}`);
|
|
118
|
+
console.log(`${chalk.dim("(received) ->")} ${received}\n`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
console.log(chalk.dim("----------------- [RESULTS] ------------------\n"));
|
|
124
|
+
process.stdout.write(chalk.bold("Files: "));
|
|
125
|
+
if (reporter.failedFiles) {
|
|
126
|
+
process.stdout.write(chalk.bold.red(reporter.failedFiles + " failed"));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
process.stdout.write(chalk.bold.greenBright("0 failed"));
|
|
130
|
+
}
|
|
131
|
+
process.stdout.write(", " + (reporter.failedFiles + reporter.passedFiles) + " total\n");
|
|
132
|
+
process.stdout.write(chalk.bold("Suites: "));
|
|
133
|
+
if (reporter.failedSuites) {
|
|
134
|
+
process.stdout.write(chalk.bold.red(reporter.failedSuites + " failed"));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
process.stdout.write(chalk.bold.greenBright("0 failed"));
|
|
138
|
+
}
|
|
139
|
+
process.stdout.write(", " + (reporter.failedSuites + reporter.passedSuites) + " total\n");
|
|
140
|
+
process.stdout.write(chalk.bold("Tests: "));
|
|
141
|
+
if (reporter.failedTests) {
|
|
142
|
+
process.stdout.write(chalk.bold.red(reporter.failedTests + " failed"));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
process.stdout.write(chalk.bold.greenBright("0 failed"));
|
|
146
|
+
}
|
|
147
|
+
process.stdout.write(", " + (reporter.failedTests + reporter.passedTests) + " total\n");
|
|
148
|
+
process.stdout.write(chalk.bold("Time: ") + formatTime(reporter.time) + "\n");
|
|
149
|
+
if (reporter.failedFiles)
|
|
150
|
+
process.exit(1);
|
|
151
|
+
process.exit(0);
|
|
152
|
+
}
|
|
153
|
+
class Reporter {
|
|
154
|
+
constructor(reports) {
|
|
155
|
+
this.passedFiles = 0;
|
|
156
|
+
this.failedFiles = 0;
|
|
157
|
+
this.passedSuites = 0;
|
|
158
|
+
this.failedSuites = 0;
|
|
159
|
+
this.passedTests = 0;
|
|
160
|
+
this.failedTests = 0;
|
|
161
|
+
this.failed = [];
|
|
162
|
+
this.time = 0.0;
|
|
163
|
+
this.readReports(reports);
|
|
164
|
+
}
|
|
165
|
+
readReports(reports) {
|
|
166
|
+
for (const file of reports) {
|
|
167
|
+
this.readFile(file);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
readFile(file) {
|
|
171
|
+
let failed = false;
|
|
172
|
+
for (const suite of file) {
|
|
173
|
+
if (suite.verdict == "fail") {
|
|
174
|
+
failed = true;
|
|
175
|
+
this.failedSuites++;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.passedSuites++;
|
|
179
|
+
}
|
|
180
|
+
this.time += suite.time.end - suite.time.start;
|
|
181
|
+
for (const subSuite of suite.suites) {
|
|
182
|
+
this.readSuite(subSuite);
|
|
183
|
+
}
|
|
184
|
+
for (const test of suite.tests) {
|
|
185
|
+
if (test.verdict == "fail")
|
|
186
|
+
this.failed.push(suite);
|
|
187
|
+
this.readTest(test);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (failed)
|
|
191
|
+
this.failedFiles++;
|
|
192
|
+
else
|
|
193
|
+
this.passedFiles++;
|
|
194
|
+
}
|
|
195
|
+
readSuite(suite) {
|
|
196
|
+
if (suite.verdict == "fail") {
|
|
197
|
+
this.failedSuites++;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
this.passedSuites++;
|
|
201
|
+
}
|
|
202
|
+
this.time += suite.time.end - suite.time.start;
|
|
203
|
+
for (const subSuite of suite.suites) {
|
|
204
|
+
this.readSuite(subSuite);
|
|
205
|
+
}
|
|
206
|
+
for (const test of suite.tests) {
|
|
207
|
+
if (test.verdict == "fail")
|
|
208
|
+
this.failed.push(suite);
|
|
209
|
+
this.readTest(test);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
readTest(test) {
|
|
213
|
+
if (test.verdict == "fail") {
|
|
214
|
+
this.failedTests++;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
this.passedTests++;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function readData(data) {
|
|
222
|
+
let out = "";
|
|
223
|
+
const start = data.indexOf("READ_LINE");
|
|
224
|
+
if (start >= 0) {
|
|
225
|
+
const slice = data.slice(start + 9);
|
|
226
|
+
const end = slice.indexOf("END_LINE");
|
|
227
|
+
out += slice.slice(0, end);
|
|
228
|
+
out += readData(slice);
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
73
231
|
}
|
package/bin/types.js
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
export class Config {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
constructor() {
|
|
3
|
+
this.input = ["./assembly/__tests__/*.spec.ts"];
|
|
4
|
+
this.outDir = "./build";
|
|
5
|
+
this.logs = "./logs";
|
|
6
|
+
this.config = "none";
|
|
7
|
+
this.plugins = {
|
|
8
|
+
coverage: true,
|
|
9
|
+
};
|
|
10
|
+
this.buildOptions = new BuildOptions();
|
|
11
|
+
this.runOptions = new RunOptions();
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
export class Suite {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
export class Coverage {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.enabled = false;
|
|
20
|
-
this.show = false;
|
|
21
|
-
}
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = "";
|
|
17
|
+
}
|
|
22
18
|
}
|
|
23
19
|
export class BuildOptions {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.verbose = true;
|
|
29
|
-
}
|
|
20
|
+
constructor() {
|
|
21
|
+
this.args = [];
|
|
22
|
+
this.target = "wasi";
|
|
23
|
+
}
|
|
30
24
|
}
|
|
31
25
|
export class RunOptions {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
constructor() {
|
|
27
|
+
this.runtime = new Runtime();
|
|
28
|
+
}
|
|
35
29
|
}
|
|
36
30
|
export class Runtime {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
constructor() {
|
|
32
|
+
this.name = "wasmtime";
|
|
33
|
+
this.run = "wasmtime <file>";
|
|
34
|
+
}
|
|
41
35
|
}
|