as-test 0.1.1 → 0.1.2

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
@@ -9,4 +9,5 @@ v0.0.8 - Fix readme typo in v0.0.7
9
9
  v0.0.9 - Fix type issue
10
10
 
11
11
  v0.1.0 - Fix more type issues
12
- v0.1.1 - Add code coverage!
12
+ v0.1.1 - Add code coverage!
13
+ v0.1.2 - Fix bugs with globals and dependencies
package/README.md CHANGED
@@ -16,7 +16,7 @@ npm install as-test
16
16
  Add the transform to your `asc` command (e.g. in package.json)
17
17
 
18
18
  ```bash
19
- --transform json-as/transform
19
+ --transform as-test/transform
20
20
  ```
21
21
 
22
22
  Alternatively, add it to your `asconfig.json`
@@ -25,7 +25,7 @@ Alternatively, add it to your `asconfig.json`
25
25
  {
26
26
  // ...
27
27
  "options": {
28
- "transform": ["json-as/transform"]
28
+ "transform": ["as-test/transform"]
29
29
  }
30
30
  }
31
31
  ```
@@ -0,0 +1,31 @@
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;
8
+ }
9
+
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();
14
+ }
15
+
16
+ export function __REGISTER(point: CoverPoint): void {
17
+ Coverage.SN.points++;
18
+ Coverage.SN.hashes.set(point.hash, point);
19
+ }
20
+
21
+ export function __COVER(hash: string): void {
22
+ if (Coverage.SN.hashes.has(hash)) Coverage.SN.hashes.delete(hash);
23
+ }
24
+
25
+ export function __HASHES(): Map<string, CoverPoint> {
26
+ return Coverage.SN.hashes;
27
+ }
28
+
29
+ export function __POINTS(): i32 {
30
+ return Coverage.SN.points;
31
+ }
package/assembly/index.ts CHANGED
@@ -3,7 +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
+ import { __COVER, __HASHES, __POINTS } from "as-test/assembly/coverage";
7
7
 
8
8
  /**
9
9
  * Enumeration representing the verdict of a test case.
@@ -21,12 +21,9 @@ let groups: TestGroup[] = [];
21
21
  let before_all_callback: (() => void) | null = null;
22
22
  let after_all_callback: (() => void) | null = null;
23
23
 
24
- // @ts-ignore
25
- @global let before_each_callback: (() => void) | null = null;
26
- // @ts-ignore
27
- @global let after_each_callback: (() => void) | null = null;
28
- // @ts-ignore
29
- @global let __test_options!: RunOptions;
24
+ export let before_each_callback: (() => void) | null = null;
25
+ export let after_each_callback: (() => void) | null = null;
26
+ let __test_options!: RunOptions;
30
27
 
31
28
  /**
32
29
  * Creates a test group containing multiple test cases.
@@ -252,7 +249,7 @@ export function run(options: RunOptions = new RunOptions()): void {
252
249
  console.log(txt);
253
250
  }
254
251
 
255
- const report = suite.report();
252
+ const report = suite.getLogs();
256
253
  if (report) {
257
254
  if (report.passed) console.log(report.passed!);
258
255
  if (report.failed) failed_suite_logs += report.failed!;
@@ -266,14 +263,10 @@ export function run(options: RunOptions = new RunOptions()): void {
266
263
  console.log(failed_suite_logs);
267
264
  }
268
265
 
269
- // @ts-ignore
270
- const cv = __COVERAGE_STATS();
271
- const COVER_POINTS = cv.hashs;
272
- const COVER_TOTAL_POINTS = cv.points;
273
266
 
274
- if (options.coverage && COVER_POINTS.size) {
267
+ if (options.coverage && __HASHES().size) {
275
268
  console.log(rainbow.dimMk("----------------- [COVERAGE] -----------------\n"));
276
- const points = COVER_POINTS.values();
269
+ const points = __HASHES().values();
277
270
 
278
271
  for (let i = 0; i < points.length; i++) {
279
272
  const point = unchecked(points[i]);
@@ -285,10 +278,11 @@ export function run(options: RunOptions = new RunOptions()): void {
285
278
  console.log(rainbow.dimMk("----------------- [RESULTS] ------------------\n"));
286
279
  const ms = performance.now() - start;
287
280
  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");
281
+ console.log(rainbow.boldMk("Tests: ") + (failed_tests ? rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + tests.toString() + " total");
282
+ if (options.coverage) console.log(rainbow.boldMk("Coverage: ") + (__HASHES().size ? rainbow.boldMk(rainbow.red(__HASHES().size.toString() + " failed")) : rainbow.boldMk(rainbow.green("0 failed"))) + ", " + __POINTS().toString() + " total");
290
283
  console.log(rainbow.boldMk("Snapshots: ") + "0 total");
291
284
  console.log(rainbow.boldMk("Time: ") + formatTime(ms));
285
+ __COVER("joe mom")
292
286
  if (failed) {
293
287
  process.exit(1);
294
288
  }
@@ -1,7 +1,7 @@
1
1
  import { rainbow } from "as-rainbow";
2
2
  import { diff, visualize } from "../util";
3
3
  import { Node } from "./node";
4
- import { Verdict } from "..";
4
+ import { Verdict, after_each_callback, before_each_callback } from "..";
5
5
 
6
6
  export class Expectation<T> extends Node {
7
7
  public verdict: Verdict = Verdict.Unreachable;
@@ -21,7 +21,7 @@ export class TestGroup {
21
21
  this.results.push(test);
22
22
  }
23
23
 
24
- report(): ReportLogs | null {
24
+ getLogs(): ReportLogs {
25
25
  let passed_logs = "";
26
26
  let failed_logs = "";
27
27
  for (let i = 0; i < this.results.length; i++) {
package/assembly/test.ts CHANGED
@@ -63,7 +63,7 @@ describe("Array manipulation", () => {
63
63
  });
64
64
  });
65
65
 
66
- export function foo(): void {
66
+ function foo(): void {
67
67
 
68
68
  }
69
69
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -21,19 +21,16 @@
21
21
  "assemblyscript-prettier": "^3.0.1",
22
22
  "jest": "^29.7.0",
23
23
  "typescript": "^5.3.3",
24
- "visitor-as": "^0.11.4"
24
+ "visitor-as": "^0.11.4",
25
+ "json-as": "^0.9.6"
25
26
  },
26
27
  "dependencies": {
27
28
  "as-console": "^6.0.2",
28
- "as-convert-seconds": "^1.0.0",
29
29
  "as-rainbow": "^0.1.0",
30
30
  "as-string-sink": "^0.5.3",
31
31
  "as-variant": "^0.4.1",
32
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"
33
+ "micromatch": "^4.0.7"
37
34
  },
38
35
  "overrides": {
39
36
  "assemblyscript": "$assemblyscript",
@@ -58,4 +55,4 @@
58
55
  "publishConfig": {
59
56
  "@JairusSW:registry": "https://npm.pkg.github.com"
60
57
  }
61
- }
58
+ }
package/src/cli.ts CHANGED
@@ -1,10 +0,0 @@
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()
@@ -1,7 +1,7 @@
1
1
  import { Transform } from "assemblyscript/dist/transform.js";
2
- import { Source, Tokenizer, BlockStatement, ExpressionStatement, Node } from "assemblyscript/dist/assemblyscript.js";
2
+ import { Source, BlockStatement, ExpressionStatement, Node, Tokenizer } from "assemblyscript/dist/assemblyscript.js";
3
3
  import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
4
- import { isStdlib, toString } from "visitor-as/dist/utils.js";
4
+ import { isStdlib } from "visitor-as/dist/utils.js";
5
5
  import { RangeTransform } from "visitor-as/dist/transformRange.js";
6
6
  let ENABLED = false;
7
7
  var CoverType;
@@ -51,7 +51,7 @@ class CoverageTransform extends BaseVisitor {
51
51
  hash: "${point.hash}",
52
52
  line: ${point.line},
53
53
  column: ${point.column},
54
- type: __COVERTYPES.Expression,
54
+ type: "Expression",
55
55
  executed: false
56
56
  });`);
