as-test 0.4.4 → 0.5.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +196 -82
  3. package/as-test.config.schema.json +137 -0
  4. package/assembly/coverage.ts +19 -0
  5. package/assembly/index.ts +172 -85
  6. package/assembly/src/expectation.ts +263 -199
  7. package/assembly/src/log.ts +1 -9
  8. package/assembly/src/suite.ts +61 -25
  9. package/assembly/src/tests.ts +2 -0
  10. package/assembly/util/wipc.ts +286 -0
  11. package/bin/build.js +86 -41
  12. package/bin/index.js +337 -68
  13. package/bin/init.js +441 -183
  14. package/bin/reporter.js +1 -1
  15. package/bin/reporters/default.js +379 -0
  16. package/bin/reporters/types.js +1 -0
  17. package/bin/run.js +882 -194
  18. package/bin/types.js +14 -7
  19. package/bin/util.js +54 -3
  20. package/package.json +34 -16
  21. package/transform/lib/builder.js +169 -169
  22. package/transform/lib/builder.js.map +1 -1
  23. package/transform/lib/coverage.js +47 -1
  24. package/transform/lib/coverage.js.map +1 -1
  25. package/transform/lib/index.js +70 -0
  26. package/transform/lib/index.js.map +1 -1
  27. package/transform/lib/location.js +20 -0
  28. package/transform/lib/location.js.map +1 -0
  29. package/transform/lib/log.js +118 -0
  30. package/transform/lib/log.js.map +1 -0
  31. package/transform/lib/mock.js +2 -2
  32. package/transform/lib/mock.js.map +1 -1
  33. package/transform/lib/util.js +3 -3
  34. package/transform/lib/util.js.map +1 -1
  35. package/.github/workflows/as-test.yml +0 -26
  36. package/.prettierrc +0 -3
  37. package/as-test.config.json +0 -19
  38. package/assembly/__tests__/array.spec.ts +0 -25
  39. package/assembly/__tests__/math.spec.ts +0 -16
  40. package/assembly/__tests__/mock.spec.ts +0 -22
  41. package/assembly/__tests__/mock.ts +0 -7
  42. package/assembly/__tests__/sleep.spec.ts +0 -28
  43. package/assembly/tsconfig.json +0 -97
  44. package/assets/img/screenshot.png +0 -0
  45. package/cli/build.ts +0 -117
  46. package/cli/index.ts +0 -190
  47. package/cli/init.ts +0 -247
  48. package/cli/reporter.ts +0 -1
  49. package/cli/run.ts +0 -286
  50. package/cli/tsconfig.json +0 -9
  51. package/cli/types.ts +0 -29
  52. package/cli/util.ts +0 -65
  53. package/run/package.json +0 -27
  54. package/tests/array.run.js +0 -7
  55. package/tests/math.run.js +0 -7
  56. package/tests/mock.run.js +0 -14
  57. package/tests/sleep.run.js +0 -7
  58. package/transform/src/builder.ts +0 -1474
  59. package/transform/src/coverage.ts +0 -580
  60. package/transform/src/index.ts +0 -73
  61. package/transform/src/linker.ts +0 -41
  62. package/transform/src/mock.ts +0 -163
  63. package/transform/src/range.ts +0 -12
  64. package/transform/src/types.ts +0 -35
  65. package/transform/src/util.ts +0 -81
  66. package/transform/src/visitor.ts +0 -744
  67. package/transform/tsconfig.json +0 -10
package/bin/types.js CHANGED
@@ -1,16 +1,23 @@
1
1
  export class Config {
2
2
  constructor() {
3
+ this.$schema = "./as-test.config.schema.json";
3
4
  this.input = ["./assembly/__tests__/*.spec.ts"];
4
- this.outDir = "./build";
5
- this.logs = "./logs";
5
+ this.outDir = "./.as-test/build";
6
+ this.logs = "./.as-test/logs";
7
+ this.coverageDir = "./.as-test/coverage";
8
+ this.snapshotDir = "./.as-test/snapshots";
6
9
  this.config = "none";
7
- this.plugins = {
8
- coverage: true,
9
- };
10
+ this.coverage = true;
10
11
  this.buildOptions = new BuildOptions();
11
12
  this.runOptions = new RunOptions();
12
13
  }
13
14
  }
