as-test 0.0.5 → 0.0.8
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/CHANGELOG.md +8 -0
- package/README.md +29 -1
- package/assembly/index.ts +22 -5
- package/assembly/src/group.ts +19 -5
- package/package.json +3 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
v0.0.0 - Initial project setup
|
|
2
|
+
v0.0.1 - Updates to UI, some bug fixes
|
|
3
|
+
v0.0.2 - Diff between expected and recieved results
|
|
4
|
+
v0.0.3 - Added `afterEach`, `beforeEach`, `afterAll`, `beforeAll`, `test`, `it`, `.toBeGreaterThan`, `.toBeGreaterThanOrEqualTo`, ect..
|
|
5
|
+
v0.0.4 - Fix import issue in README usage section
|
|
6
|
+
v0.0.5 - Switch errors to be thrown at compile time instead of runtime
|
|
7
|
+
v0.0.6 - Failed tests should be pushed to bottom of logs
|
|
8
|
+
v0.0.8 - Fix readme typo in v0.0.7
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
| _ || __| ___|_ _|| __|| __||_ _|
|
|
4
4
|
| ||__ ||___| | | | __||__ | | |
|
|
5
5
|
|__|__||_____| |_| |_____||_____| |_|
|
|
6
|
-
v0.0.
|
|
6
|
+
v0.0.8
|
|
7
7
|
</pre>
|
|
8
8
|
</h5>
|
|
9
9
|
|
|
@@ -117,6 +117,34 @@ Time: 101.812μs
|
|
|
117
117
|
</pre>
|
|
118
118
|
</h6>
|
|
119
119
|
|
|
120
|
+
## Running
|
|
121
|
+
|
|
122
|
+
You can run as-test *anywhere* that WASI is supported! I've yet to add support for bindings, but all it needs is access to the terminal.
|
|
123
|
+
|
|
124
|
+
To add WASI support, install it with
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
npm install @assemblyscript/wasi-shim
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Add the following scripts to your `package.json` where NAME-HERE is your test file.
|
|
131
|
+
You can swap out `wasmtime` with [Node.js](https://nodejs.org/), [Wasmer](https://wasmer.io/), [Wasm3](https://github.com/wasm3/wasm3), or any WASI-supporting runtime
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
"scripts": {
|
|
135
|
+
"test": "wasmtime ./build/NAME.spec.wasm",
|
|
136
|
+
"pretest": "asc asc NAME.spec.ts -o build/NAME.spec.wasm --bindings esm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json"
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
And finally, run it with:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm run test
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
To add `as-test` to your CI/CD workflow, check out [The provided example](https://github.com/JairusSW/as-test/blob/main/.github/workflows/nodejs.yml)
|
|
147
|
+
|
|
120
148
|
If you use this project in your codebase, consider dropping a [⭐ HERE](https://github.com/JairusSW/as-test). I would really appreciate it!
|
|
121
149
|
|
|
122
150
|
## Notes
|
package/assembly/index.ts
CHANGED
|
@@ -214,11 +214,12 @@ export function run(options: RunOptions = new RunOptions()): void {
|
|
|
214
214
|
console.log(rainbow.boldMk(rainbow.green(`| _ || __| ___|_ _|| __|| __||_ _|`)));
|
|
215
215
|
console.log(rainbow.boldMk(rainbow.green(`| ||__ ||___| | | | __||__ | | | `)));
|
|
216
216
|
console.log(rainbow.boldMk(rainbow.green(`|__|__||_____| |_| |_____||_____| |_| `)));
|
|
217
|
-
console.log(rainbow.dimMk("\n
|
|
217
|
+
console.log(rainbow.dimMk ("\n------------------- v0.0.8 -------------------\n"));
|
|
218
218
|
const suites = groups.length;
|
|
219
219
|
let failed = 0;
|
|
220
220
|
let tests = 0;
|
|
221
221
|
let failed_tests = 0;
|
|
222
|
+
let failed_suite_logs = "";
|
|
222
223
|
const start = performance.now();
|
|
223
224
|
for (let i = 0; i < groups.length; i++) {
|
|
224
225
|
if (before_all_callback) before_all_callback();
|
|
@@ -241,17 +242,33 @@ export function run(options: RunOptions = new RunOptions()): void {
|
|
|
241
242
|
console.log(rainbow.bgGreenBright(" PASS ") + " " + rainbow.dimMk(suite.description) + "\n");
|
|
242
243
|
} else {
|
|
243
244
|
failed++;
|
|
244
|
-
|
|
245
|
+
const txt = rainbow.bgRed(" FAIL ") + " " + rainbow.dimMk(suite.description) + "\n";
|
|
246
|
+
failed_suite_logs += txt
|
|
247
|
+
console.log(txt);
|
|
245
248
|
}
|
|
246
249
|
|
|
247
250
|
const report = suite.report();
|
|
248
|
-
if (report)
|
|
251
|
+
if (report) {
|
|
252
|
+
if (report.passed) console.log(report.passed!);
|
|
253
|
+
if (report.failed) failed_suite_logs += report.failed!;
|
|
254
|
+
|
|
255
|
+
}
|
|
249
256
|
if (after_all_callback) after_all_callback();
|
|
250
257
|
}
|
|
258
|
+
|
|
259
|
+
if (failed) {
|
|
260
|
+
console.log(rainbow.red("------------------ [FAILED] ------------------\n"));
|
|
261
|
+
console.log(failed_suite_logs);
|
|
262
|
+
console.log(rainbow.red("----------------- [RESULTS] ------------------\n"));
|
|
263
|
+
} else {
|
|
264
|
+
console.log(rainbow.dimMk("----------------- [RESULTS] ------------------\n"));
|
|
265
|
+
}
|
|
251
266
|
const ms = performance.now() - start;
|
|
252
|
-
console.log(rainbow.dimMk("-----------------------------------------\n"));
|
|
253
267
|
console.log(rainbow.boldMk("Test Suites: ") + (failed ? rainbow.boldMk(rainbow.red(failed.toString() + " failed")) : rainbow.boldMk(rainbow.green(failed.toString() + " failed"))) + ", " + suites.toString() + " total");
|
|
254
268
|
console.log(rainbow.boldMk("Tests: ") + (failed_tests ? rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) : rainbow.boldMk(rainbow.green(failed_tests.toString() + " failed"))) + ", " + tests.toString() + " total");
|
|
255
269
|
console.log(rainbow.boldMk("Snapshots: ") + "0 total");
|
|
256
|
-
console.log(rainbow.boldMk("Time: ") + formatTime(ms))
|
|
270
|
+
console.log(rainbow.boldMk("Time: ") + formatTime(ms));
|
|
271
|
+
if (failed) {
|
|
272
|
+
process.exit(1)
|
|
273
|
+
}
|
|
257
274
|
}
|
package/assembly/src/group.ts
CHANGED
|
@@ -21,16 +21,30 @@ export class TestGroup {
|
|
|
21
21
|
this.results.push(test);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
report():
|
|
25
|
-
let
|
|
24
|
+
report(): ReportLogs | null {
|
|
25
|
+
let passed_logs = "";
|
|
26
|
+
let failed_logs = "";
|
|
26
27
|
for (let i = 0; i < this.results.length; i++) {
|
|
27
|
-
const result = unchecked(this.results[i])
|
|
28
|
-
|
|
28
|
+
const result = unchecked(this.results[i]);
|
|
29
|
+
const report = result.report();
|
|
30
|
+
if (report) {
|
|
31
|
+
if (result.verdict === Verdict.Fail) failed_logs += report + "\n";
|
|
32
|
+
else if (result.verdict === Verdict.Ok) passed_logs += report + "\n";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
passed: passed_logs.length ? passed_logs : null,
|
|
37
|
+
failed: failed_logs.length ? failed_logs : null
|
|
29
38
|
}
|
|
30
|
-
return report.length ? report : null;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
run(): void {
|
|
34
42
|
this.callback();
|
|
35
43
|
}
|
|
36
44
|
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ReportLogs {
|
|
48
|
+
passed: string | null;
|
|
49
|
+
failed: string | null;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "as-test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
|
|
5
5
|
"types": "assembly/index.ts",
|
|
6
6
|
"author": "Jairus Tanaka",
|
|
7
7
|
"contributors": [],
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
10
|
+
"test": "wasmtime ./build/test.wasm",
|
|
11
|
+
"pretest": "asc assembly/test.ts -o build/test.wasm --bindings esm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json > ./build/test.build.log",
|
|
11
12
|
"build:bench": "asc assembly/bench/bench.ts -o build/bench.wasm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --optimizeLevel 3 --converge --exportRuntime --runtime stub",
|
|
12
13
|
"bench:wasmtime": "wasmtime ./build/bench.wasm",
|
|
13
14
|
"build:transform": "tsc -p ./transform",
|
|
14
|
-
"test:wasmtime": "wasmtime ./build/test.wasm",
|
|
15
15
|
"prettier": "as-prettier -w ."
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|