57
57
  replacer.visit(registerStmt);
@@ -91,7 +91,7 @@ class CoverageTransform extends BaseVisitor {
91
91
  hash: "${point.hash}",
92
92
  line: ${point.line},
93
93
  column: ${point.column},
94
- type: __COVERTYPES.Function,
94
+ type: "Function",
95
95
  executed: false
96
96
  })`);
97
97
  replacer.visit(registerStmt);
@@ -129,7 +129,7 @@ class CoverageTransform extends BaseVisitor {
129
129
  hash: "${point.hash}",
130
130
  line: ${point.line},
131
131
  column: ${point.column},
132
- type: __COVERTYPES.Expression,
132
+ type: "Expression",
133
133
  executed: false
134
134
  })`);
135
135
  replacer.visit(registerStmt);
@@ -167,7 +167,7 @@ class CoverageTransform extends BaseVisitor {
167
167
  hash: "${point.hash}",
168
168
  line: ${point.line},
169
169
  column: ${point.column},
170
- type: __COVERTYPES.Function,
170
+ type: "Function",
171
171
  executed: false
172
172
  })`);
173
173
  replacer.visit(registerStmt);
@@ -227,7 +227,7 @@ class CoverageTransform extends BaseVisitor {
227
227
  hash: "${point.hash}",
228
228
  line: ${point.line},
229
229
  column: ${point.column},
230
- type: __COVERTYPES.Expression,
230
+ type: "Expression",
231
231
  executed: false
232
232
  })`);
