as-test 0.0.9 → 0.1.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 CHANGED
@@ -5,4 +5,8 @@ v0.0.3 - Added `afterEach`, `beforeEach`, `afterAll`, `beforeAll`, `test`, `it`,
5
5
  v0.0.4 - Fix import issue in README usage section
6
6
  v0.0.5 - Switch errors to be thrown at compile time instead of runtime
7
7
  v0.0.6 - Failed tests should be pushed to bottom of logs
8
- v0.0.8 - Fix readme typo in v0.0.7
8
+ v0.0.8 - Fix readme typo in v0.0.7
9
+ v0.0.9 - Fix type issue
10
+
11
+ v0.1.0 - Fix more type issues
12
+ v0.1.1 - Add code coverage!
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  | _ || __| ___|_ _|| __|| __||_ _|
4
4
  | ||__ ||___| | | | __||__ | | |
5
5
  |__|__||_____| |_| |_____||_____| |_|
6
- v0.0.9
6
+ v0.1.1
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -13,6 +13,25 @@ v0.0.9
13
13
  npm install as-test
14
14
  ```
15
15
 
16
+ Add the transform to your `asc` command (e.g. in package.json)
17
+
18
+ ```bash
19
+ --transform json-as/transform
20
+ ```
21
+
22
+ Alternatively, add it to your `asconfig.json`
23
+
24
+ ```
25
+ {
26
+ // ...
27
+ "options": {
28
+ "transform": ["json-as/transform"]
29
+ }
30
+ }
31
+ ```
32
+
33
+ Note: The transform *is* OPTIONAL, though it is required to enable code coverage.
34
+
16
35
  ## Usage
17
36
 
18
37
  ```js
@@ -82,7 +101,8 @@ describe("Array manipulation", () => {
82
101
  });
83
102
 
84
103
  run({
85
- log: false
104
+ log: false,
105
+ coverage: true
86
106
  });
