as-test 1.1.6 → 1.1.7

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 (42) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +4 -9
  3. package/assembly/index.ts +10 -15
  4. package/assembly/src/expectation.ts +11 -11
  5. package/assembly/src/fuzz.ts +11 -7
  6. package/assembly/src/log.ts +2 -2
  7. package/assembly/src/suite.ts +5 -5
  8. package/assembly/src/tests.ts +8 -8
  9. package/assembly/util/wipc.ts +5 -1
  10. package/bin/build-worker-pool.js +146 -142
  11. package/bin/build-worker.js +37 -34
  12. package/bin/commands/build-core.js +577 -465
  13. package/bin/commands/build.js +49 -29
  14. package/bin/commands/clean-core.js +120 -113
  15. package/bin/commands/clean.js +14 -8
  16. package/bin/commands/doctor-core.js +288 -289
  17. package/bin/commands/doctor.js +1 -1
  18. package/bin/commands/fuzz-core.js +467 -414
  19. package/bin/commands/fuzz.js +27 -10
  20. package/bin/commands/init-core.js +905 -794
  21. package/bin/commands/init.js +2 -2
  22. package/bin/commands/run-core.js +2675 -2344
  23. package/bin/commands/run.js +43 -25
  24. package/bin/commands/test.js +56 -32
  25. package/bin/commands/web-runner-source.js +1 -1
  26. package/bin/commands/web-session.js +516 -525
  27. package/bin/coverage-points.js +363 -341
  28. package/bin/crash-store.js +56 -66
  29. package/bin/index.js +4092 -3150
  30. package/bin/reporters/default.js +1090 -890
  31. package/bin/reporters/tap.js +319 -325
  32. package/bin/types.js +67 -67
  33. package/bin/util.js +1290 -1239
  34. package/bin/wipc.js +70 -73
  35. package/lib/build/index.d.ts +3 -1
  36. package/lib/build/index.js +1039 -1034
  37. package/lib/build/web-runner/client.js +1 -1
  38. package/lib/build/web-runner/html.js +1 -1
  39. package/lib/build/web-runner/worker.js +1 -1
  40. package/package.json +6 -3
  41. package/transform/lib/log.js +9 -5
  42. package/assembly/util/json.ts +0 -112