233
233
  replacer.visit(registerStmt);
@@ -253,7 +253,7 @@ class CoverageTransform extends BaseVisitor {
253
253
  hash: "${point.hash}",
254
254
  line: ${point.line},
255
255
  column: ${point.column},
256
- type: __COVERTYPES.Expression,
256
+ type: "Expression",
257
257
  executed: false
258
258
  })`);
259
259
  replacer.visit(registerStmt);
@@ -311,7 +311,7 @@ class CoverageTransform extends BaseVisitor {
311
311
  hash: "${point.hash}",
312
312
  line: ${point.line},
313
313
  column: ${point.column},
314
- type: __COVERTYPES.Expression,
314
+ type: "Expression",
315
315
  executed: false
316
316
  })`);
317
317
  replacer.visit(registerStmt);
@@ -335,7 +335,7 @@ class CoverageTransform extends BaseVisitor {
335
335
  hash: "${point.hash}",
336
336
  line: ${point.line},
337
337
  column: ${point.column},
338
- type: __COVERTYPES.Expression,
338
+ type: "Expression",
339
339
  executed: false
340
340
  })`);
341
341
  replacer.visit(registerStmt);
@@ -366,7 +366,7 @@ class CoverageTransform extends BaseVisitor {
366
366
  hash: "${point.hash}",
367
367
  line: ${point.line},
368
368
  column: ${point.column},
369
- type: __COVERTYPES.Block,
369
+ type: "Block",
370
370
  executed: false
371
371
  })`);
372
372
  replacer.visit(registerStmt);
@@ -396,7 +396,7 @@ class CoverageTransform extends BaseVisitor {
396
396
  hash: "${point.hash}",
397
397
  line: ${point.line},
398
398
  column: ${point.column},
399
- type: __COVERTYPES.Block,
399
+ type: "Block",
400
400
  executed: false
401
401
  })`);
402
402
  replacer.visit(registerStmt);
@@ -463,14 +463,10 @@ export default class Transformer extends Transform {
463
463
  transformer.visit(source);
464
464
  if (transformer.globalStatements.length) {
465
465
  source.statements.unshift(...transformer.globalStatements);
466
- const tokenizer = new Tokenizer(new Source(0 /* SourceKind.User */, source.normalizedPath, "import { __REGISTER, __COVER, __COVERTYPES, __COVERAGE_STATS } from \"as-test/coverage\";"));
466
+ const tokenizer = new Tokenizer(new Source(0 /* SourceKind.User */, source.normalizedPath, "import { __REGISTER, __COVER } from \"as-test/assembly/coverage\";"));
467
467
  parser.currentSource = tokenizer.source;
468
468
  source.statements.unshift(parser.parseTopLevelStatement(tokenizer));
469
469
  parser.currentSource = source;
470
- // @ts-ignore
471
- if (process && process.env["TEST_DEBUG"]?.toString().toLowerCase() == "all") {
472
- console.log(toString(source));
473
- }
474
470
  }
475
471
  }
476
472
  transformer.globalStatements = [];
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@as-test/transform",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -4,7 +4,6 @@ import {
4
4
  Source,
5
5
  SourceKind,
6
6
  Statement,
7
- Tokenizer,
8
7
  Token,
9
8
 
10
9
  BinaryExpression,
@@ -22,10 +21,12 @@ import {
22
21
  NodeKind,
23
22
  ArrowKind,
24
23
  Node,
25
- ObjectLiteralExpression
24
+ ObjectLiteralExpression,
25
+ Tokenizer
26
26
  } from "assemblyscript/dist/assemblyscript.js";
27
+
27
28
  import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
28
- import { isStdlib, toString } from "visitor-as/dist/utils.js";
29
+ import { isStdlib } from "visitor-as/dist/utils.js";
29
30
  import { RangeTransform } from "visitor-as/dist/transformRange.js";
30
31
 
31
32
  let ENABLED = false;
@@ -79,7 +80,7 @@ class CoverageTransform extends BaseVisitor {
79
80
  hash: "${point.hash}",
80
81
  line: ${point.line},
81
82
  column: ${point.column},
82
- type: __COVERTYPES.Expression,
83
+ type: "Expression",
83
84
  executed: false
84
85
  });`
