as-test 0.1.4 → 0.1.6

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.
@@ -1,25 +1,26 @@
1
- name: Node.js CI
1
+ name: Bun/Wasmtime CI
2
2
 
3
3
  on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
-
8
7
  runs-on: ubuntu-latest
9
8
 
10
9
  steps:
11
10
  - name: Checkout the repository
12
11
  uses: actions/checkout@v4
13
-
12
+
14
13
  - name: Install Wasmtime
15
14
  uses: jcbhmr/setup-wasmtime@v2
16
15
 
17
- - name: Setup Node.js
18
- uses: actions/setup-node@v2
16
+ - name: Setup Bun
17
+ uses: oven-sh/setup-bun@v1
19
18
 
20
19
  - name: Install dependencies
21
- if: steps.node-cache.outputs.cache-hit != 'true'
22
- run: yarn
20
+ run: bun install
21
+
22
+ - name: Build tests
23
+ run: bun run pretest
23
24
 
24
- - name: Perform tests
25
- run: yarn run test
25
+ - name: Run tests
26
+ run: bun run test
package/.prettierrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "plugins": ["assemblyscript-prettier"]
3
+ }
package/CHANGELOG.md CHANGED
@@ -11,4 +11,7 @@ v0.0.9 - Fix type issue
11
11
  v0.1.0 - Fix more type issues
12
12
  v0.1.1 - Add code coverage!
13
13
  v0.1.2 - Fix bugs with globals and dependencies
14
- v0.1.3 - Revamp `log<T>(data: T)` with new as-console version
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
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  | _ || __| ___|_ _|| __|| __||_ _|
4
4
  | ||__ ||___| | | | __||__ | | |
5
5
  |__|__||_____| |_| |_____||_____| |_|
6
- v0.1.4
6
+ v0.1.6
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -13,26 +13,21 @@ v0.1.4
13
13
  npm install as-test
14
14
  ```
15
15
 
16
- Add the transform to your `asc` command (e.g. in package.json)
16
+ Note: The transform _is_ OPTIONAL, though it is required to enable code coverage.
17
17
 
18
- ```bash
19
- --transform as-test/transform
20
- ```
18
+ ## Usage
21
19
 
22
- Alternatively, add it to your `asconfig.json`
20
+ You can setup the configuration files using
23
21
 
24
- ```
25
- {
26
- // ...
27
- "options": {
28
- "transform": ["as-test/transform"]
29
- }
30
- }
22
+ ```bash
23
+ as-test init
31
24
  ```
32
25
 
33
- Note: The transform *is* OPTIONAL, though it is required to enable code coverage.
26
+ Note: You can use either `ast` or `as-test` in the terminal.
34
27
 
35
- ## Usage
28
+ Next, create a test file
29
+
30
+ `assembly/__tests__/test.spec.ts`
36
31
 
37
32
  ```js
38
33
  import {
@@ -101,62 +96,21 @@ describe("Array manipulation", () => {
101
96
  });
102
97
 
103
98
  run({
104
- log: false,
105
- coverage: true
99
+ log: true
106
100
  });
107
101
  ```
108
102
 
109
- <h6>
110
- <pre> _____ _____ _____ _____ _____ _____
111
- | _ || __| ___|_ _|| __|| __||_ _|
112
- | ||__ ||___| | | | __||__ | | |
113
- |__|__||_____| |_| |_____||_____| |_|
114
-
115
- -----------------------------------------
116
-
117
- [PASS] Math operations
118
-
119
- [PASS] Array manipulation
120
-
121
- [PASS] Addition
103
+ Build and run it using as-test
122
104
 
123
- [PASS] Comparison
124
-
125
- [PASS] Type checking
126
-
127
- [PASS] Array length
128
-
129
- [PASS] Array inclusion
130
-
131
- -----------------------------------------
105
+ ```bash
106
+ as-test test
107
+ ```
132
108
 
133
- Test Suites: 0 failed, 2 total
134
- Tests: 0 failed, 8 total
135
- Coverage: 0 failed, 23 total
136
- Snapshots: 0 total
137
- Time: 101.812μs
138
- </pre>z
139
- </h6>
109
+ <h6>
140
110
 
141
111
  ## Running
142
112
 
