as-test 0.1.0 → 0.1.2
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 +4 -1
- package/README.md +24 -2
- package/asconfig.json +36 -0
- package/assembly/coverage.ts +31 -0
- package/assembly/index.ts +34 -19
- package/assembly/src/expectation.ts +1 -1
- package/assembly/src/group.ts +1 -1
- package/assembly/test.ts +6 -1
- package/package.json +17 -7
- package/src/cli.ts +0 -0
- package/test.config.json +0 -0
- package/transform/lib/index.js +508 -0
- package/transform/package.json +33 -0
- package/transform/src/index.ts +661 -0
- package/transform/tsconfig.json +63 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,4 +7,7 @@ v0.0.5 - Switch errors to be thrown at compile time instead of runtime
|
|
|
7
7
|
v0.0.6 - Failed tests should be pushed to bottom of logs
|
|
8
8
|
v0.0.8 - Fix readme typo in v0.0.7
|
|
9
9
|
v0.0.9 - Fix type issue
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
v0.1.0 - Fix more type issues
|
|
12
|
+
v0.1.1 - Add code coverage!
|
|
13
|
+
v0.1.2 - Fix bugs with globals and dependencies
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
| _ || __| ___|_ _|| __|| __||_ _|
|
|
4
4
|
| ||__ ||___| | | | __||__ | | |
|
|
5
5
|
|__|__||_____| |_| |_____||_____| |_|
|
|
6
|
-
v0.1.
|
|
6
|
+
v0.1.1
|
|
7
7
|
</pre>
|
|
8
8
|
</h5>
|
|
9
9
|
|
|
@@ -13,6 +13,25 @@ v0.1.0
|
|
|
13
13
|
npm install as-test
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
Add the transform to your `asc` command (e.g. in package.json)
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
--transform as-test/transform
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Alternatively, add it to your `asconfig.json`
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
{
|
|
26
|
+
// ...
|
|
27
|
+
"options": {
|
|
28
|
+
"transform": ["as-test/transform"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Note: The transform *is* OPTIONAL, though it is required to enable code coverage.
|
|
34
|
+
|
|
16
35
|
## Usage
|
|
17
36
|
|
|
18
37
|
```js
|
|
@@ -82,7 +101,8 @@ describe("Array manipulation", () => {
|
|
|
82
101
|
});
|
|
83
102
|
|
|
84
103
|
run({
|
|
85
|
-
log: false
|
|
104
|
+
log: false,
|
|
105
|
+
coverage: true
|
|
86
106
|
});
|
|
87
107
|
```
|
|
88
108
|
|
|
@@ -112,6 +132,7 @@ run({
|
|
|
112
132
|
|
|
113
133
|
Test Suites: 0 failed, 2 total
|
|
114
134
|
Tests: 0 failed, 8 total
|
|
135
|
+
Coverage: 0 failed, 23 total
|
|
115
136
|
Snapshots: 0 total
|
|
116
137
|
Time: 101.812μs
|
|
117
138
|
</pre>
|
|
@@ -147,6 +168,7 @@ To add `as-test` to your CI/CD workflow, check out [The provided example](https:
|
|
|
147
168
|
|
|
148
169
|
If you use this project in your codebase, consider dropping a [⭐ HERE](https://github.com/JairusSW/as-test). I would really appreciate it!
|
|
149
170
|
|
|
171
|
+
|
|
150
172
|
## Notes
|
|
151
173
|
|
|
152
174
|
This library is in the EARLY STAGES OF DEVELOPMENT!
|
package/asconfig.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": {
|
|
3
|
+
"test": {
|
|
4
|
+
"outFile": "build/test.spec.wasm",
|
|
5
|
+
"sourceMap": false,
|
|
6
|
+
"optimizeLevel": 0,
|
|
7
|
+
"shrinkLevel": 0,
|
|
8
|
+
"converge": false,
|
|
9
|
+
"noAssert": false
|
|
10
|
+
},
|
|
11
|
+
"debug": {
|
|
12
|
+
"outFile": "build/test.wasm",
|
|
13
|
+
"sourceMap": false,
|
|
14
|
+
"optimizeLevel": 0,
|
|
15
|
+
"shrinkLevel": 0,
|
|
16
|
+
"converge": false,
|
|
17
|
+
"noAssert": false
|
|
18
|
+
},
|
|
19
|
+
"bench": {
|
|
20
|
+
"outFile": "build/bench.wasm",
|
|
21
|
+
"sourceMap": false,
|
|
22
|
+
"optimizeLevel": 3,
|
|
23
|
+
"shrinkLevel": 0,
|
|
24
|
+
"converge": true,
|
|
25
|
+
"noAssert": false
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"options": {
|
|
29
|
+
"transform": ["./transform"],
|
|
30
|
+
"disableWarning": [
|
|
31
|
+
226
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class CoverPoint {
|
|
2
|
+
public file: string = "";
|
|
3
|
+
public hash: string = "";
|
|
4
|
+
public line: i32 = 0;
|
|
5
|
+
public column: i32 = 0;
|
|
6
|
+
public type!: string;
|
|
7
|
+
public executed: boolean = false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class Coverage {
|
|
11
|
+
public hashes: Map<string, CoverPoint> = new Map<string, CoverPoint>();
|
|
12
|
+
public points: i32 = 0;
|
|
13
|
+
static SN: Coverage = new Coverage();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function __REGISTER(point: CoverPoint): void {
|
|
17
|
+
Coverage.SN.points++;
|
|
18
|
+
Coverage.SN.hashes.set(point.hash, point);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function __COVER(hash: string): void {
|
|
22
|
+
if (Coverage.SN.hashes.has(hash)) Coverage.SN.hashes.delete(hash);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function __HASHES(): Map<string, CoverPoint> {
|
|
26
|
+
return Coverage.SN.hashes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function __POINTS(): i32 {
|
|
30
|
+
return Coverage.SN.points;
|
|
31
|
+
}
|
package/assembly/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { TestGroup } from "./src/group";
|
|
|
3
3
|
import { Expectation } from "./src/expectation";
|
|
4
4
|
import { formatTime } from "./util";
|
|
5
5
|
import { stringify } from "as-console/assembly";
|
|
6
|
+
import { __COVER, __HASHES, __POINTS } from "as-test/assembly/coverage";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Enumeration representing the verdict of a test case.
|
|
@@ -20,12 +21,9 @@ let groups: TestGroup[] = [];
|
|
|
20
21
|
let before_all_callback: (() => void) | null = null;
|
|
21
22
|
let after_all_callback: (() => void) | null = null;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@global let after_each_callback: (() => void) | null = null;
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
@global let __test_options!: RunOptions;
|
|
24
|
+
export let before_each_callback: (() => void) | null = null;
|
|
25
|
+
export let after_each_callback: (() => void) | null = null;
|
|
26
|
+
let __test_options!: RunOptions;
|
|
29
27
|
|
|
30
28
|
/**
|
|
31
29
|
* Creates a test group containing multiple test cases.
|
|
@@ -184,7 +182,8 @@ export function afterEach(callback: () => void): void {
|
|
|
184
182
|
* - `log` (boolean, default: true): Controls whether enable the log() function
|
|
185
183
|
**/
|
|
186
184
|
class RunOptions {
|
|
187
|
-
log: boolean = true
|
|
185
|
+
log: boolean = true;
|
|
186
|
+
coverage: boolean = false;
|
|
188
187
|
}
|
|
189
188
|
|
|
190
189
|
/**
|
|
@@ -210,11 +209,14 @@ class RunOptions {
|
|
|
210
209
|
*/
|
|
211
210
|
export function run(options: RunOptions = new RunOptions()): void {
|
|
212
211
|
__test_options = options;
|
|
213
|
-
console.log(rainbow.boldMk(rainbow.
|
|
214
|
-
console.log(rainbow.boldMk(rainbow.
|
|
215
|
-
console.log(rainbow.boldMk(rainbow.
|
|
216
|
-
console.log(rainbow.boldMk(rainbow.
|
|
217
|
-
console.log(rainbow.dimMk
|
|
212
|
+
console.log(rainbow.boldMk(rainbow.blueBright(` _____ _____ _____ _____ _____ _____ `)));
|
|
213
|
+
console.log(rainbow.boldMk(rainbow.blueBright(`| _ || __| ___|_ _|| __|| __||_ _|`)));
|
|
214
|
+
console.log(rainbow.boldMk(rainbow.blueBright(`| ||__ ||___| | | | __||__ | | | `)));
|
|
215
|
+
console.log(rainbow.boldMk(rainbow.blueBright(`|__|__||_____| |_| |_____||_____| |_| `)));
|
|
216
|
+
console.log(rainbow.dimMk("\n------------------- v0.1.1 -------------------\n"));
|
|
217
|
+
if (options.coverage) {
|
|
218
|
+
console.log(rainbow.bgBlueBright(" PLUGIN ") + " " + rainbow.dimMk("Using Code Coverage") + "\n");
|
|
219
|
+
}
|
|
218
220
|
const suites = groups.length;
|
|
219
221
|
let failed = 0;
|
|
220
222
|
let tests = 0;
|
|
@@ -247,7 +249,7 @@ export function run(options: RunOptions = new RunOptions()): void {
|
|
|
247
249
|
console.log(txt);
|
|
248
250
|
}
|
|
249
251
|
|
|
250
|
-
const report = suite.
|
|
252
|
+
const report = suite.getLogs();
|
|
251
253
|
if (report) {
|
|
252
254
|
if (report.passed) console.log(report.passed!);
|
|
253
255
|
if (report.failed) failed_suite_logs += report.failed!;
|
|
@@ -259,16 +261,29 @@ export function run(options: RunOptions = new RunOptions()): void {
|
|
|
259
261
|
if (failed) {
|
|
260
262
|
console.log(rainbow.red("------------------ [FAILED] ------------------\n"));
|
|
261
263
|
console.log(failed_suite_logs);
|
|
262
|
-
console.log(rainbow.red("----------------- [RESULTS] ------------------\n"));
|
|
263
|
-
} else {
|
|
264
|
-
console.log(rainbow.dimMk("----------------- [RESULTS] ------------------\n"));
|
|
265
264
|
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
if (options.coverage && __HASHES().size) {
|
|
268
|
+
console.log(rainbow.dimMk("----------------- [COVERAGE] -----------------\n"));
|
|
269
|
+
const points = __HASHES().values();
|
|
270
|
+
|
|
271
|
+
for (let i = 0; i < points.length; i++) {
|
|
272
|
+
const point = unchecked(points[i]);
|
|
273
|
+
console.log(rainbow.bgRed(" UNCOVERED ") + " " + point.type + " at " + point.file + ":" + point.line.toString() + ":" + point.column.toString());
|
|
274
|
+
}
|
|
275
|
+
console.log("");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
console.log(rainbow.dimMk("----------------- [RESULTS] ------------------\n"));
|
|
266
279
|
const ms = performance.now() - start;
|
|
267
|
-
console.log(rainbow.boldMk("Test Suites: ") + (failed ? rainbow.boldMk(rainbow.red(failed.toString() + " failed")) : rainbow.boldMk(rainbow.green(
|
|
268
|
-
console.log(rainbow.boldMk("Tests: ") + (failed_tests ? rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) : rainbow.boldMk(rainbow.green(
|
|
280
|
+
console.log(rainbow.boldMk("Test Suites: ") + (failed ? rainbow.boldMk(rainbow.red(failed.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + suites.toString() + " total");
|
|
281
|
+
console.log(rainbow.boldMk("Tests: ") + (failed_tests ? rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + tests.toString() + " total");
|
|
282
|
+
if (options.coverage) console.log(rainbow.boldMk("Coverage: ") + (__HASHES().size ? rainbow.boldMk(rainbow.red(__HASHES().size.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + __POINTS().toString() + " total");
|
|
269
283
|
console.log(rainbow.boldMk("Snapshots: ") + "0 total");
|
|
270
284
|
console.log(rainbow.boldMk("Time: ") + formatTime(ms));
|
|
285
|
+
__COVER("joe mom")
|
|
271
286
|
if (failed) {
|
|
272
|
-
process.exit(1)
|
|
287
|
+
process.exit(1);
|
|
273
288
|
}
|
|
274
289
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rainbow } from "as-rainbow";
|
|
2
2
|
import { diff, visualize } from "../util";
|
|
3
3
|
import { Node } from "./node";
|
|
4
|
-
import { Verdict } from "..";
|
|
4
|
+
import { Verdict, after_each_callback, before_each_callback } from "..";
|
|
5
5
|
|
|
6
6
|
export class Expectation<T> extends Node {
|
|
7
7
|
public verdict: Verdict = Verdict.Unreachable;
|
package/assembly/src/group.ts
CHANGED
package/assembly/test.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "as-test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
|
|
5
5
|
"types": "assembly/index.ts",
|
|
6
6
|
"author": "Jairus Tanaka",
|
|
@@ -8,23 +8,33 @@
|
|
|
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
|
|
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",
|
|
11
|
+
"pretest": "TEST_DEBUG=all asc assembly/test.ts -o build/test.wasm --transform ./transform --bindings esm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
|
|
13
12
|
"bench:wasmtime": "wasmtime ./build/bench.wasm",
|
|
14
13
|
"build:transform": "tsc -p ./transform",
|
|
15
14
|
"prettier": "as-prettier -w ."
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
17
|
+
"as-test": "./",
|
|
18
18
|
"@assemblyscript/wasi-shim": "^0.1.0",
|
|
19
|
+
"@types/micromatch": "^4.0.7",
|
|
19
20
|
"assemblyscript": "^0.27.22",
|
|
20
21
|
"assemblyscript-prettier": "^3.0.1",
|
|
21
22
|
"jest": "^29.7.0",
|
|
22
23
|
"typescript": "^5.3.3",
|
|
23
|
-
"visitor-as": "^0.11.4"
|
|
24
|
+
"visitor-as": "^0.11.4",
|
|
25
|
+
"json-as": "^0.9.6"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"as-console": "^6.0.2",
|
|
29
|
+
"as-rainbow": "^0.1.0",
|
|
30
|
+
"as-string-sink": "^0.5.3",
|
|
31
|
+
"as-variant": "^0.4.1",
|
|
32
|
+
"chalk": "^5.3.0",
|
|
33
|
+
"micromatch": "^4.0.7"
|
|
24
34
|
},
|
|
25
|
-
"dependencies": { "as-console": "^6.0.2", "as-convert-seconds": "^1.0.0", "as-rainbow": "^0.1.0", "as-string-sink": "^0.5.3", "as-variant": "^0.4.1", "json-as": "^0.9.6" },
|
|
26
35
|
"overrides": {
|
|
27
|
-
"assemblyscript": "$assemblyscript"
|
|
36
|
+
"assemblyscript": "$assemblyscript",
|
|
37
|
+
"visitor-as": "$visitor-as"
|
|
28
38
|
},
|
|
29
39
|
"repository": {
|
|
30
40
|
"type": "git",
|
|
@@ -45,4 +55,4 @@
|
|
|
45
55
|
"publishConfig": {
|
|
46
56
|
"@JairusSW:registry": "https://npm.pkg.github.com"
|
|
47
57
|
}
|
|
48
|
-
}
|
|
58
|
+
}
|
package/src/cli.ts
ADDED
|
File without changes
|
package/test.config.json
ADDED
|
File without changes
|