as-test 0.4.0 → 0.4.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +12 -12
  3. package/as-test.config.json +1 -1
  4. package/assembly/__tests__/array.spec.ts +3 -3
  5. package/assembly/src/expectation.ts +29 -16
  6. package/assembly/src/suite.ts +2 -0
  7. package/assembly/src/tests.ts +1 -0
  8. package/bin/build.js +65 -77
  9. package/bin/index.js +130 -160
  10. package/bin/init.js +96 -109
  11. package/bin/reporter.js +1 -1
  12. package/bin/run.js +210 -236
  13. package/bin/types.js +25 -25
  14. package/bin/util.js +35 -42
  15. package/cli/run.ts +13 -15
  16. package/cli/tsconfig.json +2 -1
  17. package/package.json +12 -9
  18. package/transform/lib/builder.js +1361 -0
  19. package/transform/lib/builder.js.map +1 -0
  20. package/transform/lib/coverage.js +6 -6
  21. package/transform/lib/coverage.js.map +1 -1
  22. package/transform/lib/index.js +1 -1
  23. package/transform/lib/index.js.map +1 -1
  24. package/transform/lib/linker.js +19 -0
  25. package/transform/lib/linker.js.map +1 -0
  26. package/transform/lib/mock.js +9 -9
  27. package/transform/lib/mock.js.map +1 -1
  28. package/transform/lib/range.js +13 -0
  29. package/transform/lib/range.js.map +1 -0
  30. package/transform/lib/types.js +26 -0
  31. package/transform/lib/types.js.map +1 -0
  32. package/transform/lib/util.js +47 -0
  33. package/transform/lib/util.js.map +1 -0
  34. package/transform/lib/visitor.js +532 -0
  35. package/transform/lib/visitor.js.map +1 -0
  36. package/transform/src/builder.ts +1474 -0
  37. package/transform/src/coverage.ts +6 -7
  38. package/transform/src/index.ts +1 -2
  39. package/transform/src/linker.ts +41 -0
  40. package/transform/src/mock.ts +9 -10
  41. package/transform/src/range.ts +12 -0
  42. package/transform/src/types.ts +35 -0
  43. package/transform/src/util.ts +81 -0
  44. package/transform/src/visitor.ts +744 -0
  45. package/.trunk/configs/.markdownlint.yaml +0 -2
  46. package/.trunk/configs/.yamllint.yaml +0 -7
  47. package/.trunk/trunk.yaml +0 -34
  48. package/bin/about.js +0 -135
  49. package/bin/package.json +0 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 2025-05-28 - v0.4.2
4
+
5
+ - deps: update json-as to `v1.1.11`
6
+ - deps: make json-as a peer dependency
7
+
8
+ ## 2025-03-12 - v0.4.1
9
+
10
+ - deps: update json-as to `v1.0.1`
11
+
3
12
  ## 2025-03-09 - v0.4.0
4
13
 
5
14
  - deps: update json-as to `v1.0.0`
@@ -14,4 +23,4 @@
14
23
 
15
24
  ## 2025-03-03 - v0.4.0-beta.1
16
25
 
17
- - deps: update json-as to `v1.0.0-beta.8`
26
+ - deps: update json-as to `v1.0.0-beta.8`
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  ██ ██ ██ ██ ██ ██ ██
7
7
  ██ ██ ███████ ██ ███████ ███████ ██
8
8
  </span>
9
- AssemblyScript - v0.4.0
9
+ AssemblyScript - v0.4.1
10
10
  </pre>
11
11
  </h5>
12
12
 
@@ -44,17 +44,17 @@ Create a new test file in `assembly/__tests__/`, for example, `math.spec.ts`:
44
44
  import { describe, test, expect, run } from "as-test";
45
45
 