@@ -1,5 +1,5 @@
1
1
  export function buildWebRunnerClientSource() {
2
- return String.raw `const runnerOrigin = location.origin;
2
+ return String.raw`const runnerOrigin = location.origin;
3
3
  const workerUrl = new URL("/worker.js", runnerOrigin);
4
4
  const wsUrl = new URL("/ws", runnerOrigin);
5
5
  wsUrl.protocol = location.protocol == "https:" ? "wss:" : "ws:";
@@ -1,5 +1,5 @@
1
1
  export function buildWebRunnerHtml() {
2
- return String.raw `<!doctype html>
2
+ return String.raw`<!doctype html>
3
3
  <html lang="en">
4
4
  <head>
5
5
  <meta charset="utf-8" />
@@ -1,5 +1,5 @@
1
1
  export function buildWebRunnerWorkerSource() {
2
- return String.raw `let replyState = null;
2
+ return String.raw`let replyState = null;
3
3
  let replyBytes = null;
4
4
  const WIPC_MAGIC = [0x57, 0x49, 0x50, 0x43];
5
5
  let runtimeEnv = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "author": "Jairus Tanaka",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,6 +12,9 @@
12
12
  "typer-diff": "^1.1.1",
13
13
  "wipc-js": "^0.1.1"
14
14
  },
15
+ "peerDependencies": {
16
+ "json-as": ">=1.0.0"
17
+ },
15
18
  "devDependencies": {
16
19
  "@assemblyscript/wasi-shim": "^0.1.0",
17
20
  "@eslint/js": "^10.0.1",
@@ -20,7 +23,7 @@
20
23
  "as-test": "./",
21
24
  "assemblyscript": "^0.28.17",
22
25
  "assemblyscript-prettier": "^3.0.4",
23
- "json-as": "^1.3.5",
26
+ "json-as": "^1.3.6",
24
27
  "prettier": "3.8.3",
25
28
  "try-as": "^1.0.1",
26
29
  "typescript": "^6.0.3",
@@ -94,7 +97,7 @@
94
97
  "docs:preview": "vitepress preview docs",
95
98
  "format": "prettier -w .",
96
99
  "release:check": "npm run build:cli && npm run build:lib && npm run build:transform && npm run test && npm run test:integration && npm run test:examples && npm pack --dry-run --cache /tmp/as-test-npm-cache",
97
- "prepublishOnly": "npm run build:cli && npm run build:lib && npm run build:transform && npm run format && npm run test && npm run test:integration"
100
+ "prepublishOnly": "npm run build:cli && npm run build:lib && npm run build:transform && npm run test && npm run test:integration && npm run format"
98
101
  },
99
102
  "type": "module"
100
103
  }
@@ -4,7 +4,7 @@ import { toString } from "./util.js";
4
4
  const LOG_CALL_FN = "__as_test_log_call";
5
5
  const LOG_ENABLED_IMPORT = "__as_test_log_is_enabled_internal";
6
6
  const LOG_SERIALIZED_IMPORT = "__as_test_log_serialized_internal";
7
- const LOG_DEFAULT_IMPORT = "__as_test_log_default_internal";
7
+ const LOG_JSON_IMPORT = "__as_test_log_json_internal";
8
8
  export class LogTransform extends Visitor {
9
9
  parser;
10
10
  activeSource = null;
@@ -27,11 +27,15 @@ export class LogTransform extends Visitor {
27
27
  return;
28
28
  }
29
29
  const asTestPath = detectAsTestImportPath(node.text) ?? "as-test";
30
- const tokenizer = new Tokenizer(new Source(0, node.normalizedPath, `import { __as_test_log_is_enabled as ${LOG_ENABLED_IMPORT}, __as_test_log_serialized as ${LOG_SERIALIZED_IMPORT}, __as_test_log_default as ${LOG_DEFAULT_IMPORT} } from "${asTestPath}";`));
31
- this.parser.currentSource = tokenizer.source;
32
- node.statements.unshift(this.parser.parseTopLevelStatement(tokenizer));
30
+ const asTestTokenizer = new Tokenizer(new Source(0, node.normalizedPath, `import { __as_test_log_is_enabled as ${LOG_ENABLED_IMPORT}, __as_test_log_serialized as ${LOG_SERIALIZED_IMPORT} } from "${asTestPath}";`));
31
+ this.parser.currentSource = asTestTokenizer.source;
32
+ node.statements.unshift(this.parser.parseTopLevelStatement(asTestTokenizer));
33
33
  this.parser.currentSource = node;
34
- const callTokenizer = new Tokenizer(new Source(0, node.normalizedPath, `function ${LOG_CALL_FN}<T>(value: T): void { if (!${LOG_ENABLED_IMPORT}()) return; ${LOG_SERIALIZED_IMPORT}(${LOG_DEFAULT_IMPORT}<T>(value)); }`));
34
+ const jsonTokenizer = new Tokenizer(new Source(0, node.normalizedPath, `import { JSON as ${LOG_JSON_IMPORT} } from "json-as/assembly";`));
35
+ this.parser.currentSource = jsonTokenizer.source;
36
+ node.statements.unshift(this.parser.parseTopLevelStatement(jsonTokenizer));
37
+ this.parser.currentSource = node;
38
+ const callTokenizer = new Tokenizer(new Source(0, node.normalizedPath, `function ${LOG_CALL_FN}<T>(value: T): void { if (!${LOG_ENABLED_IMPORT}()) return; ${LOG_SERIALIZED_IMPORT}(${LOG_JSON_IMPORT}.stringify<T>(value)); }`));
35
39
  this.parser.currentSource = callTokenizer.source;
36
40
  node.statements.push(this.parser.parseTopLevelStatement(callTokenizer));
37
41
  this.parser.currentSource = node;
@@ -1,112 +0,0 @@
1
- import { formatValue } from "./format";
2
-
3
- export function quote(value: string): string {
4
- return '"' + escape(value) + '"';
5
- }
6
-
7
- export function rawOrNull(value: string): string {
8
- return value.length ? value : "null";
9
- }
10
-
11
- export function stringifyValue<T>(value: T): string {
12
- if (isNullable<T>() && changetype<usize>(value) == <usize>0) {
13
- return "null";
14
- }
15
-
16
- if (isBoolean<T>()) {
17
- return (value as bool) ? "true" : "false";
18
- }
19
-
20
- if (isInteger<T>() || isFloat<T>()) {
21
- // @ts-expect-error: type
22
- return value.toString();
23
- }
24
-
25
- if (isString<T>()) {
26
- return quote(value as string);
27
- }
28
-
29
- if (isArray<T>()) {
30
- // @ts-expect-error: type
31
- return stringifyArray<valueof<T>>(value as valueof<T>[]);
32
- }
33
-
34
- if (isManaged<T>()) {
35
- // @ts-expect-error: method exists
36
- return value.__as_test_json();
37
- }
38
-
39
- const formatted = formatValue<T>(value);
40
- if (formatted != "none") {
41
- return quote(formatted);
42
- }
43
-
44
- return quote(nameof<T>());
45
- }
46
-
47
- export function __as_test_json_value<T>(value: T): string {
48
- return stringifyValue<T>(value);
49
- }
50
-
51
- function stringifyArray<T>(values: T[]): string {
52
- if (!values.length) return "[]";
53
-
54
- let out = "[";
55
- for (let i = 0; i < values.length; i++) {
56
- if (i) out += ",";
57
- out += stringifyValue<T>(unchecked(values[i]));
58
- }
59
- out += "]";
60
- return out;
61
- }
62
-
63
- function escape(value: string): string {
64
- let out = "";
65
- for (let i = 0; i < value.length; i++) {
66
- const ch = value.charCodeAt(i);
67
- if (ch == 34) {
68
- out += '\\"';
69
- } else if (ch == 92) {
70
- out += "\\\\";
71
- } else if (ch == 8) {
72
- out += "\\b";
73
- } else if (ch == 12) {
74
- out += "\\f";
75
- } else if (ch == 10) {
76
- out += "\\n";
77
- } else if (ch == 13) {
78
- out += "\\r";
79
- } else if (ch == 9) {
80
- out += "\\t";
81
- } else if (ch < 32) {
82
- out += unicodeEscape(ch);
83
- } else if (ch >= 0xd800 && ch <= 0xdfff) {
84
- if (ch <= 0xdbff && i + 1 < value.length) {
85
- const next = value.charCodeAt(i + 1);
86
- if (next >= 0xdc00 && next <= 0xdfff) {
87
- out += value.charAt(i);
88
- out += value.charAt(i + 1);
89
- i++;
90
- continue;
91
- }
92
- }
93
- out += unicodeEscape(ch);
94
- } else {
95
- out += value.charAt(i);
96
- }
97
- }
98
- return out;
99
- }
100
-
101
- function unicodeEscape(code: i32): string {
102
- let out = "\\u";
103
- out += hexNibble((code >> 12) & 0xf);
104
- out += hexNibble((code >> 8) & 0xf);
105
- out += hexNibble((code >> 4) & 0xf);
106
- out += hexNibble(code & 0xf);
107
- return out;
108
- }
109
-
110
- function hexNibble(value: i32): string {
111
- return String.fromCharCode(value < 10 ? 48 + value : 87 + value);
112
- }