as-test 0.3.4 → 0.4.0-beta.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.
- package/CHANGELOG.md +3 -28
- package/README.md +92 -97
- package/as-test.config.json +2 -2
- package/assembly/__tests__/array.spec.ts +13 -7
- package/assembly/coverage.ts +1 -1
- package/assembly/src/expectation.ts +53 -46
- package/assembly/src/tests.ts +4 -3
- package/assembly/util/helpers.ts +13 -0
- package/bin/index.js +1 -1
- package/bin/init.js +2 -2
- package/bin/run.js +4 -4
- package/cli/index.ts +1 -1
- package/cli/init.ts +2 -2
- package/cli/run.ts +3 -3
- package/package.json +7 -7
- package/run/package.json +1 -1
- package/transform/lib/coverage.js +319 -325
- package/transform/lib/index.js +36 -51
- package/transform/lib/mock.js +93 -126
- package/transform/package.json +1 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
|
|
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
|
|
9
|
-
v0.0.9 - Fix type issue
|
|
1
|
+
# Change Log
|
|
10
2
|
|
|
11
|
-
v0.
|
|
12
|
-
v0.1.1 - Add code coverage!
|
|
13
|
-
v0.1.2 - Fix bugs with globals and dependencies
|
|
14
|
-
v0.1.3 - Revamp `log<T>(data: T)` with new as-console version
|
|
15
|
-
v0.1.4 - Fix a few bugs with the cli
|
|
16
|
-
v0.1.5 - Add skeleton cli and custom config
|
|
17
|
-
v0.1.6 - Fix: args should be prefixed with a space
|
|
18
|
-
v0.1.7 - Fix: remove warning about wasi-shim not being included when it is included
|
|
19
|
-
v0.1.8 - Feat: function mocking
|
|
20
|
-
v0.1.9 - Fix: mocks were not being applied to declared functions, only property accesses
|
|
21
|
-
v0.1.10 - Feat: support node, deno, and bun
|
|
3
|
+
## 2025-03-03 - v0.4.0-beta.1
|
|
22
4
|
|
|
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
|
|
27
|
-
v0.3.1 - Add screenshot of completed tests to readme
|
|
28
|
-
v0.3.2 - Add `mockImport` to override imported functions
|
|
29
|
-
v0.3.3 - Allow `mockImport`'s return type to be any
|
|
30
|
-
v0.3.4 - Fix: import functions were not received after visitSource()
|
|
5
|
+
- deps: update json-as to `v1.0.0-beta.8`
|
package/README.md
CHANGED
|
@@ -1,90 +1,47 @@
|
|
|
1
1
|
<h5 align="center">
|
|
2
|
-
<pre>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
<pre>
|
|
3
|
+
<span style="font-size: 0.8em;"> █████ ███████ ████████ ███████ ███████ ████████
|
|
4
|
+
██ ██ ██ ██ ██ ██ ██
|
|
5
|
+
███████ ███████ █████ ██ █████ ███████ ██
|
|
6
|
+
██ ██ ██ ██ ██ ██ ██
|
|
7
|
+
██ ██ ███████ ██ ███████ ███████ ██
|
|
8
|
+
</span>
|
|
9
|
+
AssemblyScript - v0.4.0-beta.1
|
|
7
10
|
</pre>
|
|
8
11
|
</h5>
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
A lightweight testing framework for AssemblyScript.
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
🔹 Minimal and fast – Run your tests without unnecessary overhead.
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
🔹 Familiar API – Inspired by modern JavaScript testing frameworks.
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
🔹 Powerful mocking – Easily override functions and track calls.
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
🔹 Seamless CI/CD integration – Works effortlessly in automation pipelines.
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
🔹 Universal environment – Run your tests on any platform, runtime, or bindings.
|
|
21
24
|
|
|
22
|
-
##
|
|
25
|
+
## 💾 Installation
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
```bash
|
|
28
|
+
npm install as-test
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Initialize your test setup with:
|
|
25
32
|
|
|
26
33
|
```bash
|
|
27
34
|
as-test init
|
|
28
35
|
```
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
This creates a test directory at `assembly/__tests__/` with a sample test file.
|
|
31
38
|
|
|
32
|
-
|
|
39
|
+
## 📝 Writing Tests
|
|
33
40
|
|
|
34
|
-
`assembly/__tests__
|
|
41
|
+
Create a new test file in `assembly/__tests__/`, for example, `math.spec.ts`:
|
|
35
42
|
|
|
36
43
|
```js
|
|
37
|
-
import {
|
|
38
|
-
describe,
|
|
39
|
-
expect,
|
|
40
|
-
test,
|
|
41
|
-
beforeAll,
|
|
42
|
-
afterAll,
|
|
43
|
-
mockFn,
|
|
44
|
-
log,
|
|
45
|
-
run,
|
|
46
|
-
it
|
|
47
|
-
} from "as-test";
|
|
48
|
-
|
|
49
|
-
beforeAll(() => {
|
|
50
|
-
log("Setting up test environment...");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterAll(() => {
|
|
54
|
-
log("Tearing down test environment...");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Mock/override the function console.log
|
|
58
|
-
mockFn<void>("console.log", (data: string): void => {
|
|
59
|
-
console.log("[MOCKED]: " + data + "\n");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Or override an imported function with mockImport
|
|
63
|
-
|
|
64
|
-
describe("Should sleep", () => {
|
|
65
|
-
test("1ms", () => {
|
|
66
|
-
const start = Date.now();
|
|
67
|
-
sleep(1);
|
|
68
|
-
expect(Date.now() - start).toBeGreaterOrEqualTo(1);
|
|
69
|
-
});
|
|
70
|
-
test("10ms", () => {
|
|
71
|
-
const start = Date.now();
|
|
72
|
-
sleep(10);
|
|
73
|
-
expect(Date.now() - start).toBeGreaterOrEqualTo(10);
|
|
74
|
-
});
|
|
75
|
-
test("1s", () => {
|
|
76
|
-
const start = Date.now();
|
|
77
|
-
sleep(1000);
|
|
78
|
-
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
|
|
79
|
-
});
|
|
80
|
-
test("5s", () => {
|
|
81
|
-
const start = Date.now();
|
|
82
|
-
log("Sleeping...");
|
|
83
|
-
sleep(5000);
|
|
84
|
-
log("Done!");
|
|
85
|
-
expect(Date.now() - start).toBeGreaterOrEqualTo(5000);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
44
|
+
import { describe, test, expect, run } from "as-test";
|
|
88
45
|
|
|
89
46
|
describe("Math operations", () => {
|
|
90
47
|
test("Addition", () => {
|
|
@@ -92,55 +49,93 @@ describe("Math operations", () => {
|
|
|
92
49
|
});
|
|
93
50
|
|
|
94
51
|
test("Subtraction", () => {
|
|
95
|
-
expect(
|
|
52
|
+
expect(5 - 2).toBe(3);
|
|
96
53
|
});
|
|
97
54
|
|
|
98
|
-
test("
|
|
99
|
-
expect(
|
|
100
|
-
expect(2).toBeLessThan(4);
|
|
55
|
+
test("Multiplication", () => {
|
|
56
|
+
expect(3 * 3).toBe(9);
|
|
101
57
|
});
|
|
58
|
+
});
|
|
102
59
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
60
|
+
run();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## 🔍 Examples
|
|
64
|
+
|
|
65
|
+
### 🏗️ Mocking Functions
|
|
66
|
+
|
|
67
|
+
Use `mockFn` to override functions during testing:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { mockFn } from "as-test";
|
|
71
|
+
|
|
72
|
+
// Mock console.log
|
|
73
|
+
mockFn<void>("console.log", (data: string): void => {
|
|
74
|
+
console.log("[MOCKED]: " + data);
|
|
108
75
|
});
|
|
109
76
|
|
|
110
|
-
|
|
77
|
+
run();
|
|
78
|
+
```
|
|
111
79
|
|
|
112
|
-
|
|
113
|
-
test("Array length", () => {
|
|
114
|
-
expect(myArray).toHaveLength(3);
|
|
115
|
-
});
|
|
80
|
+
Or override imported functions with `mockImport`.
|
|
116
81
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
82
|
+
### ⚒️ Setup and Teardown
|
|
83
|
+
|
|
84
|
+
Use `beforeAll` and `afterAll` to run code before and after a test is run.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import { beforeAll, afterAll } from "as-test";
|
|
120
88
|
|
|
121
|
-
|
|
89
|
+
beforeAll(() => {
|
|
90
|
+
log("Setting up test environment...");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
afterAll(() => {
|
|
94
|
+
log("Tearing down test environment...");
|
|
122
95
|
});
|
|
123
96
|
|
|
124
97
|
run();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 📃 Pretty Logging
|
|
125
101
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
102
|
+
Using `console.log` will mess up the terminal output. Instead, use the inbuilt `log` function:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import { log } from "as-test";
|
|
106
|
+
|
|
107
|
+
log("This is a pretty log function");
|
|
108
|
+
|
|
109
|
+
run();
|
|
130
110
|
```
|
|
131
111
|
|
|
132
|
-
|
|
112
|
+
Or override all existing `console.log` calls with `log`:
|
|
133
113
|
|
|
134
|
-
```
|
|
135
|
-
|
|
114
|
+
```js
|
|
115
|
+
import { mockFn, log } from "as-test";
|
|
116
|
+
|
|
117
|
+
mockFn<void>("console.log", (data: string): void => {
|
|
118
|
+
log(data);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
run();
|
|
136
122
|
```
|
|
137
123
|
|
|
138
|
-
|
|
124
|
+
### 🔄 Running Tests in CI
|
|
125
|
+
|
|
126
|
+
To integrate `as-test` into your CI/CD workflow, see the [example configuration](https://github.com/JairusSW/as-test/blob/main/.github/workflows/as-test.yml).
|
|
127
|
+
|
|
128
|
+
`assembly/__tests__/example.spec.ts`
|
|
129
|
+
|
|
130
|
+
## 📃 License
|
|
139
131
|
|
|
140
|
-
|
|
132
|
+
This project is distributed under an open source license. You can view the full license using the following link: [License](./LICENSE)
|
|
141
133
|
|
|
142
|
-
|
|
134
|
+
## 📫 Contact
|
|
143
135
|
|
|
144
|
-
|
|
136
|
+
Please send all issues to [GitHub Issues](https://github.com/JairusSW/as-test/issues) and to converse, please send me an email at [me@jairus.dev](mailto:me@jairus.dev)
|
|
145
137
|
|
|
146
|
-
|
|
138
|
+
- **Email:** Send me inquiries, questions, or requests at [me@jairus.dev](mailto:me@jairus.dev)
|
|
139
|
+
- **GitHub:** Visit the official GitHub repository [Here](https://github.com/JairusSW/as-test)
|
|
140
|
+
- **Website:** Visit my official website at [jairus.dev](https://jairus.dev/)
|
|
141
|
+
- **Discord:** Contact me at [My Discord](https://discord.com/users/600700584038760448) or on the [AssemblyScript Discord Server](https://discord.gg/assemblyscript/)
|
package/as-test.config.json
CHANGED
|
@@ -3,17 +3,23 @@ import { describe, expect, test, run, it } from "..";
|
|
|
3
3
|
const myArray: i32[] = [1, 2, 3];
|
|
4
4
|
|
|
5
5
|
describe("Array manipulation", () => {
|
|
6
|
-
test("Array length", () => {
|
|
7
|
-
|
|
8
|
-
});
|
|
6
|
+
// test("Array length", () => {
|
|
7
|
+
// expect("foo").toBe("foo")
|
|
8
|
+
// });
|
|
9
9
|
|
|
10
|
-
test("Array inclusion", () => {
|
|
11
|
-
|
|
12
|
-
});
|
|
10
|
+
// test("Array inclusion", () => {
|
|
11
|
+
// expect(myArray).toContain(2);
|
|
12
|
+
// });
|
|
13
|
+
|
|
14
|
+
test("Array check", () => {
|
|
15
|
+
const a = [1,2,3];
|
|
16
|
+
const b = [1,2,3];
|
|
17
|
+
expect(a).toBe(b);
|
|
18
|
+
})
|
|
13
19
|
|
|
14
20
|
it("should be empty", () => {});
|
|
15
21
|
});
|
|
16
22
|
|
|
17
23
|
run({
|
|
18
|
-
log:
|
|
24
|
+
log: true,
|
|
19
25
|
});
|
package/assembly/coverage.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { visualize } from "../util/helpers";
|
|
2
2
|
import { Tests } from "./tests";
|
|
3
3
|
import { after_each_callback, before_each_callback } from "..";
|
|
4
|
+
import { JSON } from "json-as";
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
@json
|
|
7
8
|
export class Expectation<T> extends Tests {
|
|
8
9
|
public verdict: string = "none";
|
|
10
|
+
public right: JSON.Raw = JSON.Raw.from("");
|
|
11
|
+
public left: JSON.Raw = JSON.Raw.from("");
|
|
9
12
|
private _left: T;
|
|
10
13
|
// @ts-ignore
|
|
11
14
|
private _right: u64 = 0;
|
|
@@ -33,10 +36,10 @@ export class Expectation<T> extends Tests {
|
|
|
33
36
|
|
|
34
37
|
this.instr = "toBeNull";
|
|
35
38
|
|
|
36
|
-
this.left
|
|
37
|
-
this.right
|
|
39
|
+
this.left.set(visualize<T>(this._left));
|
|
40
|
+
this.right.set(visualize<T>(
|
|
38
41
|
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
|
|
39
|
-
);
|
|
42
|
+
));
|
|
40
43
|
|
|
41
44
|
// @ts-ignore
|
|
42
45
|
if (after_each_callback) after_each_callback();
|
|
@@ -62,10 +65,10 @@ export class Expectation<T> extends Tests {
|
|
|
62
65
|
|
|
63
66
|
this.instr = "toBeGreaterThan";
|
|
64
67
|
|
|
65
|
-
this.left
|
|
66
|
-
this.right
|
|
68
|
+
this.left.set(visualize<T>(this._left));
|
|
69
|
+
this.right.set(visualize<T>(
|
|
67
70
|
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
|
|
68
|
-
);
|
|
71
|
+
));
|
|
69
72
|
|
|
70
73
|
// @ts-ignore
|
|
71
74
|
if (after_each_callback) after_each_callback();
|
|
@@ -91,10 +94,10 @@ export class Expectation<T> extends Tests {
|
|
|
91
94
|
|
|
92
95
|
this.instr = "toBeGreaterThanOrEqualTo";
|
|
93
96
|
|
|
94
|
-
this.left
|
|
95
|
-
this.right
|
|
97
|
+
this.left.set(visualize<T>(this._left));
|
|
98
|
+
this.right.set(visualize<T>(
|
|
96
99
|
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
|
|
97
|
-
);
|
|
100
|
+
));
|
|
98
101
|
|
|
99
102
|
// @ts-ignore
|
|
100
103
|
if (after_each_callback) after_each_callback();
|
|
@@ -120,10 +123,10 @@ export class Expectation<T> extends Tests {
|
|
|
120
123
|
|
|
121
124
|
this.instr = "toBeLessThan";
|
|
122
125
|
|
|
123
|
-
this.left
|
|
124
|
-
this.right
|
|
126
|
+
this.left.set(visualize<T>(this._left));
|
|
127
|
+
this.right.set(visualize<T>(
|
|
125
128
|
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
|
|
126
|
-
);
|
|
129
|
+
));
|
|
127
130
|
|
|
128
131
|
// @ts-ignore
|
|
129
132
|
if (after_each_callback) after_each_callback();
|
|
@@ -149,10 +152,10 @@ export class Expectation<T> extends Tests {
|
|
|
149
152
|
|
|
150
153
|
this.instr = "toBeLessThanOrEqualTo";
|
|
151
154
|
|
|
152
|
-
this.left
|
|
153
|
-
this.right
|
|
155
|
+
this.left.set(visualize<T>(this._left));
|
|
156
|
+
this.right.set(visualize<T>(
|
|
154
157
|
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
|
|
155
|
-
);
|
|
158
|
+
));
|
|
156
159
|
|
|
157
160
|
// @ts-ignore
|
|
158
161
|
if (after_each_callback) after_each_callback();
|
|
@@ -167,8 +170,8 @@ export class Expectation<T> extends Tests {
|
|
|
167
170
|
toBeString(): void {
|
|
168
171
|
this.verdict = isString<T>() ? "ok" : "fail";
|
|
169
172
|
|
|
170
|
-
this.left
|
|
171
|
-
this.right
|
|
173
|
+
this.left.set(nameof<T>());
|
|
174
|
+
this.right.set("string");
|
|
172
175
|
|
|
173
176
|
this.instr = "toBeString";
|
|
174
177
|
|
|
@@ -185,8 +188,8 @@ export class Expectation<T> extends Tests {
|
|
|
185
188
|
toBeBoolean(): void {
|
|
186
189
|
this.verdict = isBoolean<T>() ? "ok" : "fail";
|
|
187
190
|
|
|
188
|
-
this.left
|
|
189
|
-
this.right
|
|
191
|
+
this.left.set(nameof<T>());
|
|
192
|
+
this.right.set("boolean");
|
|
190
193
|
|
|
191
194
|
this.instr = "toBeBoolean";
|
|
192
195
|
|
|
@@ -203,8 +206,8 @@ export class Expectation<T> extends Tests {
|
|
|
203
206
|
toBeArray(): void {
|
|
204
207
|
this.verdict = isArray<T>() ? "ok" : "fail";
|
|
205
208
|
|
|
206
|
-
this.left
|
|
207
|
-
this.right
|
|
209
|
+
this.left.set(nameof<T>());
|
|
210
|
+
this.right.set("Array<any>");
|
|
208
211
|
|
|
209
212
|
this.instr = "toBeArray";
|
|
210
213
|
|
|
@@ -221,8 +224,8 @@ export class Expectation<T> extends Tests {
|
|
|
221
224
|
toBeNumber(): void {
|
|
222
225
|
this.verdict = isFloat<T>() || isInteger<T>() ? "ok" : "fail";
|
|
223
226
|
|
|
224
|
-
this.left
|
|
225
|
-
this.right
|
|
227
|
+
this.left.set(nameof<T>());
|
|
228
|
+
this.right.set("number");
|
|
226
229
|
|
|
227
230
|
this.instr = "toBeNumber";
|
|
228
231
|
|
|
@@ -239,8 +242,8 @@ export class Expectation<T> extends Tests {
|
|
|
239
242
|
toBeInteger(): void {
|
|
240
243
|
this.verdict = isInteger<T>() ? "ok" : "fail";
|
|
241
244
|
|
|
242
|
-
this.left
|
|
243
|
-
this.right
|
|
245
|
+
this.left.set(nameof<T>());
|
|
246
|
+
this.right.set("float");
|
|
244
247
|
|
|
245
248
|
this.instr = "toBeInteger";
|
|
246
249
|
|
|
@@ -257,8 +260,8 @@ export class Expectation<T> extends Tests {
|
|
|
257
260
|
toBeFloat(): void {
|
|
258
261
|
this.verdict = isFloat<T>() ? "ok" : "fail";
|
|
259
262
|
|
|
260
|
-
this.left
|
|
261
|
-
this.right
|
|
263
|
+
this.left.set(nameof<T>());
|
|
264
|
+
this.right.set("integer");
|
|
262
265
|
|
|
263
266
|
this.instr = "toBeFloat";
|
|
264
267
|
|
|
@@ -277,8 +280,8 @@ export class Expectation<T> extends Tests {
|
|
|
277
280
|
// @ts-ignore
|
|
278
281
|
(isFloat<T>() || isInteger<T>()) && isFinite(this._left) ? "ok" : "fail";
|
|
279
282
|
|
|
280
|
-
this.left
|
|
281
|
-
this.right
|
|
283
|
+
this.left.set("Infinity");
|
|
284
|
+
this.right.set("Finite");
|
|
282
285
|
|
|
283
286
|
this.instr = "toBeFinite";
|
|
284
287
|
|
|
@@ -300,8 +303,8 @@ export class Expectation<T> extends Tests {
|
|
|
300
303
|
isArray<T>() && this._left.length == value ? "ok" : "fail";
|
|
301
304
|
|
|
302
305
|
// @ts-ignore
|
|
303
|
-
this.left
|
|
304
|
-
this.right
|
|
306
|
+
this.left.set(this._left.length.toString());
|
|
307
|
+
this.right.set(value.toString());
|
|
305
308
|
|
|
306
309
|
this.instr = "toHaveLength";
|
|
307
310
|
|
|
@@ -323,9 +326,8 @@ export class Expectation<T> extends Tests {
|
|
|
323
326
|
// @ts-ignore
|
|
324
327
|
isArray<T>() && this._left.includes(value) ? "ok" : "fail";
|
|
325
328
|
|
|
326
|
-
|
|
327
|
-
this.
|
|
328
|
-
this.right = "does not include value";
|
|
329
|
+
this.left.set("includes value");
|
|
330
|
+
this.right.set("does not include value");
|
|
329
331
|
this.instr = "toContain";
|
|
330
332
|
|
|
331
333
|
// @ts-ignore
|
|
@@ -340,33 +342,38 @@ export class Expectation<T> extends Tests {
|
|
|
340
342
|
* @returns - void
|
|
341
343
|
*/
|
|
342
344
|
toBe(equals: T): void {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
equals
|
|
346
|
-
|
|
347
|
-
);
|
|
348
|
-
if (isBoolean<T>()) {
|
|
345
|
+
if (isArray<T>()) {
|
|
346
|
+
// @ts-ignore
|
|
347
|
+
this.verdict = arrayEquals(this._left, equals) ? "ok" : "fail";
|
|
348
|
+
} else if (isBoolean<T>()) {
|
|
349
349
|
this.verdict = this._left === equals ? "ok" : "fail";
|
|
350
350
|
} else if (isString<T>()) {
|
|
351
351
|
this.verdict = this._left === equals ? "ok" : "fail";
|
|
352
352
|
} else if (isInteger<T>() || isFloat<T>()) {
|
|
353
353
|
this.verdict = this._left === equals ? "ok" : "fail";
|
|
354
|
-
} else if (isArray<T>()) {
|
|
355
|
-
// getArrayDepth<T>();
|
|
356
354
|
} else {
|
|
357
355
|
this.verdict = "none";
|
|
358
356
|
}
|
|
359
357
|
|
|
360
358
|
this.instr = "toBe";
|
|
361
359
|
|
|
362
|
-
this.left
|
|
363
|
-
this.right
|
|
364
|
-
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
|
|
365
|
-
);
|
|
360
|
+
this.left.set(JSON.stringify<T>(this._left));
|
|
361
|
+
this.right.set(JSON.stringify<T>(equals));
|
|
366
362
|
|
|
367
363
|
// @ts-ignore
|
|
368
364
|
if (after_each_callback) after_each_callback();
|
|
369
365
|
// @ts-ignore
|
|
370
366
|
if (before_each_callback) before_each_callback();
|
|
367
|
+
|
|
368
|
+
// store<T>(
|
|
369
|
+
// changetype<usize>(this),
|
|
370
|
+
// equals,
|
|
371
|
+
// offsetof<Expectation<T>>("_right"),
|
|
372
|
+
// );
|
|
371
373
|
}
|
|
372
374
|
}
|
|
375
|
+
|
|
376
|
+
function arrayEquals<T extends any[]>(a: T, b: T): boolean {
|
|
377
|
+
if (a.length != b.length) return false;
|
|
378
|
+
return JSON.stringify(a) == JSON.stringify(b);
|
|
379
|
+
}
|
package/assembly/src/tests.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { JSON } from "json-as";
|
|
1
2
|
|
|
2
3
|
@json
|
|
3
4
|
export class Tests {
|
|
4
5
|
public order: i32 = 0;
|
|
5
|
-
public type
|
|
6
|
+
public type: string = "";
|
|
6
7
|
public verdict: string = "none";
|
|
7
|
-
public left:
|
|
8
|
-
public right:
|
|
8
|
+
public left: JSON.Raw = JSON.Raw.from("");
|
|
9
|
+
public right: JSON.Raw = JSON.Raw.from("");
|
|
9
10
|
public instr: string = "";
|
|
10
11
|
}
|
package/assembly/util/helpers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { rainbow } from "as-rainbow";
|
|
2
|
+
import { JSON } from "json-as";
|
|
2
3
|
|
|
3
4
|
export function visualize<T>(value: T): string {
|
|
4
5
|
if (isNullable<T>() && changetype<usize>(value) == <usize>0) {
|
|
@@ -11,6 +12,18 @@ export function visualize<T>(value: T): string {
|
|
|
11
12
|
} else if (isInteger<T>() || isFloat<T>()) {
|
|
12
13
|
// @ts-ignore
|
|
13
14
|
return value.toString();
|
|
15
|
+
} else if (isArray<T>()) {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
if (!value.length) return "[]";
|
|
18
|
+
let out = "[";
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
for (let i = 0; i < value.length - 1; i++) {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
out += visualize<valueof<T>>(value[i]);
|
|
23
|
+
}
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
out += visualize<valueof<T>>(value[value.length - 1]);
|
|
26
|
+
return out;
|
|
14
27
|
}
|
|
15
28
|
|
|
16
29
|
return unreachable();
|
package/bin/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const _args = process.argv.slice(2);
|
|
|
7
7
|
const flags = [];
|
|
8
8
|
const args = [];
|
|
9
9
|
const COMMANDS = ["run", "build", "test", "init"];
|
|
10
|
-
const version = "0.3.
|
|
10
|
+
const version = "0.3.5";
|
|
11
11
|
for (const arg of _args) {
|
|
12
12
|
if (arg.startsWith("-")) flags.push(arg);
|
|
13
13
|
else args.push(arg);
|
package/bin/init.js
CHANGED
|
@@ -9,7 +9,7 @@ export async function init(args) {
|
|
|
9
9
|
input: process.stdin,
|
|
10
10
|
output: process.stdout,
|
|
11
11
|
});
|
|
12
|
-
console.log(chalk.bold("as-test init v0.3.
|
|
12
|
+
console.log(chalk.bold("as-test init v0.3.5") + "\n");
|
|
13
13
|
console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
|
|
14
14
|
const target = await ask(chalk.dim(" -> "), rl);
|
|
15
15
|
if (!TARGETS.includes(target)) {
|
|
@@ -182,7 +182,7 @@ const exports = instantiate(module, {});`,
|
|
|
182
182
|
}
|
|
183
183
|
if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
|
|
184
184
|
if (!pkg["devDependencies"]["as-test"])
|
|
185
|
-
pkg["devDependencies"]["as-test"] = "^0.3.
|
|
185
|
+
pkg["devDependencies"]["as-test"] = "^0.3.5";
|
|
186
186
|
if (target == "bindings") {
|
|
187
187
|
pkg["type"] = "module";
|
|
188
188
|
}
|
package/bin/run.js
CHANGED
|
@@ -35,7 +35,7 @@ export async function run() {
|
|
|
35
35
|
chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `),
|
|
36
36
|
);
|
|
37
37
|
console.log(
|
|
38
|
-
chalk.dim("\n------------------- v0.3.
|
|
38
|
+
chalk.dim("\n------------------- v0.3.5 -------------------\n"),
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
41
|
for (const plugin of Object.keys(config.plugins)) {
|
|
@@ -114,10 +114,10 @@ export async function run() {
|
|
|
114
114
|
);
|
|
115
115
|
for (const test of failed.tests) {
|
|
116
116
|
const diffResult = diff(
|
|
117
|
-
JSON.stringify(test.
|
|
118
|
-
JSON.stringify(test.
|
|
117
|
+
JSON.stringify(test.left),
|
|
118
|
+
JSON.stringify(test.right),
|
|
119
119
|
);
|
|
120
|
-
let expected = chalk.dim(JSON.stringify(test.
|
|
120
|
+
let expected = chalk.dim(JSON.stringify(test.left));
|
|
121
121
|
let received = "";
|
|
122
122
|
for (const res of diffResult.diff) {
|
|
123
123
|
switch (res.type) {
|