143
- 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.
144
-
145
- To add WASI support, install it with
146
-
147
- ```
148
- npm install @assemblyscript/wasi-shim
149
- ```
150
-
151
- Add the following scripts to your `package.json` where NAME-HERE is your test file.
152
- You can swap out `wasmtime` with [Node.js](https://nodejs.org/), [Wasmer](https://wasmer.io/), [Wasm3](https://github.com/wasm3/wasm3), or any WASI-supporting runtime
153
-
154
- ```json
155
- "scripts": {
156
- "test": "wasmtime ./build/NAME.spec.wasm",
157
- "pretest": "asc asc NAME.spec.ts -o build/NAME.spec.wasm --bindings esm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json"
158
- }
159
- ```
113
+ 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.
160
114
 
161
115
  And finally, run it with:
162
116
 
@@ -168,7 +122,6 @@ To add `as-test` to your CI/CD workflow, check out [The provided example](https:
168
122
 
169
123
  If you use this project in your codebase, consider dropping a [⭐ HERE](https://github.com/JairusSW/as-test). I would really appreciate it!
170
124
 
171
-
172
125
  ## Notes
173
126
 
174
127
  This library is in the EARLY STAGES OF DEVELOPMENT!
@@ -186,4 +139,4 @@ Discord: `jairussw`
186
139
 
187
140
  ## Issues
188
141
 
189
- Please submit an issue to https://github.com/JairusSW/as-test/issues if you find anything wrong with this library
142
+ Please submit an issue to https://github.com/JairusSW/as-test/issues if you find anything wrong with this library
@@ -0,0 +1,22 @@
1
+ {
2
+ "input": ["./assembly/__tests__/*.spec.ts"],
3
+ "outDir": "./build",
4
+ "config": "./asconfig.json",
5
+ "suites": [],
6
+ "coverage": {
7
+ "enabled": true,
8
+ "show": false
9
+ },
10
+ "buildOptions": {
11
+ "args": [],
12
+ "wasi": true,
13
+ "parallel": true,
14
+ "verbose": true
15
+ },
16
+ "runOptions": {
17
+ "runtime": {
18
+ "name": "wasmtime",
19
+ "run": "wasmtime <file>"
20
+ }
21
+ }
22
+ }
package/asconfig.json CHANGED
@@ -1,36 +1,33 @@
1
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
- }
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
27
10
  },
28
- "options": {
29
- "transform": ["./transform"],
30
- "disableWarning": [
31
- 226
32
- ]
11
+ "debug": {
12
+ "outFile": "build/test.wasm",
13
+ "sourceMap": false,
14
+ "optimizeLevel": 0,
15
+ "shrinkLevel": 0,
16
+ "converge": false,
17
+ "noAssert": false
33
18
  },
34
- "extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
35
- }
36
-
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": [226]
31
+ },
32
+ "extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
33
+ }
@@ -0,0 +1,70 @@
1
+ import {
2
+ describe,
3
+ expect,
4
+ test, // Alias for `it`
5
+ beforeAll,
6
+ afterAll,
7
+ beforeEach,
8
+ afterEach,
9
+ log,
10
+ run,
11
+ } from "..";
12
+
13
+ // Shared setup for all tests (executed once before all tests)
14
+ beforeAll(() => {
15
+ log("Setting up test environment...");
16
+ });
17
+
18
+ // Shared teardown for all tests (executed once after all tests)
19
+ afterAll(() => {
20
+ log("Tearing down test environment...");
21
+ });
22
+
23
+ describe("Math operations", () => {
24
+ // Setup before each test in this group (optional)
25
+ beforeEach(() => {
26
+ log("Initializing test...");
27
+ });
28
+
29
+ // Teardown after each test in this group (optional)
30
+ afterEach(() => {
31
+ log("Cleaning up after test...");
32
+ });
33
+
34
+ test("Addition", () => {
35
+ expect(1 + 2).toBe(3);
36
+ });
37
+
38
+ test("Comparison", () => {
39
+ expect(5).toBeGreaterThan(3);
40
+ expect(2).toBeLessThan(4);
41
+ });
42
+
43
+ test("Type checking", () => {
44
+ expect("hello").toBeString();
45
+ expect(true).toBeBoolean();
46
+ expect(10.5).toBeNumber();
47
+ });
48
+ });
49
+
50
+ let myArray: i32[] = [];
51
+
52
+ describe("Array manipulation", () => {
53
+ beforeAll(() => {
54
+ myArray = [1, 2, 3];
55
+ });
56
+
57
+ test("Array length", () => {
58
+ expect(myArray).toHaveLength(3);
59
+ });
60
+
61
+ test("Array inclusion", () => {
62
+ expect(myArray).toContain(2);
63
+ });
64
+ });
65
+
66
+ function foo(): void {}
67
+
68
+ run({
69
+ log: false,
70
+ });
@@ -1,31 +1,31 @@
1
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;
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
8
  }
9
9
 
10
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();
11
+ public hashes: Map<string, CoverPoint> = new Map<string, CoverPoint>();
12
+ public points: i32 = 0;
13
+ static SN: Coverage = new Coverage();
14
14
  }
15
15
 
16
16
  export function __REGISTER(point: CoverPoint): void {
17
- Coverage.SN.points++;
18
- Coverage.SN.hashes.set(point.hash, point);
17
+ Coverage.SN.points++;
18
+ Coverage.SN.hashes.set(point.hash, point);
19
19
  }
20
20
 
21
21
  export function __COVER(hash: string): void {
22
- if (Coverage.SN.hashes.has(hash)) Coverage.SN.hashes.delete(hash);
22
+ if (Coverage.SN.hashes.has(hash)) Coverage.SN.hashes.delete(hash);
23
23
  }
24
24
 
25
25
  export function __HASHES(): Map<string, CoverPoint> {
26
- return Coverage.SN.hashes;
26
+ return Coverage.SN.hashes;
27
27
  }
28
28
 
29
29
  export function __POINTS(): i32 {
30
- return Coverage.SN.points;
31
- }
30
+ return Coverage.SN.points;
31
+ }