as-test 0.2.1 → 0.3.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +75 -68
  3. package/as-test.config.json +7 -10
  4. package/assembly/__tests__/array.spec.ts +19 -0
  5. package/assembly/__tests__/math.spec.ts +16 -0
  6. package/assembly/__tests__/sleep.spec.ts +28 -0
  7. package/assembly/index.ts +181 -165
  8. package/assembly/src/expectation.ts +119 -112
  9. package/assembly/src/log.ts +19 -0
  10. package/assembly/src/suite.ts +99 -0
  11. package/assembly/src/tests.ts +10 -0
  12. package/assembly/tsconfig.json +1 -1
  13. package/assembly/util/helpers.ts +0 -33
  14. package/assembly/util/term.ts +55 -0
  15. package/assets/img/screenshot.png +0 -0
  16. package/bin/about.js +135 -0
  17. package/bin/build.js +72 -131
  18. package/bin/index.js +70 -112
  19. package/bin/init.js +211 -39
  20. package/bin/reporter.js +1 -0
  21. package/bin/run.js +226 -68
  22. package/bin/types.js +25 -31
  23. package/bin/util.js +44 -20
  24. package/cli/build.ts +70 -109
  25. package/cli/index.ts +148 -159
  26. package/cli/init.ts +235 -34
  27. package/cli/reporter.ts +1 -0
  28. package/cli/run.ts +266 -57
  29. package/cli/types.ts +6 -11
  30. package/cli/util.ts +35 -0
  31. package/package.json +5 -2
  32. package/run/package.json +27 -0
  33. package/tests/array.run.js +7 -0
  34. package/tests/math.run.js +7 -0
  35. package/tests/sleep.run.js +7 -0
  36. package/transform/lib/coverage.js +325 -319
  37. package/transform/lib/index.js +51 -31
  38. package/transform/lib/index.js.map +1 -1
  39. package/transform/lib/mock.js +60 -52
  40. package/transform/lib/mock.js.map +1 -1
  41. package/transform/package.json +1 -1
  42. package/transform/src/index.ts +22 -3
  43. package/transform/src/mock.ts +1 -1
  44. package/asconfig.json +0 -31
  45. package/assembly/__tests__/example.spec.ts +0 -79
  46. package/assembly/reporters/tap.ts +0 -30
  47. package/assembly/src/group.ts +0 -44
  48. package/assembly/src/node.ts +0 -13
  49. package/jest.test.js +0 -44
  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
package/CHANGELOG.md CHANGED
@@ -23,4 +23,5 @@ v0.1.10 - Feat: support node, deno, and bun
23
23
  v0.2.0 - Fix mock -> mockFn artifacts
24
24
  v0.2.1 - Remove accidental logging
25
25
 
26
- [UNRELEASED] - Feat: snapshotting
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
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  | _ || __| ___|_ _|| __|| __||_ _|
4
4
  | ||__ ||___| | | | __||__ | | |
5
5
  |__|__||_____| |_| |_____||_____| |_|
6
- v0.2.1
6
+ v0.3.1
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -17,14 +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
-
26
- [Node/Bun/Deno](https://github.com/JairusSW/as-test/tree/template/node-bun-deno)
27
-
28
20
  View the docs: https://docs.jairus.dev/as-test
29
21
 
30
22
  ## Usage
@@ -37,101 +29,116 @@ as-test init
37
29
 
38
30
  Note: You can use either `ast` or `as-test` in the terminal.
39
31
 
40
- Next, create a test file
32
+ Next, take a look at the generated test file
41
33
 
42
- `assembly/__tests__/test.spec.ts`
34
+ `assembly/__tests__/example.spec.ts`
43
35
 
44
36
  ```js
45
37
  import {
46
- describe,
47
- expect,
48
- test,
49
- beforeAll,
50
- afterAll,
51
- beforeEach,
52
- afterEach,
53
- mockFn,
54
- log,
55
- run
38
+ describe,
39
+ expect,
40
+ test,
41
+ beforeAll,
42
+ afterAll,
43
+ mockFn,
44
+ log,
45
+ run,
46
+ it
56
47
  } from "as-test";
57
48
 
58
49
  beforeAll(() => {
59
- log("Setting up test environment...");
50
+ log("Setting up test environment...");
60
51
  });
61
52
 
62
53
  afterAll(() => {
63
- log("Tearing down test environment...");
54
+ log("Tearing down test environment...");
64
55
  });
65
56
 
66
57
  // Mock/override the function console.log
67
58
  mockFn<void>("console.log", (data: string): void => {
68
- 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
+ });
69
85
  });
70
86
 
71
87
  describe("Math operations", () => {
72
- beforeEach(() => {
73
- log("Initializing test...");
74
- });
75
-
76
- afterEach(() => {
77
- log("Cleaning up after test...");
78
- });
79
-
80
- test("Addition", () => {
81
- expect(1 + 2).toBe(3);
82
- });
83
-
84
- test("Comparison", () => {
85
- expect(5).toBeGreaterThan(3);
86
- expect(2).toBeLessThan(4);
87
- });
88
-
89
- test("Type checking", () => {
90
- expect("hello").toBeString();
91
- expect(true).toBeBoolean();
92
- expect(10.5).toBeNumber();
93
- });
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
+ });
94
106
  });
95
107
 
96
- let myArray: i32[] = [];
108
+ let myArray: i32[] = [1, 2, 3];
97
109
 
98
110
  describe("Array manipulation", () => {
99
- beforeAll(() => {
100
- myArray = [1, 2, 3];
101
- });
111
+ test("Array length", () => {
112
+ expect(myArray).toHaveLength(3);
113
+ });
102
114
 
103
- test("Array length", () => {
104
- expect(myArray).toHaveLength(3);
105
- });
115
+ test("Array inclusion", () => {
116
+ expect(myArray).toContain(2);
117
+ });
106
118
 
107
- test("Array inclusion", () => {
108
- expect(myArray).toContain(2);
109
- });
119
+ it("should be empty", () => { });
110
120
  });
111
121
 
112
- run({
113
- log: true
114
- });
122
+ run();
123
+
124
+ function sleep(ms: i64): void {
125
+ const target = Date.now() + ms;
126
+ while (target > Date.now()) { }
127
+ }
115
128
  ```
116
129
 
117
130
  Build and run it using as-test
118
131
 
119
132
  ```bash
120
- as-test test
133
+ npm run test
121
134
  ```
122
135
 
136
+ <img src="https://raw.githubusercontent.com/JairusSW/as-test/main/assets/img/screenshot.png">
137
+
123
138
  <h6>
124
139
 
125
140
  ## Running
126
141
 
127
- 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.
128
-
129
- And finally, run it with:
130
-
131
- ```bash
132
- npm run test
133
- ```
134
-
135
142
  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)
136
143
 
137
144
  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();