as-test 0.0.0 → 0.0.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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  | _ | __|___|_ _| __| __|_ _|
5
5
  | |__ |___| | | | __|__ | | |
6
6
  |__|__|_____| |_| |_____|_____| |_|
7
- v0.0.0
7
+ v0.0.2
8
8
  </pre>
9
9
  </h5>
10
10
 
package/assembly/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { rainbow } from "as-rainbow";
2
2
  import { TestGroup } from "./src/group";
3
3
  import { Expectation } from "./src/expectation";
4
- import { convertSeconds } from "as-convert-seconds/assembly";
5
4
  import { Verdict } from "./src/result";
6
5
  import { formatTime } from "./util";
7
6
 
@@ -44,11 +43,11 @@ export function expect<T>(value: T): Expectation<T> {
44
43
 
45
44
  export function run(): void {
46
45
  console.log(rainbow.boldMk(rainbow.blue(
47
- ` _____ _____ _____ _____ _____ _____
46
+ ` _____ _____ _____ _____ _____ _____
48
47
  | _ | __|___|_ _| __| __|_ _|
49
48
  | |__ |___| | | | __|__ | | |
50
49
  |__|__|_____| |_| |_____|_____| |_| `)));
51
- console.log(rainbow.dimMk("\n-----------------------------------------\n"));
50
+ console.log(rainbow.dimMk("\n-----------------------------------------\n"));
52
51
  const suites = groups.length;
53
52
  let failed = 0;
54
53
  let tests = 0;
@@ -56,7 +55,6 @@ console.log(rainbow.dimMk("\n-----------------------------------------\n"));
56
55
  const start = performance.now();
57
56
  for (let i = 0; i < groups.length; i++) {
58
57
  const suite = unchecked(groups[i]);
59
- console.log(rainbow.boldMk(`Running test suite: ${suite.description}...`));
60
58
  suite.run();
61
59
  for (let i = 0; i < suite.results.length; i++) {
62
60
  const expectation = unchecked(suite.results[i]);
@@ -70,13 +68,21 @@ console.log(rainbow.dimMk("\n-----------------------------------------\n"));
70
68
  failed_tests++;
71
69
  }
72
70
  }
73
- if (suite.verdict == Verdict.Unreachable) suite.verdict = Verdict.Ok;
74
- else failed++;
71
+ if (suite.verdict == Verdict.Unreachable) {
72
+ suite.verdict = Verdict.Ok;
73
+ console.log(rainbow.bgGreen(" PASS ") + " " + rainbow.dimMk(suite.description) + "\n");
74
+ } else {
75
+ failed++;
76
+ console.log(rainbow.bgRed(" FAIL ") + " " + rainbow.dimMk(suite.description) + "\n");
77
+ }
78
+
79
+ const report = suite.report();
80
+ if (report) console.log(report);
75
81
  }
76
82
  const ms = performance.now() - start;
77
- console.log(rainbow.dimMk("\n-----------------------------------------\n"));
78
- console.log(rainbow.boldMk("Test Suites: ") + rainbow.boldMk(rainbow.red(failed.toString() + " failed")) + ", " + suites.toString() + " total");
79
- console.log(rainbow.boldMk("Tests: ") + rainbow.boldMk(rainbow.red(failed_tests.toString() + " failed")) + ", " + tests.toString() + " total");
83
+ console.log(rainbow.dimMk("-----------------------------------------\n"));
84
+ console.log(rainbow.boldMk("Test Suites: ") + (failed ? rainbow.boldMk(rainbow.red(failed.toString() + " failed")) : rainbow.boldMk(rainbow.green(failed.toString() + " failed"))) + ", " + suites.toString() + " total");
85
+ 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");
80
86
  console.log(rainbow.boldMk("Snapshots: ") + "0 total");
81
87
  console.log(rainbow.boldMk("Time: ") + formatTime(ms))
82
88
  }
@@ -1,13 +1,16 @@
1
1
  import { Verdict } from "./result";
2
2
  import { rainbow } from "as-rainbow";
3
3
  import { diff, visualize } from "../util";
4
+ import { Node } from "./node";
4
5
 
5
- export class Expectation<T> {
6
+ export class Expectation<T> extends Node {
6
7
  public verdict: Verdict = Verdict.Unreachable;
7
8
  public left: T;
8
9
  public right!: T;
9
10
  private _not: boolean = false;
11
+ private op: string = "=";
10
12
  constructor(left: T) {
13
+ super();
11
14
  this.left = left;
12
15
  }
13
16
  get not(): Expectation<T> {
@@ -20,8 +23,7 @@ export class Expectation<T> {
20
23
  // @ts-ignore
21
24
  this.right = null;
22
25
 
23
- const report = this.report();
24
- if (report) console.log(report);
26
+ this.op = "="
25
27
 
26
28
  return this;
27
29
  }
@@ -36,8 +38,7 @@ export class Expectation<T> {
36
38
  this.verdict = this.left > value ? Verdict.Ok : Verdict.Fail;
37
39
  this.right = value;
38
40
 
39
- const report = this.report(">");
40
- if (report) console.log(report);
41
+ this.op = ">";
41
42
 
42
43
  return this;
43
44
  }
@@ -52,8 +53,7 @@ export class Expectation<T> {
52
53
  this.verdict = this.left >= value ? Verdict.Ok : Verdict.Fail;
53
54
  this.right = value;
54
55
 
55
- const report = this.report(">=");
56
- if (report) console.log(report);
56
+ this.op = ">=";
57
57
 
58
58
  return this;
59
59
  }
@@ -68,8 +68,7 @@ export class Expectation<T> {
68
68
  this.verdict = this.left < value ? Verdict.Ok : Verdict.Fail;
69
69
  this.right = value;
70
70
 
71
- const report = this.report("<");
72
- if (report) console.log(report);
71
+ this.op = "<";
73
72
 
74
73
  return this;
75
74
  }
@@ -84,8 +83,7 @@ export class Expectation<T> {
84
83
  this.verdict = this.left <= value ? Verdict.Ok : Verdict.Fail;
85
84
  this.right = value;
86
85
 
87
- const report = this.report("<=");
88
- if (report) console.log(report);
86
+ this.op = "<=";
89
87
 
90
88
  return this;
91
89
  }
@@ -115,13 +113,12 @@ export class Expectation<T> {
115
113
  this.verdict = Verdict.Unreachable;
116
114
  }
117
115
 
118
- const report = this.report();
119
- if (report) console.log(report);
116
+ this.op = "=";
120
117
 
121
118
  return this;
122
119
  }
123
120
 
124
- report(op: string = "="): string | null {
121
+ report(): string | null {
125
122
  if (!this._not && this.verdict === Verdict.Ok) return null;
126
123
 
127
124
  const left = visualize(this.left);
@@ -130,13 +127,13 @@ export class Expectation<T> {
130
127
  if (this._not) {
131
128
  if (this.verdict === Verdict.Fail) return null;
132
129
  const dif = diff(left, right, true);
133
- return rainbow.red(" - Test failed") + "\n" + rainbow.italicMk(` ${rainbow.dimMk("(expected) ->")} ${dif.left.toString()}\n ${rainbow.dimMk("[ !" + op + " ]")}\n ${rainbow.dimMk("(recieved) ->")} ${dif.right.toString()}`);
130
+ return rainbow.red(" - Test failed") + "\n" + rainbow.italicMk(` ${rainbow.dimMk("(expected) ->")} ${dif.left.toString()}\n ${rainbow.dimMk("[ !" + this.op + " ]")}\n ${rainbow.dimMk("(recieved) ->")} ${dif.right.toString()}`);
134
131
  }
135
132
 
136
133
  if (left == right) return null;
137
134
 
138
135
  const dif = diff(left, right);
139
136
 
140
- return rainbow.red(" - Test failed") + "\n" + rainbow.italicMk(` ${rainbow.dimMk("(expected) ->")} ${dif.left.toString()}\n ${rainbow.dimMk("[ " + op + " ]")}\n ${rainbow.dimMk("(recieved) ->")} ${dif.right.toString()}`);
137
+ return rainbow.red(" - Test failed") + "\n" + rainbow.italicMk(` ${rainbow.dimMk("(expected) ->")} ${dif.left.toString()}\n ${rainbow.dimMk("[ " + this.op + " ]")}\n ${rainbow.dimMk("(recieved) ->")} ${dif.right.toString()}`);
141
138
  }
142
139
  }
@@ -1,7 +1,8 @@
1
1
  import { Expectation } from "./expectation";
2
+ import { Node } from "./node";
2
3
  import { Verdict } from "./result";
3
4
  export class TestGroup {
4
- public results: Expectation<usize>[] = [];
5
+ public results: Node[] = [];
5
6
 
6
7
  public description: string;
7
8
  public executed: boolean = false;
@@ -17,7 +18,16 @@ export class TestGroup {
17
18
  }
18
19
 
19
20
  addExpectation<T extends Expectation<unknown>>(test: T): void {
20
- this.results.push(changetype<Expectation<usize>>(test));
21
+ this.results.push(test);
22
+ }
23
+
24
+ report(): string | null {
25
+ let report = "";
26
+ for (let i = 0; i < this.results.length; i++) {
27
+ const result = unchecked(this.results[i]).report();
28
+ if (result) report += result + "\n";
29
+ }
30
+ return report.length ? report : null;
21
31
  }
22
32
 
23
33
  run(): void {
@@ -0,0 +1,8 @@
1
+ import { Verdict } from "./result";
2
+
3
+ export class Node {
4
+ public verdict: Verdict = Verdict.Unreachable;
5
+ report(): string | null {
6
+ return "ERROR"
7
+ }
8
+ }
package/index.ts CHANGED
@@ -0,0 +1 @@
1
+ export * from "./assembly/index";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",