85
86
  );
@@ -130,7 +131,7 @@ class CoverageTransform extends BaseVisitor {
130
131
  hash: "${point.hash}",
131
132
  line: ${point.line},
132
133
  column: ${point.column},
133
- type: __COVERTYPES.Function,
134
+ type: "Function",
134
135
  executed: false
135
136
  })`
136
137
  );
@@ -178,7 +179,7 @@ class CoverageTransform extends BaseVisitor {
178
179
  hash: "${point.hash}",
179
180
  line: ${point.line},
180
181
  column: ${point.column},
181
- type: __COVERTYPES.Expression,
182
+ type: "Expression",
182
183
  executed: false
183
184
  })`
184
185
  );
@@ -226,7 +227,7 @@ class CoverageTransform extends BaseVisitor {
226
227
  hash: "${point.hash}",
227
228
  line: ${point.line},
228
229
  column: ${point.column},
229
- type: __COVERTYPES.Function,
230
+ type: "Function",
230
231
  executed: false
231
232
  })`
232
233
  );
@@ -305,7 +306,7 @@ class CoverageTransform extends BaseVisitor {
305
306
  hash: "${point.hash}",
306
307
  line: ${point.line},
307
308
  column: ${point.column},
308
- type: __COVERTYPES.Expression,
309
+ type: "Expression",
309
310
  executed: false
310
311
  })`
311
312
  );
@@ -346,7 +347,7 @@ class CoverageTransform extends BaseVisitor {
346
347
  hash: "${point.hash}",
347
348
  line: ${point.line},
348
349
  column: ${point.column},
349
- type: __COVERTYPES.Expression,
350
+ type: "Expression",
350
351
  executed: false
351
352
  })`
352
353
  );
@@ -415,7 +416,7 @@ class CoverageTransform extends BaseVisitor {
415
416
  hash: "${point.hash}",
416
417
  line: ${point.line},
417
418
  column: ${point.column},
418
- type: __COVERTYPES.Expression,
419
+ type: "Expression",
419
420
  executed: false
420
421
  })`
421
422
  );
@@ -450,7 +451,7 @@ class CoverageTransform extends BaseVisitor {
450
451
  hash: "${point.hash}",
451
452
  line: ${point.line},
452
453
  column: ${point.column},
453
- type: __COVERTYPES.Expression,
454
+ type: "Expression",
454
455
  executed: false
455
456
  })`
456
457
  );
@@ -491,7 +492,7 @@ class CoverageTransform extends BaseVisitor {
491
492
  hash: "${point.hash}",
492
493
  line: ${point.line},
493
494
  column: ${point.column},
494
- type: __COVERTYPES.Block,
495
+ type: "Block",
495
496
  executed: false
496
497
  })`
497
498
  );
@@ -532,7 +533,7 @@ class CoverageTransform extends BaseVisitor {
532
533
  hash: "${point.hash}",
533
534
  line: ${point.line},
534
535
  column: ${point.column},
535
- type: __COVERTYPES.Block,
536
+ type: "Block",
536
537
  executed: false
537
538
  })`
538
539
  );
@@ -576,6 +577,7 @@ export default class Transformer extends Transform {
576
577
  }
577
578
  }
578
579
  if (!ENABLED) return;
580
+
579
581
  // Create new transform
580
582
  const transformer = new CoverageTransform();
581
583
 
@@ -607,16 +609,12 @@ export default class Transformer extends Transform {
607
609
  new Source(
608
610
  SourceKind.User,
609
611
  source.normalizedPath,
610
- "import { __REGISTER, __COVER, __COVERTYPES, __COVERAGE_STATS } from \"as-test/coverage\";"
612
+ "import { __REGISTER, __COVER } from \"as-test/assembly/coverage\";"
611
613
  )
612
614
  );
613
615
  parser.currentSource = tokenizer.source;
614
616
  source.statements.unshift(parser.parseTopLevelStatement(tokenizer)!);
615
617
  parser.currentSource = source;
616
- // @ts-ignore
617
- if (process && process.env["TEST_DEBUG"]?.toString().toLowerCase() == "all") {
618
- console.log(toString(source));
619
- }
620
618
  }
621
619
  }
622
620
  transformer.globalStatements = [];
@@ -1,39 +0,0 @@
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
- }
package/coverage.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./assembly/src/coverage";