87
107
  ```
88
108
 
@@ -112,6 +132,7 @@ run({
112
132
 
113
133
  Test Suites: 0 failed, 2 total
114
134
  Tests: 0 failed, 8 total
135
+ Coverage: 0 failed, 23 total
115
136
  Snapshots: 0 total
116
137
  Time: 101.812μs
117
138
  </pre>
@@ -147,6 +168,7 @@ To add `as-test` to your CI/CD workflow, check out [The provided example](https:
147
168
 
148
169
  If you use this project in your codebase, consider dropping a [⭐ HERE](https://github.com/JairusSW/as-test). I would really appreciate it!
149
170
 
171
+
150
172
  ## Notes
151
173
 
152
174
  This library is in the EARLY STAGES OF DEVELOPMENT!
package/asconfig.json ADDED
@@ -0,0 +1,36 @@
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
+ }
27
+ },
28
+ "options": {
29
+ "transform": ["./transform"],
30
+ "disableWarning": [
31
+ 226
32
+ ]
33
+ },
34
+ "extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
35
+ }
36
+
package/assembly/index.ts CHANGED
@@ -3,6 +3,7 @@ import { TestGroup } from "./src/group";
3
3
  import { Expectation } from "./src/expectation";
4
4
  import { formatTime } from "./util";
5
5
  import { stringify } from "as-console/assembly";
6
+ import { __COVERAGE } from "./src/coverage";
6
7
 
7
8
  /**
8
9
  * Enumeration representing the verdict of a test case.
@@ -184,7 +185,8 @@ export function afterEach(callback: () => void): void {
184
185
  * - `log` (boolean, default: true): Controls whether enable the log() function
185
186
  **/
186
187
  class RunOptions {
187
- log: boolean = true
188
+ log: boolean = true;
189
+ coverage: boolean = false;
188
190
  }
189
191
 
190
192
  /**
@@ -210,11 +212,14 @@ class RunOptions {
210
212
  */
211
213
  export function run(options: RunOptions = new RunOptions()): void {
212
214
  __test_options = options;
213
- console.log(rainbow.boldMk(rainbow.green(` _____ _____ _____ _____ _____ _____ `)));
214
- console.log(rainbow.boldMk(rainbow.green(`| _ || __| ___|_ _|| __|| __||_ _|`)));
215
- console.log(rainbow.boldMk(rainbow.green(`| ||__ ||___| | | | __||__ | | | `)));
216
- console.log(rainbow.boldMk(rainbow.green(`|__|__||_____| |_| |_____||_____| |_| `)));
217
- console.log(rainbow.dimMk ("\n------------------- v0.0.9 -------------------\n"));
215
+ console.log(rainbow.boldMk(rainbow.blueBright(` _____ _____ _____ _____ _____ _____ `)));
216
+ console.log(rainbow.boldMk(rainbow.blueBright(`| _ || __| ___|_ _|| __|| __||_ _|`)));
217
+ console.log(rainbow.boldMk(rainbow.blueBright(`| ||__ ||___| | | | __||__ | | | `)));
218
+ console.log(rainbow.boldMk(rainbow.blueBright(`|__|__||_____| |_| |_____||_____| |_| `)));
219
+ console.log(rainbow.dimMk("\n------------------- v0.1.1 -------------------\n"));
220
+ if (options.coverage) {
221
+ console.log(rainbow.bgBlueBright(" PLUGIN ") + " " + rainbow.dimMk("Using Code Coverage") + "\n");
222
+ }
218
223
  const suites = groups.length;
219
224
  let failed = 0;
220
225
  let tests = 0;
@@ -259,16 +264,32 @@ export function run(options: RunOptions = new RunOptions()): void {
259
264
  if (failed) {
260
265
  console.log(rainbow.red("------------------ [FAILED] ------------------\n"));
261
266
  console.log(failed_suite_logs);
262
- console.log(rainbow.red("----------------- [RESULTS] ------------------\n"));
263
- } else {
264
- console.log(rainbow.dimMk("----------------- [RESULTS] ------------------\n"));
265
267
  }
268
+
269
+ // @ts-ignore
270
+ const cv = __COVERAGE_STATS();
271
+ const COVER_POINTS = cv.hashs;
272
+ const COVER_TOTAL_POINTS = cv.points;
273
+
274
+ if (options.coverage && COVER_POINTS.size) {
275
+ console.log(rainbow.dimMk("----------------- [COVERAGE] -----------------\n"));
276
+ const points = COVER_POINTS.values();
277
+
278
+ for (let i = 0; i < points.length; i++) {
279
+ const point = unchecked(points[i]);
280
+ console.log(rainbow.bgRed(" UNCOVERED ") + " " + point.type + " at " + point.file + ":" + point.line.toString() + ":" + point.column.toString());
281
+ }
282
+ console.log("");
283
+ }
284
+
285
+ console.log(rainbow.dimMk("----------------- [RESULTS] ------------------\n"));
266
286
  const ms = performance.now() - start;
267
- console.log(rainbow.boldMk("Test Suites: ") + (failed ? rainbow.boldMk(rainbow.red(failed.toString() + " failed")) : rainbow.boldMk(rainbow.green(failed.toString() + " failed"))) + ", " + suites.toString() + " total");
268
- console.log(rainbow.boldMk("Tests: ") + (failed_tests ? rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) : rainbow.boldMk(rainbow.green(failed_tests.toString() + " failed"))) + ", " + tests.toString() + " total");
287
+ console.log(rainbow.boldMk("Test Suites: ") + (failed ? rainbow.boldMk(rainbow.red(failed.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + suites.toString() + " total");
288
+ console.log(rainbow.boldMk("Tests: ") + (failed_tests ? rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + COVER_TOTAL_POINTS.toString() + " total");
289
+ if (options.coverage) console.log(rainbow.boldMk("Coverage: ") + (COVER_POINTS.size ? rainbow.boldMk(rainbow.red(COVER_POINTS.size.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + COVER_TOTAL_POINTS.toString() + " total");
269
290
  console.log(rainbow.boldMk("Snapshots: ") + "0 total");
270
291
  console.log(rainbow.boldMk("Time: ") + formatTime(ms));
271
292
  if (failed) {
272
- process.exit(1)
293
+ process.exit(1);
273
294
  }
274
295
  }
@@ -0,0 +1,39 @@
1
+ export namespace __COVERTYPES {
2
+ export const Function = "Function";
3
+ export const Expression = "Expression";
4
+ export const Block = "Block";
5
+ }
6
+
7
+ export class __COVERPOINT {
8
+ public file: string = "";
9
+ public hash: string = "";
10
+ public line: i32 = 0;
11
+ public column: i32 = 0;
12
+ public type!: string;
13
+ public executed: boolean = false;
14
+ }
15
+
16
+ export class __COVERAGE {
17
+ public hashs: Map<string, __COVERPOINT> = new Map<string, __COVERPOINT>();
18
+ public points: i32 = 0;
19
+ static SN: __COVERAGE | null = null;
20
+ static init(): __COVERAGE {
21
+ if (!__COVERAGE.SN) {
22
+ __COVERAGE.SN = new __COVERAGE();
23
+ }
24
+ return __COVERAGE.SN!;
25
+ }
26
+ }
27
+
28
+ export function __COVERAGE_STATS(): __COVERAGE {
29
+ return __COVERAGE.init();
30
+ }
31
+
32
+ export function __REGISTER(point: __COVERPOINT): void {
33
+ __COVERAGE.init().points++;
34
+ __COVERAGE.init().hashs.set(point.hash, point);
35
+ }
36
+
37
+ export function __COVER(hash: string): void {
38
+ __COVERAGE.init().hashs.delete(hash);
39
+ }
@@ -2,7 +2,7 @@ import { Verdict } from "..";
2
2
 
3
3
  export class Node {
4
4
  public verdict: Verdict = Verdict.Unreachable;
5
- report(): ReportLogs | null {
5
+ report(): string | null {
6
6
  return null;
7
7
  }
8
8
  }
package/assembly/test.ts CHANGED
@@ -63,6 +63,11 @@ describe("Array manipulation", () => {
63
63
  });
64
64
  });
65
65
 
66
+ export function foo(): void {
67
+
68
+ }
69
+
66
70
  run({
67
- log: false
71
+ log: false,
72
+ coverage: true
68
73
  });
package/coverage.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./assembly/src/coverage";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.0.9",
3
+ "version": "0.1.1",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -8,23 +8,36 @@
8
8
  "license": "MIT",
9
9
  "scripts": {
10
10
  "test": "wasmtime ./build/test.wasm",
11
- "pretest": "asc assembly/test.ts -o build/test.wasm --bindings esm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
12
- "build:bench": "asc assembly/bench/bench.ts -o build/bench.wasm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --optimizeLevel 3 --converge --exportRuntime --runtime stub",
11
+ "pretest": "TEST_DEBUG=all asc assembly/test.ts -o build/test.wasm --transform ./transform --bindings esm --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
13
12
  "bench:wasmtime": "wasmtime ./build/bench.wasm",
14
13
  "build:transform": "tsc -p ./transform",
15
14
  "prettier": "as-prettier -w ."
16
15
  },
17
16
  "devDependencies": {
17
+ "as-test": "./",
18
18
  "@assemblyscript/wasi-shim": "^0.1.0",
19
+ "@types/micromatch": "^4.0.7",
19
20
  "assemblyscript": "^0.27.22",
20
21
  "assemblyscript-prettier": "^3.0.1",
21
22
  "jest": "^29.7.0",
22
23
  "typescript": "^5.3.3",
23
24
  "visitor-as": "^0.11.4"
24
25
  },
25
- "dependencies": { "as-console": "^6.0.2", "as-convert-seconds": "^1.0.0", "as-rainbow": "^0.1.0", "as-string-sink": "^0.5.3", "as-variant": "^0.4.1", "json-as": "^0.9.6" },
26
+ "dependencies": {
27
+ "as-console": "^6.0.2",
28
+ "as-convert-seconds": "^1.0.0",
29
+ "as-rainbow": "^0.1.0",
30
+ "as-string-sink": "^0.5.3",
31
+ "as-variant": "^0.4.1",
32
+ "chalk": "^5.3.0",
33
+ "json-as": "^0.9.6",
34
+ "line-column": "^1.0.2",
35
+ "micromatch": "^4.0.7",
36
+ "yargs": "^17.7.2"
37
+ },
26
38
  "overrides": {
27
- "assemblyscript": "$assemblyscript"
39
+ "assemblyscript": "$assemblyscript",
40
+ "visitor-as": "$visitor-as"
28
41
  },
29
42
  "repository": {
30
43
  "type": "git",
package/src/cli.ts ADDED
@@ -0,0 +1,10 @@
1
+ import yargs, { Arguments } from 'yargs';
2
+ import { hideBin } from 'yargs/helpers'
3
+
4
+ const cli = yargs(hideBin(process.argv));
5
+
6
+ cli.command('build <options>', 'options', () => {}, (argv) => {
7
+ console.info(argv)
8
+ })
9
+ .demandCommand(1)
10
+ .parse()
File without changes