46
46
  describe("Math operations", () => {
47
- test("Addition", () => {
48
- expect(1 + 2).toBe(3);
49
- });
47
+ test("Addition", () => {
48
+ expect(1 + 2).toBe(3);
49
+ });
50
50
 
51
- test("Subtraction", () => {
52
- expect(5 - 2).toBe(3);
53
- });
51
+ test("Subtraction", () => {
52
+ expect(5 - 2).toBe(3);
53
+ });
54
54
 
55
- test("Multiplication", () => {
56
- expect(3 * 3).toBe(9);
57
- });
55
+ test("Multiplication", () => {
56
+ expect(3 * 3).toBe(9);
57
+ });
58
58
  });
59
59
 
60
60
  run();
@@ -87,11 +87,11 @@ Use `beforeAll` and `afterAll` to run code before and after a test is run.
87
87
  import { beforeAll, afterAll } from "as-test";
88
88
 
89
89
  beforeAll(() => {
90
- log("Setting up test environment...");
90
+ log("Setting up test environment...");
91
91
  });
92
92
 
93
93
  afterAll(() => {
94
- log("Tearing down test environment...");
94
+ log("Tearing down test environment...");
95
95
  });
96
96
 
97
97
  run();
@@ -7,7 +7,7 @@
7
7
  "coverage": false
8
8
  },
9
9
  "buildOptions": {
10
- "args": ["--lib ./node_modules/json-as/lib"],
10
+ "args": [],
11
11
  "target": "bindings"
12
12
  },
13
13
  "runOptions": {
@@ -12,10 +12,10 @@ describe("Array manipulation", () => {
12
12
  // });
13
13
 
14
14
  test("Array check", () => {
15
- const a = [1,2,3];
16
- const b = [1,2,3];
15
+ const a = [1, 2, 3];
16
+ const b = [1, 2, 3];
17
17
  expect(a).toBe(b);
18
- })
18
+ });
19
19
 
20
20
  it("should be empty", () => {});
21
21
  });
