as-test 0.0.4 → 0.0.6
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/nodejs.yml +28 -0
- package/CHANGELOG.md +7 -0
- package/README.md +31 -3
- package/assembly/index.ts +23 -6
- package/assembly/src/expectation.ts +6 -6
- package/assembly/src/group.ts +19 -5
- package/assembly/test.ts +0 -1
- package/package.json +8 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Node.js CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- name: Checkout the repository
|
|
12
|
+
uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- name: Install Wasmtime
|
|
15
|
+
uses: jcbhmr/setup-wasmtime@v2
|
|
16
|
+
|
|
17
|
+
- name: Setup Node.js
|
|
18
|
+
uses: actions/setup-node@v2
|
|
19
|
+
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
if: steps.node-cache.outputs.cache-hit != 'true'
|
|
22
|
+
run: yarn
|
|
23
|
+
|
|
24
|
+
- name: Build tests
|
|
25
|
+
run: yarn run build:test
|
|
26
|
+
|
|
27
|
+
- name: Perform tests
|
|
28
|
+
run: yarn run test:wasmtime
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
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
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
| _ || __| ___|_ _|| __|| __||_ _|
|
|
4
4
|
| ||__ ||___| | | | __||__ | | |
|
|
5
5
|
|__|__||_____| |_| |_____||_____| |_|
|
|
6
|
-
v0.0.
|
|
6
|
+
v0.0.5
|
|
7
7
|
</pre>
|
|
8
8
|
</h5>
|
|
9
9
|
|
|
@@ -86,7 +86,7 @@ run({
|
|
|
86
86
|
});
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
<
|
|
89
|
+
<h6>
|
|
90
90
|
<pre> _____ _____ _____ _____ _____ _____
|
|
91
91
|
| _ || __| ___|_ _|| __|| __||_ _|
|
|
92
92
|
| ||__ ||___| | | | __||__ | | |
|
|
@@ -115,7 +115,35 @@ Tests: 0 failed, 8 total
|
|
|
115
115
|
Snapshots: 0 total
|
|
116
116
|
Time: 101.812μs
|
|
117
117
|
</pre>
|
|
118
|
-
</
|
|
118
|
+
</h6>
|
|
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)
|
|
119
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
|
|
package/assembly/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rainbow } from "as-rainbow";
|
|
2
2
|
import { TestGroup } from "./src/group";
|
|
3
3
|
import { Expectation } from "./src/expectation";
|
|
4
|
-
import {
|
|
4
|
+
import { formatTime } from "./util";
|
|
5
5
|
import { stringify } from "as-console/assembly";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -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.6 -------------------\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
|
}
|
|
@@ -5,9 +5,9 @@ import { Verdict } from "..";
|
|
|
5
5
|
|
|
6
6
|
export class Expectation<T> extends Node {
|
|
7
7
|
public verdict: Verdict = Verdict.Unreachable;
|
|
8
|
-
|
|
8
|
+
private left: T;
|
|
9
9
|
private _left: string | null = null;
|
|
10
|
-
|
|
10
|
+
private right: u64 = 0;
|
|
11
11
|
private _right: string | null = null;
|
|
12
12
|
private _not: boolean = false;
|
|
13
13
|
private op: string = "=";
|
|
@@ -44,7 +44,7 @@ export class Expectation<T> extends Node {
|
|
|
44
44
|
* @returns - void
|
|
45
45
|
*/
|
|
46
46
|
toBeGreaterThan(value: T): void {
|
|
47
|
-
if (!isInteger<T>() && !isFloat<T>())
|
|
47
|
+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeGreaterThan() can only be used on number types!");
|
|
48
48
|
|
|
49
49
|
this.verdict = this.left > value ? Verdict.Ok : Verdict.Fail;
|
|
50
50
|
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
@@ -63,7 +63,7 @@ export class Expectation<T> extends Node {
|
|
|
63
63
|
* @returns - void
|
|
64
64
|
*/
|
|
65
65
|
toBeGreaterOrEqualTo(value: T): void {
|
|
66
|
-
if (!isInteger<T>() && !isFloat<T>())
|
|
66
|
+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeGreaterOrEqualTo() can only be used on number types!");
|
|
67
67
|
|
|
68
68
|
this.verdict = this.left >= value ? Verdict.Ok : Verdict.Fail;
|
|
69
69
|
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
@@ -82,7 +82,7 @@ export class Expectation<T> extends Node {
|
|
|
82
82
|
* @returns - void
|
|
83
83
|
*/
|
|
84
84
|
toBeLessThan(value: T): void {
|
|
85
|
-
if (!isInteger<T>() && !isFloat<T>())
|
|
85
|
+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeLessThan() can only be used on number types!");
|
|
86
86
|
|
|
87
87
|
this.verdict = this.left < value ? Verdict.Ok : Verdict.Fail;
|
|
88
88
|
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
@@ -101,7 +101,7 @@ export class Expectation<T> extends Node {
|
|
|
101
101
|
* @returns - void
|
|
102
102
|
*/
|
|
103
103
|
toBeLessThanOrEqualTo(value: T): void {
|
|
104
|
-
if (!isInteger<T>() && !isFloat<T>())
|
|
104
|
+
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeLessThanOrEqualTo() can only be used on number types!");
|
|
105
105
|
|
|
106
106
|
this.verdict = this.left <= value ? Verdict.Ok : Verdict.Fail;
|
|
107
107
|
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
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/assembly/test.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "as-test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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": {
|
|
@@ -31,7 +31,11 @@
|
|
|
31
31
|
"url": "git+https://github.com/JairusSW/as-test.git"
|
|
32
32
|
},
|
|
33
33
|
"keywords": [
|
|
34
|
-
"assemblyscript"
|
|
34
|
+
"assemblyscript",
|
|
35
|
+
"testing",
|
|
36
|
+
"test",
|
|
37
|
+
"as-pect",
|
|
38
|
+
"aspect"
|
|
35
39
|
],
|
|
36
40
|
"bugs": {
|
|
37
41
|
"url": "https://github.com/JairusSW/as-test/issues"
|