as-test 0.2.1 → 0.3.1

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