@@ -9,11 +9,14 @@ export class Expectation<T> extends Tests {
9
9
  public verdict: string = "none";
10
10
  public right: JSON.Raw = JSON.Raw.from("");
11
11
  public left: JSON.Raw = JSON.Raw.from("");
12
+
12
13
  @omit
13
14
  private _left: T;
15
+
14
16
  @omit
15
17
  // @ts-ignore
16
18
  private _right: u64 = 0;
19
+
17
20
  @omit
18
21
  // @ts-ignore
19
22
  private _not: boolean = false;
@@ -40,9 +43,11 @@ export class Expectation<T> extends Tests {
40
43
  this.instr = "toBeNull";
41
44
 
42
45
  this.left.set(visualize<T>(this._left));
43
- this.right.set(visualize<T>(
44
- load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
45
- ));
46
+ this.right.set(
47
+ visualize<T>(
48
+ load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
49
+ ),
50
+ );
46
51
 
47
52
  // @ts-ignore
48
53
  if (after_each_callback) after_each_callback();
@@ -69,9 +74,11 @@ export class Expectation<T> extends Tests {
69
74
  this.instr = "toBeGreaterThan";
70
75
 
71
76
  this.left.set(visualize<T>(this._left));
72
- this.right.set(visualize<T>(
73
- load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
74
- ));
77
+ this.right.set(
78
+ visualize<T>(
79
+ load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
80
+ ),
81
+ );
75
82
 
76
83
  // @ts-ignore
77
84
  if (after_each_callback) after_each_callback();
@@ -98,9 +105,11 @@ export class Expectation<T> extends Tests {
98
105
  this.instr = "toBeGreaterThanOrEqualTo";
99
106
 
100
107
  this.left.set(visualize<T>(this._left));
101
- this.right.set(visualize<T>(
102
- load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
103
- ));
108
+ this.right.set(
109
+ visualize<T>(
110
+ load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
111
+ ),
112
+ );
104
113
 
105
114
  // @ts-ignore
106
115
  if (after_each_callback) after_each_callback();
@@ -127,9 +136,11 @@ export class Expectation<T> extends Tests {
127
136
  this.instr = "toBeLessThan";
128
137
 
129
138
  this.left.set(visualize<T>(this._left));
130
- this.right.set(visualize<T>(
131
- load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
132
- ));
139
+ this.right.set(
140
+ visualize<T>(
141
+ load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
142
+ ),
143
+ );
133
144
 
134
145
  // @ts-ignore
135
146
  if (after_each_callback) after_each_callback();
@@ -156,9 +167,11 @@ export class Expectation<T> extends Tests {
156
167
  this.instr = "toBeLessThanOrEqualTo";
157
168
 
158
169
  this.left.set(visualize<T>(this._left));
159
- this.right.set(visualize<T>(
160
- load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
161
- ));
170
+ this.right.set(
171
+ visualize<T>(
172
+ load<T>(changetype<usize>(this), offsetof<Expectation<T>>("_right")),
173
+ ),
174
+ );
162
175
 
163
176
  // @ts-ignore
164
177
  if (after_each_callback) after_each_callback();
@@ -379,4 +392,4 @@ export class Expectation<T> extends Tests {
379
392
  function arrayEquals<T extends any[]>(a: T, b: T): boolean {
380
393
  if (a.length != b.length) return false;
381
394
  return JSON.stringify(a) == JSON.stringify(b);
382
- }
395
+ }
@@ -8,6 +8,8 @@ import { Log } from "./log";
8
8
 
9
9
  @json
10
10
  export class Suite {
11
+
12
+ @omitif((self: Suite) => self.depth > 0)
11
13
  public file: string = "unknown";
12
14
  public order: i32 = 0;
13
15
  public time: Time = new Time();
@@ -1,5 +1,6 @@
1
1
  import { JSON } from "json-as";
2
2
 
3
+
3
4
  @json
4
5
  export class Tests {
5
6
  public order: i32 = 0;
package/bin/build.js CHANGED
@@ -7,92 +7,80 @@ import { loadConfig } from "./util.js";
7
7
  const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
8
8
  const PKG_PATH = path.join(process.cwd(), "./package.json");
9
9
  export async function build() {
10
- let config = loadConfig(CONFIG_PATH, true);
11
- const ASCONFIG_PATH = path.join(process.cwd(), config.config);
12
- if (config.config && config.config !== "none" && !existsSync(ASCONFIG_PATH)) {
13
- console.log(
14
- `${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate asconfig.json file! If you do not want to provide a config, set "config": "none"`,
15
- );
16
- }
17
- ensureDeps(config);
18
- let pkgRunner = getPkgRunner();
19
- const inputFiles = await glob(config.input);
20
- let buildArgs = getBuildArgs(config);
21
- for (const file of inputFiles) {
22
- let cmd = `${pkgRunner} asc ${file}${buildArgs}`;
23
- const outFile = `${config.outDir}/${file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm")}`;
24
- if (config.outDir) {
25
- cmd += " -o " + outFile;
10
+ let config = loadConfig(CONFIG_PATH, true);
11
+ const ASCONFIG_PATH = path.join(process.cwd(), config.config);
12
+ if (config.config && config.config !== "none" && !existsSync(ASCONFIG_PATH)) {
13
+ console.log(`${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate asconfig.json file! If you do not want to provide a config, set "config": "none"`);
14
+ }
15
+ ensureDeps(config);
16
+ let pkgRunner = getPkgRunner();
17
+ const inputFiles = await glob(config.input);
18
+ let buildArgs = getBuildArgs(config);
19
+ for (const file of inputFiles) {
20
+ let cmd = `${pkgRunner} asc ${file}${buildArgs}`;
21
+ const outFile = `${config.outDir}/${file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm")}`;
22
+ if (config.outDir) {
23
+ cmd += " -o " + outFile;
24
+ }
25
+ buildFile(cmd);
26
26
  }
27
- buildFile(cmd);
28
- }
29
27
  }
30
28
  function ensureDeps(config) {
31
- const pkg = JSON.parse(readFileSync(PKG_PATH).toString());
32
- if (config.buildOptions.target == "wasi") {
33
- if (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
34
- console.log(
35
- `${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!`,
36
- );
37
- process.exit(1);
38
- }
39
- if (
40
- pkg.dependencies &&
41
- !Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim") &&
42
- pkg.devDependencies &&
43
- !Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim") &&
44
- pkg.peerDependencies &&
45
- !Object.keys(pkg.peerDependencies).includes(
46
- "@assemblyscript/wasi-shim",
47
- ) &&
48
- existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")
49
- ) {
50
- console.log(
51
- `${chalk.bold.bgMagentaBright(" WARN ")}${chalk.dim(":")} @assemblyscript/wasi-shim is not included in project dependencies!"`,
52
- );
29
+ const pkg = JSON.parse(readFileSync(PKG_PATH).toString());
30
+ if (config.buildOptions.target == "wasi") {
31
+ if (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
32
+ console.log(`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!`);
33
+ process.exit(1);
34
+ }
35
+ if (pkg.dependencies &&
36
+ !Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim") &&
37
+ pkg.devDependencies &&
38
+ !Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim") &&
39
+ pkg.peerDependencies &&
40
+ !Object.keys(pkg.peerDependencies).includes("@assemblyscript/wasi-shim") &&
41
+ existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
42
+ console.log(`${chalk.bold.bgMagentaBright(" WARN ")}${chalk.dim(":")} @assemblyscript/wasi-shim is not included in project dependencies!"`);
43
+ }
53
44
  }
54
- }
55
45
  }
56
46
  function getPkgRunner() {
57
- switch (process.env.npm_config_user_agent) {
58
- case "pnpm": {
59
- return "pnpx";
60
- }
61
- case "yarn": {
62
- return "yarn";
47
+ switch (process.env.npm_config_user_agent) {
48
+ case "pnpm": {
49
+ return "pnpx";
50
+ }
51
+ case "yarn": {
52
+ return "yarn";
53
+ }
54
+ case "bun": {
55
+ return "bunx";
56
+ }
63
57
  }
64
- case "bun": {
65
- return "bunx";
66
- }
67
- }
68
- return "npx";
58
+ return "npx";
69
59
  }
70
60
  function buildFile(command) {
71
- execSync(command, { stdio: "inherit" });
61
+ execSync(command, { stdio: "inherit" });
72
62
  }
73
63
  function getBuildArgs(config) {
74
- let buildArgs = "";
75
- buildArgs += " --transform as-test/transform --transform json-as/transform";
76
- if (config.config && config.config !== "none") {
77
- buildArgs += " --config " + config.config;
78
- }
79
- // Should also strip any bindings-enabling from asconfig
80
- if (config.buildOptions.target == "bindings") {
81
- buildArgs += " --bindings raw --exportRuntime --exportStart _start";
82
- } else if (config.buildOptions.target == "wasi") {
83
- buildArgs +=
84
- " --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
85
- } else {
86
- console.log(
87
- `${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could determine target in config! Set target to 'bindings' or 'wasi'`,
88
- );
89
- process.exit(0);
90
- }
91
- if (
92
- config.buildOptions.args.length &&
93
- config.buildOptions.args.find((v) => v.length > 0)
94
- ) {
95
- buildArgs += " " + config.buildOptions.args.join(" ");
96
- }
97
- return buildArgs;
64
+ let buildArgs = "";
65
+ buildArgs += " --transform as-test/transform --transform json-as/transform";
66
+ if (config.config && config.config !== "none") {
67
+ buildArgs += " --config " + config.config;
68
+ }
69
+ // Should also strip any bindings-enabling from asconfig
70
+ if (config.buildOptions.target == "bindings") {
71
+ buildArgs += " --bindings raw --exportRuntime --exportStart _start";
72
+ }
73
+ else if (config.buildOptions.target == "wasi") {
74
+ buildArgs +=
75
+ " --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
76
+ }
77
+ else {
78
+ console.log(`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could determine target in config! Set target to 'bindings' or 'wasi'`);
79
+ process.exit(0);
80
+ }
81
+ if (config.buildOptions.args.length &&
82
+ config.buildOptions.args.find((v) => v.length > 0)) {
83
+ buildArgs += " " + config.buildOptions.args.join(" ");
84
+ }
85
+ return buildArgs;
98
86
  }