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.
Files changed (54) hide show
  1. package/.github/workflows/as-test.yml +3 -0
  2. package/CHANGELOG.md +4 -1
  3. package/README.md +73 -67
  4. package/as-test.config.json +7 -10
  5. package/assembly/__tests__/array.spec.ts +19 -0
  6. package/assembly/__tests__/math.spec.ts +16 -0
  7. package/assembly/__tests__/sleep.spec.ts +28 -0
  8. package/assembly/index.ts +181 -165
  9. package/assembly/src/expectation.ts +119 -112
  10. package/assembly/src/log.ts +19 -0
  11. package/assembly/src/suite.ts +99 -0
  12. package/assembly/src/tests.ts +10 -0
  13. package/assembly/tsconfig.json +1 -1
  14. package/assembly/util/helpers.ts +0 -33
  15. package/assembly/util/term.ts +55 -0
  16. package/assets/img/download.png +0 -0
  17. package/bin/about.js +135 -0
  18. package/bin/build.js +72 -131
  19. package/bin/index.js +70 -112
  20. package/bin/init.js +211 -39
  21. package/bin/reporter.js +1 -0
  22. package/bin/run.js +226 -68
  23. package/bin/types.js +25 -31
  24. package/bin/util.js +44 -20
  25. package/cli/build.ts +70 -109
  26. package/cli/index.ts +148 -159
  27. package/cli/init.ts +235 -34
  28. package/cli/reporter.ts +1 -0
  29. package/cli/run.ts +266 -57
  30. package/cli/types.ts +6 -11
  31. package/cli/util.ts +35 -0
  32. package/package.json +6 -2
  33. package/run/package.json +27 -0
  34. package/tests/array.run.js +7 -0
  35. package/tests/math.run.js +7 -0
  36. package/tests/sleep.run.js +7 -0
  37. package/transform/lib/coverage.js +325 -319
  38. package/transform/lib/index.js +51 -31
  39. package/transform/lib/index.js.map +1 -1
  40. package/transform/lib/mock.js +61 -55
  41. package/transform/lib/mock.js.map +1 -1
  42. package/transform/package.json +1 -1
  43. package/transform/src/index.ts +22 -3
  44. package/transform/src/mock.ts +1 -1
  45. package/asconfig.json +0 -31
  46. package/assembly/__tests__/example.spec.ts +0 -79
  47. package/assembly/reporters/tap.ts +0 -30
  48. package/assembly/src/group.ts +0 -44
  49. package/assembly/src/node.ts +0 -13
  50. package/test.config.json +0 -0
  51. package/tests/test.tap +0 -14
  52. package/unision +0 -38
  53. package/unision.pub +0 -1
  54. package/utils.ts +0 -1
@@ -19,6 +19,9 @@ jobs:
19
19
  - name: Install dependencies
20
20
  run: bun install
21
21
 
22
+ - name: Build reporter
23
+ run: bun run build:log
24
+
22
25
  - name: Build tests
23
26
  run: bun run pretest
24
27
 
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
- [UNRELEASED] - Feat: snapshotting
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.2.0
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, create a test file
32
+ Next, take a look at the generated test file
40
33
 
41
- `assembly/__tests__/test.spec.ts`
34
+ `assembly/__tests__/example.spec.ts`
42
35
 
43
36
  ```js
44
37
  import {
45
- describe,
46
- expect,
47
- test,
48
- beforeAll,
49
- afterAll,
50
- beforeEach,
51
- afterEach,
52
- mockFn,
53
- log,
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
- log("Setting up test environment...");
50
+ log("Setting up test environment...");
59
51
  });
60
52
 
61
53
  afterAll(() => {
62
- log("Tearing down test environment...");
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
- console.log("[MOCKED]: " + data + "\n");
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
- beforeEach(() => {
72
- log("Initializing test...");
73
- });
74
-
75
- afterEach(() => {
76
- log("Cleaning up after test...");
77
- });
78
-
79
- test("Addition", () => {
80
- expect(1 + 2).toBe(3);
81
- });
82
-
83
- test("Comparison", () => {
84
- expect(5).toBeGreaterThan(3);
85
- expect(2).toBeLessThan(4);
86
- });
87
-
88
- test("Type checking", () => {
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
- beforeAll(() => {
99
- myArray = [1, 2, 3];
100
- });
111
+ test("Array length", () => {
112
+ expect(myArray).toHaveLength(3);
113
+ });
101
114
 
102
- test("Array length", () => {
103
- expect(myArray).toHaveLength(3);
104
- });
115
+ test("Array inclusion", () => {
116
+ expect(myArray).toContain(2);
117
+ });
105
118
 
106
- test("Array inclusion", () => {
107
- expect(myArray).toContain(2);
108
- });
119
+ it("should be empty", () => { });
109
120
  });
110
121
 
111
- run({
112
- log: true
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
- as-test test
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!
@@ -1,22 +1,19 @@
1
1
  {
2
2
  "input": ["./assembly/__tests__/*.spec.ts"],
3
3
  "outDir": "./build",
4
- "config": "./asconfig.json",
5
- "suites": [],
6
- "coverage": {
7
- "enabled": true,
8
- "show": false
4
+ "logs": "./logs",
5
+ "config": "none",
6
+ "plugins": {
7
+ "coverage": true
9
8
  },
10
9
  "buildOptions": {
11
10
  "args": [],
12
- "wasi": true,
13
- "parallel": true,
14
- "verbose": true
11
+ "target": "bindings"
15
12
  },
16
13
  "runOptions": {
17
14
  "runtime": {
18
- "name": "wasmtime",
19
- "run": "wasmtime <file>"
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();