as-test 0.3.4 → 0.3.5

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
@@ -27,4 +27,5 @@ v0.3.0 - Pass metadata through terminal - Support for multiple files - Better re
27
27
  v0.3.1 - Add screenshot of completed tests to readme
28
28
  v0.3.2 - Add `mockImport` to override imported functions
29
29
  v0.3.3 - Allow `mockImport`'s return type to be any
30
- v0.3.4 - Fix: import functions were not received after visitSource()
30
+ v0.3.4 - Fix: import functions were not received after visitSource
31
+ v0.3.5 - Fix: allow arrays to be used in `.toBe()`
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  | _ || __| ___|_ _|| __|| __||_ _|
4
4
  | ||__ ||___| | | | __||__ | | |
5
5
  |__|__||_____| |_| |_____||_____| |_|
6
- v0.3.4
6
+ v0.3.5
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -3,17 +3,23 @@ import { describe, expect, test, run, it } from "..";
3
3
  const myArray: i32[] = [1, 2, 3];
4
4
 
5
5
  describe("Array manipulation", () => {
6
- test("Array length", () => {
7
- expect(myArray).toHaveLength(3);
8
- });
6
+ // test("Array length", () => {
7
+ // expect("foo").toBe("foo")
8
+ // });
9
9
 
10
- test("Array inclusion", () => {
11
- expect(myArray).toContain(2);
12
- });
10
+ // test("Array inclusion", () => {
11
+ // expect(myArray).toContain(2);
12
+ // });
13
+
14
+ test("Array check", () => {
15
+ const a = [1,2,3];
16
+ const b = [1,2,3];
17
+ expect(a).toBe(b);
18
+ })
13
19
 
14
20
  it("should be empty", () => {});
15
21
  });
16
22
 
17
23
  run({
18
- log: false,
24
+ log: true,
19
25
  });
@@ -3,7 +3,7 @@ export class CoverPoint {
3
3
  public hash: string = "";
4
4
  public line: i32 = 0;
5
5
  public column: i32 = 0;
6
- public type!: string;
6
+ public type: string = "";
7
7
  public executed: boolean = false;
8
8
  }
9
9
 
@@ -1,11 +1,14 @@
1
1
  import { visualize } from "../util/helpers";
2
2
  import { Tests } from "./tests";
3
- import { after_each_callback, before_each_callback } from "..";
3
+ import { after_each_callback, before_each_callback, log } from "..";
4
+ import { JSON } from "json-as";
4
5
 
5
6
 
6
7
  @json
