as-test 0.2.0 → 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 +4 -1
- package/README.md +73 -67
- 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 +61 -55
- 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/CHANGELOG.md
CHANGED
|
@@ -19,5 +19,8 @@ v0.1.7 - Fix: remove warning about wasi-shim not being included when it is inclu
|
|
|
19
19
|
v0.1.8 - Feat: function mocking
|
|
20
20
|
v0.1.9 - Fix: mocks were not being applied to declared functions, only property accesses
|
|
21
21
|
v0.1.10 - Feat: support node, deno, and bun
|
|
22
|
+
|
|
22
23
|
v0.2.0 - Fix mock -> mockFn artifacts
|
|
23
|
-
|
|
24
|
+
v0.2.1 - Remove accidental logging
|
|
25
|
+
|
|
26
|
+
v0.3.0 - Pass metadata through terminal - Support for multiple files - Better reporting - Timing for suites - Terminal utilities
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
| _ || __| ___|_ _|| __|| __||_ _|
|
|
4
4
|
| ||__ ||___| | | | __||__ | | |
|
|
5
5
|
|__|__||_____| |_| |_____||_____| |_|
|
|
6
|
-
v0.
|
|
6
|
+
v0.3.0
|
|
7
7
|
</pre>
|
|
8
8
|
</h5>
|
|
9
9
|
|
|
@@ -17,13 +17,6 @@ You'll also need to install `visitor-as`
|
|
|
17
17
|
|
|
18
18
|
`npm i visitor-as --save-dev`
|
|
19
19
|
|
|
20
|
-
## Templates
|
|
21
|
-
|
|
22
|
-
I provide two templates for reference
|
|
23
|
-
|
|
24
|
-
[WASI](https://github.com/JairusSW/as-test/tree/template/wasi)
|
|
25
|
-
[Node/Bun/Deno](https://github.com/JairusSW/as-test/tree/template/node-bun-deno)
|
|
26
|
-
|
|
27
20
|
View the docs: https://docs.jairus.dev/as-test
|
|
28
21
|
|
|
29
22
|
## Usage
|
|
@@ -36,101 +29,114 @@ as-test init
|
|
|
36
29
|
|
|
37
30
|
Note: You can use either `ast` or `as-test` in the terminal.
|
|
38
31
|
|
|
39
|
-
Next,
|
|
32
|
+
Next, take a look at the generated test file
|
|
40
33
|
|
|
41
|
-
`assembly/__tests__/
|
|
34
|
+
`assembly/__tests__/example.spec.ts`
|
|
42
35
|
|
|
43
36
|
```js
|
|
44
37
|
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
run
|
|
38
|
+
describe,
|
|
39
|
+
expect,
|
|
40
|
+
test,
|
|
41
|
+
beforeAll,
|
|
42
|
+
afterAll,
|
|
43
|
+
mockFn,
|
|
44
|
+
log,
|
|
45
|
+
run,
|
|
46
|
+
it
|
|
55
47
|
} from "as-test";
|
|
56
48
|
|
|
57
49
|
beforeAll(() => {
|
|
58
|
-
|
|
50
|
+
log("Setting up test environment...");
|
|
59
51
|
});
|
|
60
52
|
|
|
61
53
|
afterAll(() => {
|
|
62
|
-
|
|
54
|
+
log("Tearing down test environment...");
|
|
63
55
|
});
|
|
64
56
|
|
|
65
57
|
// Mock/override the function console.log
|
|
66
58
|
mockFn<void>("console.log", (data: string): void => {
|
|
67
|
-
|
|
59
|
+
console.log("[MOCKED]: " + data + "\n");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("Should sleep", () => {
|
|
63
|
+
test("1ms", () => {
|
|
64
|
+
const start = Date.now();
|
|
65
|
+
sleep(1);
|
|
66
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(1);
|
|
67
|
+
});
|
|
68
|
+
test("10ms", () => {
|
|
69
|
+
const start = Date.now();
|
|
70
|
+
sleep(10);
|
|
71
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(10);
|
|
72
|
+
});
|
|
73
|
+
test("1s", () => {
|
|
74
|
+
const start = Date.now();
|
|
75
|
+
sleep(1000);
|
|
76
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
|
|
77
|
+
});
|
|
78
|
+
test("5s", () => {
|
|
79
|
+
const start = Date.now();
|
|
80
|
+
log("Sleeping...");
|
|
81
|
+
sleep(5000);
|
|
82
|
+
log("Done!");
|
|
83
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(5000);
|
|
84
|
+
});
|
|
68
85
|
});
|
|
69
86
|
|
|
70
87
|
describe("Math operations", () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
expect("hello").toBeString();
|
|
90
|
-
expect(true).toBeBoolean();
|
|
91
|
-
expect(10.5).toBeNumber();
|
|
92
|
-
});
|
|
88
|
+
test("Addition", () => {
|
|
89
|
+
expect(1 + 2).toBe(3);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("Subtraction", () => {
|
|
93
|
+
expect(1 - 2).toBe(-1);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("Comparison", () => {
|
|
97
|
+
expect(5).toBeGreaterThan(3);
|
|
98
|
+
expect(2).toBeLessThan(4);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("Type checking", () => {
|
|
102
|
+
expect("hello").toBeString();
|
|
103
|
+
expect(true).toBeBoolean();
|
|
104
|
+
expect(10.5).toBeNumber();
|
|
105
|
+
});
|
|
93
106
|
});
|
|
94
107
|
|
|
95
|
-
let myArray: i32[] = [];
|
|
108
|
+
let myArray: i32[] = [1, 2, 3];
|
|
96
109
|
|
|
97
110
|
describe("Array manipulation", () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
test("Array length", () => {
|
|
112
|
+
expect(myArray).toHaveLength(3);
|
|
113
|
+
});
|
|
101
114
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
test("Array inclusion", () => {
|
|
116
|
+
expect(myArray).toContain(2);
|
|
117
|
+
});
|
|
105
118
|
|
|
106
|
-
|
|
107
|
-
expect(myArray).toContain(2);
|
|
108
|
-
});
|
|
119
|
+
it("should be empty", () => { });
|
|
109
120
|
});
|
|
110
121
|
|
|
111
|
-
run(
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
run();
|
|
123
|
+
|
|
124
|
+
function sleep(ms: i64): void {
|
|
125
|
+
const target = Date.now() + ms;
|
|
126
|
+
while (target > Date.now()) { }
|
|
127
|
+
}
|
|
114
128
|
```
|
|
115
129
|
|
|
116
130
|
Build and run it using as-test
|
|
117
131
|
|
|
118
132
|
```bash
|
|
119
|
-
|
|
133
|
+
npm run test
|
|
120
134
|
```
|
|
121
135
|
|
|
122
136
|
<h6>
|
|
123
137
|
|
|
124
138
|
## Running
|
|
125
139
|
|
|
126
|
-
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.
|
|
127
|
-
|
|
128
|
-
And finally, run it with:
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
npm run test
|
|
132
|
-
```
|
|
133
|
-
|
|
134
140
|
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)
|
|
135
141
|
|
|
136
142
|
If you use this project in your codebase, consider dropping a [⭐ HERE](https://github.com/JairusSW/as-test). I would really appreciate it!
|
package/as-test.config.json
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"input": ["./assembly/__tests__/*.spec.ts"],
|
|
3
3
|
"outDir": "./build",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"show": false
|
|
4
|
+
"logs": "./logs",
|
|
5
|
+
"config": "none",
|
|
6
|
+
"plugins": {
|
|
7
|
+
"coverage": true
|
|
9
8
|
},
|
|
10
9
|
"buildOptions": {
|
|
11
10
|
"args": [],
|
|
12
|
-
"
|
|
13
|
-
"parallel": true,
|
|
14
|
-
"verbose": true
|
|
11
|
+
"target": "bindings"
|
|
15
12
|
},
|
|
16
13
|
"runOptions": {
|
|
17
14
|
"runtime": {
|
|
18
|
-
"name": "
|
|
19
|
-
"run": "
|
|
15
|
+
"name": "node",
|
|
16
|
+
"run": "node ./tests/<name>.run.js"
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, test, run, it } from "..";
|
|
2
|
+
|
|
3
|
+
const myArray: i32[] = [1, 2, 3];
|
|
4
|
+
|
|
5
|
+
describe("Array manipulation", () => {
|
|
6
|
+
test("Array length", () => {
|
|
7
|
+
expect(myArray).toHaveLength(3);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("Array inclusion", () => {
|
|
11
|
+
expect(myArray).toContain(2);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should be empty", () => {});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
run({
|
|
18
|
+
log: false,
|
|
19
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test, run } from "..";
|
|
2
|
+
|
|
3
|
+
describe("Math operations", () => {
|
|
4
|
+
test("Addition", () => {
|
|
5
|
+
expect(1 + 2).toBe(3);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test("Comparison", () => {
|
|
9
|
+
expect(5).toBeGreaterThan(3);
|
|
10
|
+
expect(2).toBeLessThan(4);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
run({
|
|
15
|
+
log: false,
|
|
16
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, log, run, test } from "..";
|
|
2
|
+
import { sleep } from "as-sleep/assembly";
|
|
3
|
+
describe("Should sleep", () => {
|
|
4
|
+
test("1ms", () => {
|
|
5
|
+
const start = Date.now();
|
|
6
|
+
sleep(1);
|
|
7
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(1);
|
|
8
|
+
});
|
|
9
|
+
test("10ms", () => {
|
|
10
|
+
const start = Date.now();
|
|
11
|
+
sleep(10);
|
|
12
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(10);
|
|
13
|
+
});
|
|
14
|
+
test("1s", () => {
|
|
15
|
+
const start = Date.now();
|
|
16
|
+
sleep(1000);
|
|
17
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
|
|
18
|
+
});
|
|
19
|
+
test("5s", () => {
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
log("Sleeping...");
|
|
22
|
+
sleep(5000);
|
|
23
|
+
log("Done!");
|
|
24
|
+
expect(Date.now() - start).toBeGreaterOrEqualTo(5000);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
run();
|