as-test 0.2.0 → 0.3.0

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 (54) hide show
  1. package/.github/workflows/as-test.yml +3 -0
  2. package/CHANGELOG.md +4 -1
  3. package/README.md +73 -67
  4. package/as-test.config.json +7 -10
  5. package/assembly/__tests__/array.spec.ts +19 -0
  6. package/assembly/__tests__/math.spec.ts +16 -0
  7. package/assembly/__tests__/sleep.spec.ts +28 -0
  8. package/assembly/index.ts +181 -165
  9. package/assembly/src/expectation.ts +119 -112
  10. package/assembly/src/log.ts +19 -0
  11. package/assembly/src/suite.ts +99 -0
  12. package/assembly/src/tests.ts +10 -0
  13. package/assembly/tsconfig.json +1 -1
  14. package/assembly/util/helpers.ts +0 -33
  15. package/assembly/util/term.ts +55 -0
  16. package/assets/img/download.png +0 -0
  17. package/bin/about.js +135 -0
  18. package/bin/build.js +72 -131
  19. package/bin/index.js +70 -112
  20. package/bin/init.js +211 -39
  21. package/bin/reporter.js +1 -0
  22. package/bin/run.js +226 -68
  23. package/bin/types.js +25 -31
  24. package/bin/util.js +44 -20
  25. package/cli/build.ts +70 -109
  26. package/cli/index.ts +148 -159
  27. package/cli/init.ts +235 -34
  28. package/cli/reporter.ts +1 -0
  29. package/cli/run.ts +266 -57
  30. package/cli/types.ts +6 -11
  31. package/cli/util.ts +35 -0
  32. package/package.json +6 -2
  33. package/run/package.json +27 -0
  34. package/tests/array.run.js +7 -0
  35. package/tests/math.run.js +7 -0
  36. package/tests/sleep.run.js +7 -0
  37. package/transform/lib/coverage.js +325 -319
  38. package/transform/lib/index.js +51 -31
  39. package/transform/lib/index.js.map +1 -1
  40. package/transform/lib/mock.js +61 -55
  41. package/transform/lib/mock.js.map +1 -1
  42. package/transform/package.json +1 -1
  43. package/transform/src/index.ts +22 -3
  44. package/transform/src/mock.ts +1 -1
  45. package/asconfig.json +0 -31
  46. package/assembly/__tests__/example.spec.ts +0 -79
  47. package/assembly/reporters/tap.ts +0 -30
  48. package/assembly/src/group.ts +0 -44
  49. package/assembly/src/node.ts +0 -13
  50. package/test.config.json +0 -0
  51. package/tests/test.tap +0 -14
  52. package/unision +0 -38
  53. package/unision.pub +0 -1
  54. package/utils.ts +0 -1
package/cli/util.ts CHANGED
@@ -1,3 +1,8 @@
1
+ import { existsSync, readFileSync } from "fs";
2
+ import { Config } from "./types.js";
3
+ import chalk from "chalk";
4
+ import { delimiter, join } from "path";
5
+
1
6
  export function formatTime(ms: number): string {
2
7
  if (ms < 0) {
3
8
  throw new Error("Time should be a non-negative number.");
@@ -28,3 +33,33 @@ export function formatTime(ms: number): string {
28
33
 
29
34
  return `${us}us`;
30
35
  }
36
+
37
+ export function loadConfig(CONFIG_PATH: string, warn: boolean = false): Config {
38
+ if (!existsSync(CONFIG_PATH)) {
39
+ if (warn)
40
+ console.log(
41
+ `${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate config file in the current directory! Continuing with default config.`,
42
+ );
43
+ return new Config();
44
+ } else {
45
+ return Object.assign(
46
+ new Config(),
47
+ JSON.parse(readFileSync(CONFIG_PATH).toString()),
48
+ ) as Config;
49
+ }
50
+ }
51
+
52
+ export function getExec(exec: string): string | null {
53
+ const PATH = process.env.PATH.split(delimiter);
54
+
55
+ for (const pathDir of PATH) {
56
+ const fullPath = join(
57
+ pathDir,
58
+ exec + (process.platform === "win32" ? ".exe" : ""),
59
+ );
60
+ if (existsSync(fullPath)) {
61
+ return fullPath;
62
+ }
63
+ }
64
+ return null;
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -11,12 +11,14 @@
11
11
  "pretest": "node ./bin/index.js build",
12
12
  "build:transform": "tsc -p ./transform",
13
13
  "build:cli": "tsc -p cli",
14
+ "build:run": "tsc -p run",
14
15
  "prettier": "prettier -w .",
15
16
  "prepublish": "npm run build:cli && npm run build:transform && npm run test"
16
17
  },
17
18
  "devDependencies": {
18
19
  "@assemblyscript/wasi-shim": "^0.1.0",
19
20
  "@types/node": "^20.14.10",
21
+ "as-sleep": "^0.0.2",
20
22
  "as-test": "./",
21
23
  "assemblyscript": "^0.27.29",
22
24
  "assemblyscript-prettier": "^3.0.1",
@@ -29,7 +31,9 @@
29
31
  "as-variant": "^0.4.1",
30
32
  "chalk": "^5.3.0",
31
33
  "glob": "^11.0.0",
32
- "jest": "^29.7.0"
34
+ "jest": "^29.7.0",
35
+ "json-as": "^0.9.14",
36
+ "typer-diff": "^1.1.1"
33
37
  },
34
38
  "overrides": {
35
39
  "assemblyscript": "$assemblyscript",
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@as-test/run",
3
+ "version": "0.3.0",
4
+ "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
+ "main": "./lib/index.js",
6
+ "author": "Jairus Tanaka",
7
+ "contributors": [],
8
+ "license": "MIT",
9
+ "scripts": {},
10
+ "devDependencies": {
11
+ "typescript": "^5.5.3"
12
+ },
13
+ "dependencies": {},
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/JairusSW/as-test.git"
17
+ },
18
+ "keywords": [],
19
+ "bugs": {
20
+ "url": "https://github.com/JairusSW/as-test/issues"
21
+ },
22
+ "homepage": "https://github.com/JairusSW/as-test#readme",
23
+ "type": "module",
24
+ "publishConfig": {
25
+ "@JairusSW:registry": "https://npm.pkg.github.com"
26
+ }
27
+ }
@@ -0,0 +1,7 @@
1
+ import { readFileSync } from "fs";
2
+ import { instantiate } from "../build/array.spec.js";
3
+
4
+ const binary = readFileSync("./build/array.spec.wasm");
5
+ const module = new WebAssembly.Module(binary);
6
+
7
+ const exports = instantiate(module, {});
@@ -0,0 +1,7 @@
1
+ import { readFileSync } from "fs";
2
+ import { instantiate } from "../build/math.spec.js";
3
+
4
+ const binary = readFileSync("./build/math.spec.wasm");
5
+ const module = new WebAssembly.Module(binary);
6
+
7
+ const exports = instantiate(module, {});
@@ -0,0 +1,7 @@
1
+ import { readFileSync } from "fs";
2
+ import { instantiate } from "../build/sleep.spec.js";
3
+
4
+ const binary = readFileSync("./build/sleep.spec.wasm");
5
+ const module = new WebAssembly.Module(binary);
6
+
7
+ const exports = instantiate(module, {});