15
+ export class CoverageOptions {
16
+ constructor() {
17
+ this.enabled = true;
18
+ this.includeSpecs = false;
19
+ }
20
+ }
14
21
  export class Suite {
15
22
  constructor() {
16
23
  this.name = "";
@@ -25,11 +32,11 @@ export class BuildOptions {
25
32
  export class RunOptions {
26
33
  constructor() {
27
34
  this.runtime = new Runtime();
35
+ this.reporter = "";
28
36
  }
29
37
  }
30
38
  export class Runtime {
31
39
  constructor() {
32
- this.name = "wasmtime";
33
- this.run = "wasmtime <file>";
40
+ this.cmd = "node ./.as-test/runners/default.wasi.js <file>";
34
41
  }
35
42
  }
package/bin/util.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { existsSync, readFileSync } from "fs";
2
- import { Config } from "./types.js";
2
+ import { BuildOptions, Config, RunOptions, Runtime } from "./types.js";
3
3
  import chalk from "chalk";
4
- import { delimiter, join } from "path";
4
+ import { delimiter, dirname, join } from "path";
5
+ import { fileURLToPath } from "url";
5
6
  export function formatTime(ms) {
6
7
  if (ms < 0) {
7
8
  throw new Error("Time should be a non-negative number.");
@@ -32,9 +33,59 @@ export function loadConfig(CONFIG_PATH, warn = false) {
32
33
  return new Config();
33
34
  }
34
35
  else {
35
- return Object.assign(new Config(), JSON.parse(readFileSync(CONFIG_PATH).toString()));
36
+ const raw = JSON.parse(readFileSync(CONFIG_PATH).toString());
37
+ const config = Object.assign(new Config(), raw);
38
+ const runOptionsRaw = raw.runOptions ?? {};
39
+ config.buildOptions = Object.assign(new BuildOptions(), raw.buildOptions ?? {});
40
+ config.runOptions = Object.assign(new RunOptions(), runOptionsRaw);
41
+ const runtimeRaw = runOptionsRaw.runtime;
42
+ const runtime = new Runtime();
43
+ const legacyRun = typeof runOptionsRaw.run == "string" && runOptionsRaw.run.length
44
+ ? runOptionsRaw.run
45
+ : "";
46
+ const cmd = runtimeRaw && typeof runtimeRaw.cmd == "string" && runtimeRaw.cmd.length
47
+ ? runtimeRaw.cmd
48
+ : runtimeRaw &&
49
+ typeof runtimeRaw.run == "string" &&
50
+ runtimeRaw.run.length
51
+ ? runtimeRaw.run
52
+ : legacyRun
53
+ ? legacyRun
54
+ : runtime.cmd;
55
+ runtime.cmd = cmd;
56
+ config.runOptions.runtime = runtime;
57
+ return config;
36
58
  }
37
59
  }
60
+ export function getCliVersion() {
61
+ const candidates = [
62
+ join(process.cwd(), "package.json"),
63
+ join(dirname(fileURLToPath(import.meta.url)), "..", "package.json"),
64
+ ];
65
+ for (const pkgPath of candidates) {
66
+ if (!existsSync(pkgPath))
67
+ continue;
68
+ try {
69
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
70
+ if (pkg.version)
71
+ return pkg.version;
72
+ }
73
+ catch {
74
+ // ignore invalid package metadata and continue to fallback candidate
75
+ }
76
+ }
77
+ return "0.0.0";
78
+ }
79
+ export function getPkgRunner() {
80
+ const userAgent = process.env.npm_config_user_agent ?? "";
81
+ if (userAgent.startsWith("pnpm"))
82
+ return "pnpx";
83
+ if (userAgent.startsWith("yarn"))
84
+ return "yarn";
85
+ if (userAgent.startsWith("bun"))
86
+ return "bunx";
87
+ return "npx";
88
+ }
38
89
  export function getExec(exec) {
39
90
  const PATH = process.env.PATH.split(delimiter);
40
91
  for (const pathDir of PATH) {
package/package.json CHANGED
@@ -1,45 +1,48 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.4.4",
4
- "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
3
+ "version": "0.5.1",
4
+ "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
7
7
  "contributors": [],
8
8
  "license": "MIT",
9
9
  "scripts": {
10
- "test": "node ./bin/index.js run",
11
- "pretest": "node ./bin/index.js build",
10
+ "test": "node ./bin/index.js test",
12
11
  "build:transform": "tsc -p ./transform",
13
12
  "build:cli": "tsc -p cli",
14
13
  "build:run": "tsc -p run",
15
14
  "prettier": "prettier -w .",
16
- "prepublish": "npm run build:cli && npm run build:transform && npm run test"
15
+ "release:check": "npm run build:cli && npm run build:transform && npm run test && npm pack --dry-run --cache /tmp/as-test-npm-cache",
16
+ "prepublishOnly": "npm run build:cli && npm run build:transform && npm run test"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@assemblyscript/wasi-shim": "^0.1.0",
20
- "@types/node": "^22.13.10",
20
+ "@eslint/js": "^10.0.1",
21
+ "@types/node": "^25.2.3",
21
22
  "as-sleep": "^0.0.2",
22
23
  "as-test": "./",
23
- "assemblyscript": "^0.27.35",
24
+ "assemblyscript": "^0.28.9",
24
25
  "assemblyscript-prettier": "^3.0.1",
25
- "typescript": "^5.8.2"
26
+ "json-as": "^1.2.5",
27
+ "prettier": "3.6.2",
28
+ "typescript": "^5.9.3",
29
+ "typescript-eslint": "^8.55.0"
26
30
  },
27
31
  "dependencies": {
28
32
  "as-console": "^7.0.0",
29
33
  "as-rainbow": "^0.1.0",
30
34
  "as-variant": "^0.4.1",
31
- "chalk": "^5.4.1",
32
- "glob": "^11.0.1",
35
+ "chalk": "^5.6.2",
36
+ "glob": "^13.0.3",
33
37
  "gradient-string": "^3.0.0",
34
- "typer-diff": "^1.1.1"
38
+ "typer-diff": "^1.1.1",
39
+ "wipc-js": "^0.1.1"
35
40
  },
36
41
  "peerDependencies": {
37
- "json-as": "*"
42
+ "json-as": "^1.2.5"
38
43
  },
39
- "peerDependenciesMeta": {
40
- "json-as": {
41
- "optional": true
42
- }
44
+ "optionalDependencies": {
45
+ "try-as": "^0.2.5"
43
46
  },
44
47
  "repository": {
45
48
  "type": "git",
@@ -60,6 +63,21 @@
60
63
  "publishConfig": {
61
64
  "@JairusSW:registry": "https://npm.pkg.github.com"
62
65
  },
66
+ "files": [
67
+ "assembly/**/*.ts",
68
+ "!assembly/__tests__/**",
69
+ "!assembly/tsconfig.json",
70
+ "bin/**/*.js",
71
+ "templates/**/*.js",
72
+ "transform/lib/**/*.js",
73
+ "transform/lib/**/*.js.map",
74
+ "transform/package.json",
75
+ "CHANGELOG.md",
76
+ "README.md",
77
+ "LICENSE",
78
+ "as-test.config.schema.json",
79
+ "index.ts"
80
+ ],
63
81
  "bin": {
64
82
  "as-test": "./bin/index.js",
65
83
  "ast": "./bin/index.js"