7
8
  export class Expectation<T> extends Tests {
8
9
  public verdict: string = "none";
10
+ public right: JSON.Raw = "";
11
+ public left: JSON.Raw = "";
9
12
  private _left: T;
10
13
  // @ts-ignore
11
14
  private _right: u64 = 0;
@@ -340,33 +343,38 @@ export class Expectation<T> extends Tests {
340
343
  * @returns - void
341
344
  */
342
345
  toBe(equals: T): void {
343
- store<T>(
344
- changetype<usize>(this),
345
- equals,
346
- offsetof<Expectation<T>>("_right"),
347
- );
348
- if (isBoolean<T>()) {
346
+ if (isArray<T>()) {
347
+ // @ts-ignore
348
+ this.verdict = arrayEquals(this._left, equals) ? "ok" : "fail";
349
+ } else if (isBoolean<T>()) {
349
350
  this.verdict = this._left === equals ? "ok" : "fail";
350
351
  } else if (isString<T>()) {
351
352
  this.verdict = this._left === equals ? "ok" : "fail";
352
353
  } else if (isInteger<T>() || isFloat<T>()) {
353
354
  this.verdict = this._left === equals ? "ok" : "fail";
354
- } else if (isArray<T>()) {
355
- // getArrayDepth<T>();
356
355
  } else {
357
356
  this.verdict = "none";
358
357
  }
359
358
 
360
359
  this.instr = "toBe";
361
360
 
362
- this.left = visualize<T>(this._left);
363
- this.right = visualize<T>(
364
- load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
365
- );
361
+ this.left = JSON.stringify<T>(this._left);
362
+ this.right = JSON.stringify<T>(equals);
366
363
 
367
364
  // @ts-ignore
368
365
  if (after_each_callback) after_each_callback();
369
366
  // @ts-ignore
370
367
  if (before_each_callback) before_each_callback();
368
+
369
+ // store<T>(
370
+ // changetype<usize>(this),
371
+ // equals,
372
+ // offsetof<Expectation<T>>("_right"),
373
+ // );
371
374
  }
372
375
  }
376
+
377
+ function arrayEquals<T extends any[]>(a: T, b: T): boolean {
378
+ if (a.length != b.length) return false;
379
+ return JSON.stringify(a) == JSON.stringify(b);
380
+ }
@@ -1,10 +1,11 @@
1
+ import { JSON } from "json-as";
1
2
 
2
3
  @json
3
4
  export class Tests {
4
5
  public order: i32 = 0;
5
- public type!: string;
6
+ public type: string = "";
6
7
  public verdict: string = "none";
7
- public left: string = "";
8
- public right: string = "";
8
+ public left: JSON.Raw = "";
9
+ public right: JSON.Raw = "";
9
10
  public instr: string = "";
10
11
  }
@@ -1,4 +1,5 @@
1
1
  import { rainbow } from "as-rainbow";
2
+ import { JSON } from "json-as";
2
3
 
3
4
  export function visualize<T>(value: T): string {
4
5
  if (isNullable<T>() && changetype<usize>(value) == <usize>0) {
@@ -11,6 +12,18 @@ export function visualize<T>(value: T): string {
11
12
  } else if (isInteger<T>() || isFloat<T>()) {
12
13
  // @ts-ignore
13
14
  return value.toString();
15
+ } else if (isArray<T>()) {
16
+ // @ts-ignore
17
+ if (!value.length) return "[]";
18
+ let out = "[";
19
+ // @ts-ignore
20
+ for (let i = 0; i < value.length - 1; i++) {
21
+ // @ts-ignore
22
+ out += visualize<valueof<T>>(value[i]);
23
+ }
24
+ // @ts-ignore
25
+ out += visualize<valueof<T>>(value[value.length - 1]);
26
+ return out;
14
27
  }
15
28
 
16
29
  return unreachable();
package/bin/index.js CHANGED
@@ -7,7 +7,7 @@ const _args = process.argv.slice(2);
7
7
  const flags = [];
8
8
  const args = [];
9
9
  const COMMANDS = ["run", "build", "test", "init"];
10
- const version = "0.3.4";
10
+ const version = "0.3.5";
11
11
  for (const arg of _args) {
12
12
  if (arg.startsWith("-")) flags.push(arg);
13
13
  else args.push(arg);
package/bin/init.js CHANGED
@@ -9,7 +9,7 @@ export async function init(args) {
9
9
  input: process.stdin,
10
10
  output: process.stdout,
11
11
  });
12
- console.log(chalk.bold("as-test init v0.3.4") + "\n");
12
+ console.log(chalk.bold("as-test init v0.3.5") + "\n");
13
13
  console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
14
14
  const target = await ask(chalk.dim(" -> "), rl);
15
15
  if (!TARGETS.includes(target)) {
@@ -182,7 +182,7 @@ const exports = instantiate(module, {});`,
182
182
  }
183
183
  if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
184
184
  if (!pkg["devDependencies"]["as-test"])
185
- pkg["devDependencies"]["as-test"] = "^0.3.4";
185
+ pkg["devDependencies"]["as-test"] = "^0.3.5";
186
186
  if (target == "bindings") {
187
187
  pkg["type"] = "module";
188
188
  }
package/bin/run.js CHANGED
@@ -35,7 +35,7 @@ export async function run() {
35
35
  chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `),
36
36
  );
37
37
  console.log(
38
- chalk.dim("\n------------------- v0.3.4 -------------------\n"),
38
+ chalk.dim("\n------------------- v0.3.5 -------------------\n"),
39
39
  );
40
40
  }
41
41
  for (const plugin of Object.keys(config.plugins)) {
@@ -114,10 +114,10 @@ export async function run() {
114
114
  );
115
115
  for (const test of failed.tests) {
116
116
  const diffResult = diff(
117
- JSON.stringify(test._left),
118
- JSON.stringify(test._right),
117
+ JSON.stringify(test.left),
118
+ JSON.stringify(test.right),
119
119
  );
120
- let expected = chalk.dim(JSON.stringify(test._left));
120
+ let expected = chalk.dim(JSON.stringify(test.left));
121
121
  let received = "";
122
122
  for (const res of diffResult.diff) {
123
123
  switch (res.type) {
package/cli/index.ts CHANGED
@@ -11,7 +11,7 @@ const args: string[] = [];
11
11
 
12
12
  const COMMANDS: string[] = ["run", "build", "test", "init"];
13
13
 
14
- const version = "0.3.4";
14
+ const version = "0.3.5";
15
15
 
16
16
  for (const arg of _args) {
17
17
  if (arg.startsWith("-")) flags.push(arg);
package/cli/init.ts CHANGED
@@ -9,7 +9,7 @@ export async function init(args: string[]) {
9
9
  input: process.stdin,
10
10
  output: process.stdout,
11
11
  });
12
- console.log(chalk.bold("as-test init v0.3.4") + "\n");
12
+ console.log(chalk.bold("as-test init v0.3.5") + "\n");
13
13
  console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
14
14
  const target = await ask(chalk.dim(" -> "), rl);
15
15
  if (!TARGETS.includes(target)) {
@@ -192,7 +192,7 @@ const exports = instantiate(module, {});`,
192
192
  }
193
193
  if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
194
194
  if (!pkg["devDependencies"]["as-test"])
195
- pkg["devDependencies"]["as-test"] = "^0.3.4";
195
+ pkg["devDependencies"]["as-test"] = "^0.3.5";
196
196
  if (target == "bindings") {
197
197
  pkg["type"] = "module";
198
198
  }
package/cli/run.ts CHANGED
@@ -42,7 +42,7 @@ export async function run() {
42
42
  chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `),
43
43
  );
44
44
  console.log(
45
- chalk.dim("\n------------------- v0.3.4 -------------------\n"),
45
+ chalk.dim("\n------------------- v0.3.5 -------------------\n"),
46
46
  );
47
47
  }
48
48
 
@@ -128,8 +128,8 @@ export async function run() {
128
128
  );
129
129
  for (const test of failed.tests) {
130
130
  const diffResult = diff(
131
- JSON.stringify(test._left),
132
- JSON.stringify(test._right),
131
+ JSON.stringify(test.left),
132
+ JSON.stringify(test.right),
133
133
  );
134
134
  let expected = chalk.dim(JSON.stringify(test._left));
135
135
  let received = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -31,7 +31,7 @@
31
31
  "as-variant": "^0.4.1",
32
32
  "chalk": "^5.3.0",
33
33
  "glob": "^11.0.0",
34
- "json-as": "^0.9.14",
34
+ "json-as": "^0.9.21",
35
35
  "typer-diff": "^1.1.1"
36
36
  },
37
37
  "overrides": {
package/run/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@as-test/run",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@as-test/transform",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",