xbintsc 0.3.15 → 0.3.18

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 (156) hide show
  1. package/dist/src/cli/main.js +4 -4
  2. package/dist/src/cli/main.js.map +1 -1
  3. package/dist/src/codegen/generator/state.js +8 -0
  4. package/dist/src/codegen/generator/state.js.map +1 -1
  5. package/dist/src/codegen/generator/tables.js +8 -0
  6. package/dist/src/codegen/generator/tables.js.map +1 -1
  7. package/dist/src/driver/bundler/graph.d.ts +8 -0
  8. package/dist/src/driver/bundler/graph.js +85 -0
  9. package/dist/src/driver/bundler/graph.js.map +1 -0
  10. package/dist/src/driver/bundler/merge.d.ts +11 -0
  11. package/dist/src/driver/bundler/merge.js +288 -0
  12. package/dist/src/driver/bundler/merge.js.map +1 -0
  13. package/dist/src/driver/bundler/resolve.d.ts +12 -0
  14. package/dist/src/driver/bundler/resolve.js +246 -0
  15. package/dist/src/driver/bundler/resolve.js.map +1 -0
  16. package/dist/src/driver/bundler/symbols.d.ts +15 -0
  17. package/dist/src/driver/bundler/symbols.js +51 -0
  18. package/dist/src/driver/bundler/symbols.js.map +1 -0
  19. package/dist/src/driver/bundler/types.d.ts +36 -0
  20. package/dist/src/driver/bundler/types.js +5 -0
  21. package/dist/src/driver/bundler/types.js.map +1 -0
  22. package/dist/src/driver/modules.d.ts +9 -16
  23. package/dist/src/driver/modules.js +8 -644
  24. package/dist/src/driver/modules.js.map +1 -1
  25. package/dist/src/extensions/catalog.js +2 -1
  26. package/dist/src/extensions/catalog.js.map +1 -1
  27. package/dist/src/extensions/gui/index.d.ts +24 -0
  28. package/dist/src/extensions/gui/index.js +101 -0
  29. package/dist/src/extensions/gui/index.js.map +1 -0
  30. package/dist/tests/e2e/compile-basics.test.d.ts +4 -0
  31. package/dist/tests/e2e/compile-basics.test.js +134 -0
  32. package/dist/tests/e2e/compile-basics.test.js.map +1 -0
  33. package/dist/tests/e2e/compile-builtins.test.d.ts +4 -0
  34. package/dist/tests/e2e/compile-builtins.test.js +191 -0
  35. package/dist/tests/e2e/compile-builtins.test.js.map +1 -0
  36. package/dist/tests/e2e/compile-control-flow.test.d.ts +4 -0
  37. package/dist/tests/e2e/compile-control-flow.test.js +190 -0
  38. package/dist/tests/e2e/compile-control-flow.test.js.map +1 -0
  39. package/dist/tests/e2e/compile-modules.test.d.ts +4 -0
  40. package/dist/tests/e2e/compile-modules.test.js +48 -0
  41. package/dist/tests/e2e/compile-modules.test.js.map +1 -0
  42. package/dist/tests/e2e/compile-objects-classes.test.d.ts +4 -0
  43. package/dist/tests/e2e/compile-objects-classes.test.js +362 -0
  44. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -0
  45. package/dist/tests/e2e/differential-helpers.d.ts +12 -0
  46. package/dist/tests/e2e/differential-helpers.js +16 -0
  47. package/dist/tests/e2e/differential-helpers.js.map +1 -0
  48. package/dist/tests/e2e/differential-language.test.d.ts +4 -0
  49. package/dist/tests/e2e/{differential.test.js → differential-language.test.js} +5 -287
  50. package/dist/tests/e2e/differential-language.test.js.map +1 -0
  51. package/dist/tests/e2e/differential-symbols.test.d.ts +4 -0
  52. package/dist/tests/e2e/differential-symbols.test.js +92 -0
  53. package/dist/tests/e2e/differential-symbols.test.js.map +1 -0
  54. package/dist/tests/e2e/differential-values.test.d.ts +4 -0
  55. package/dist/tests/e2e/differential-values.test.js +197 -0
  56. package/dist/tests/e2e/differential-values.test.js.map +1 -0
  57. package/dist/tests/e2e/gui.test.d.ts +12 -0
  58. package/dist/tests/e2e/gui.test.js +493 -0
  59. package/dist/tests/e2e/gui.test.js.map +1 -0
  60. package/dist/tests/e2e/runtime-coverage-buffer.test.d.ts +4 -0
  61. package/dist/tests/e2e/runtime-coverage-buffer.test.js +97 -0
  62. package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -0
  63. package/dist/tests/e2e/runtime-coverage-globals.test.d.ts +4 -0
  64. package/dist/tests/e2e/runtime-coverage-globals.test.js +149 -0
  65. package/dist/tests/e2e/runtime-coverage-globals.test.js.map +1 -0
  66. package/dist/tests/e2e/runtime-coverage-node-modules.test.d.ts +4 -0
  67. package/dist/tests/e2e/runtime-coverage-node-modules.test.js +177 -0
  68. package/dist/tests/e2e/runtime-coverage-node-modules.test.js.map +1 -0
  69. package/dist/tests/e2e/runtime-coverage-streams.test.d.ts +4 -0
  70. package/dist/tests/e2e/runtime-coverage-streams.test.js +161 -0
  71. package/dist/tests/e2e/runtime-coverage-streams.test.js.map +1 -0
  72. package/dist/tests/e2e/runtime-coverage-system.test.d.ts +4 -0
  73. package/dist/tests/e2e/runtime-coverage-system.test.js +91 -0
  74. package/dist/tests/e2e/runtime-coverage-system.test.js.map +1 -0
  75. package/dist/tests/e2e/timers.test.d.ts +7 -0
  76. package/dist/tests/e2e/timers.test.js +63 -0
  77. package/dist/tests/e2e/timers.test.js.map +1 -0
  78. package/package.json +2 -1
  79. package/runtime/ext_gui/css.cpp +743 -0
  80. package/runtime/ext_gui/css.h +98 -0
  81. package/runtime/ext_gui/document.cpp +264 -0
  82. package/runtime/ext_gui/document.h +89 -0
  83. package/runtime/ext_gui/dom.cpp +472 -0
  84. package/runtime/ext_gui/dom.h +71 -0
  85. package/runtime/ext_gui/gui.cpp +457 -0
  86. package/runtime/ext_gui/gui_engine.h +81 -0
  87. package/runtime/ext_gui/image.cpp +125 -0
  88. package/runtime/ext_gui/image.h +42 -0
  89. package/runtime/ext_gui/layout.cpp +748 -0
  90. package/runtime/ext_gui/layout.h +93 -0
  91. package/runtime/ext_gui/paint.cpp +137 -0
  92. package/runtime/ext_gui/paint.h +75 -0
  93. package/runtime/ext_gui/renderer.cpp +959 -0
  94. package/runtime/ext_gui/renderer.h +68 -0
  95. package/runtime/ext_gui/stb_image.h +7988 -0
  96. package/runtime/ext_gui/style.cpp +771 -0
  97. package/runtime/ext_gui/style.h +117 -0
  98. package/runtime/ext_gui/text.cpp +378 -0
  99. package/runtime/ext_gui/text.h +78 -0
  100. package/runtime/ext_gui/window.cpp +405 -0
  101. package/runtime/ext_node/fs/fs_common.h +13 -527
  102. package/runtime/ext_node/fs/parts/buffer-bridge.inc +6 -0
  103. package/runtime/ext_node/fs/parts/builtins.inc +69 -0
  104. package/runtime/ext_node/fs/parts/dir.inc +47 -0
  105. package/runtime/ext_node/fs/parts/encoding.inc +186 -0
  106. package/runtime/ext_node/fs/parts/errors.inc +66 -0
  107. package/runtime/ext_node/fs/parts/flags.inc +39 -0
  108. package/runtime/ext_node/fs/parts/platform.inc +86 -0
  109. package/runtime/ext_node/fs/parts/promisify.inc +15 -0
  110. package/runtime/ext_node/fs/parts/time.inc +9 -0
  111. package/runtime/rt.h +33 -0
  112. package/runtime/xt_builtins.c +4 -0
  113. package/runtime/xt_containers/access.inc +168 -0
  114. package/runtime/xt_containers/arrays.inc +108 -0
  115. package/runtime/xt_containers/boxes.inc +11 -0
  116. package/runtime/xt_containers/objects.inc +326 -0
  117. package/runtime/xt_containers.c +8 -618
  118. package/runtime/xt_io/base64.inc +87 -0
  119. package/runtime/xt_io/console.inc +119 -0
  120. package/runtime/xt_io/exception.inc +142 -0
  121. package/runtime/xt_io/inspect.inc +212 -0
  122. package/runtime/xt_io.c +8 -553
  123. package/runtime/xt_loop.c +262 -24
  124. package/runtime/xt_regex/api.inc +58 -0
  125. package/runtime/xt_regex/helpers.inc +68 -0
  126. package/runtime/xt_regex/matcher.inc +248 -0
  127. package/runtime/xt_regex/parser.inc +236 -0
  128. package/runtime/xt_regex/types.inc +58 -0
  129. package/runtime/xt_regex.h +9 -672
  130. package/runtime/xt_values/arithmetic.inc +150 -0
  131. package/runtime/xt_values/comparison.inc +112 -0
  132. package/runtime/xt_values/constructors.inc +41 -0
  133. package/runtime/xt_values/conversions.inc +115 -0
  134. package/runtime/xt_values/number-format.inc +180 -0
  135. package/runtime/xt_values/strings.inc +22 -0
  136. package/runtime/xt_values.c +10 -626
  137. package/scripts/build-gui.ts +317 -0
  138. package/src/cli/main.ts +4 -3
  139. package/src/codegen/generator/state.ts +8 -0
  140. package/src/codegen/generator/tables.ts +8 -0
  141. package/src/driver/bundler/graph.ts +95 -0
  142. package/src/driver/bundler/merge.ts +312 -0
  143. package/src/driver/bundler/resolve.ts +240 -0
  144. package/src/driver/bundler/symbols.ts +55 -0
  145. package/src/driver/bundler/types.ts +37 -0
  146. package/src/driver/modules.ts +9 -693
  147. package/src/extensions/catalog.ts +2 -1
  148. package/src/extensions/gui/index.ts +107 -0
  149. package/dist/tests/e2e/compile.test.d.ts +0 -8
  150. package/dist/tests/e2e/compile.test.js +0 -893
  151. package/dist/tests/e2e/compile.test.js.map +0 -1
  152. package/dist/tests/e2e/differential.test.d.ts +0 -7
  153. package/dist/tests/e2e/differential.test.js.map +0 -1
  154. package/dist/tests/e2e/runtime-coverage.test.d.ts +0 -11
  155. package/dist/tests/e2e/runtime-coverage.test.js +0 -646
  156. package/dist/tests/e2e/runtime-coverage.test.js.map +0 -1
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Runtime-coverage tests for the global objects, console helpers and BigInt.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: globals", (h) => {
8
+ it("covers Object, Map, Set and JSON globals", () => {
9
+ const source = `
10
+ console.log(Object.keys({a:1,b:2}).join(","), Object.values({a:1,b:2}).join(","), Object.entries({a:1,b:2}).map(e => e[0]+e[1]).join(","));
11
+ console.log(Object.getOwnPropertyNames([1,2]).join(","), Object.getOwnPropertyNames("ab").join(","));
12
+ console.log(Object.assign({a:1}, {b:2}, {a:3}).a, Object.assign({}, {b:2}).b);
13
+ const fz = Object.freeze({x:1});
14
+ console.log(Object.isFrozen(fz), Object.isFrozen({}));
15
+ console.log(Object.hasOwn({x:1},"x"), Object.hasOwn({x:1},"y"));
16
+ console.log(Object.is(NaN, NaN), Object.is(0, -0), Object.is(1,1), Object.is({},{}));
17
+ const proto = { greet() { return "hi"; } };
18
+ const child = Object.create(proto);
19
+ console.log(child.greet(), Object.getPrototypeOf(child) === proto);
20
+ const grouped = Object.groupBy([1,2,3,4], (n: number) => n % 2 === 0 ? "even" : "odd");
21
+ console.log(grouped.odd.join(","), grouped.even.join(","));
22
+ console.log(Object.fromEntries([["a",1],["b",2]]).a);
23
+ console.log(JSON.stringify({a:1,b:[2,3],c:"x"}), JSON.parse('{"a":1,"b":[2,3]}').b[1]);
24
+ const m = new Map<string, number>(); m.set("a",1); m.set("b",2); console.log(m.get("a"), m.size, m.has("b"), m.delete("a"), m.size);
25
+ const s = new Set<number>(); s.add(1); s.add(2); s.add(1); console.log(s.size, s.has(2), s.delete(1), s.size);
26
+ console.log([...m.keys()].join(","), [...s.values()].join(","));
27
+ `;
28
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
29
+ expect(stdout.split("\n")).toEqual([
30
+ "a,b 1,2 a1,b2",
31
+ "0,1,length 0,1,length",
32
+ "3 2",
33
+ "true false",
34
+ "true false",
35
+ "true false true false",
36
+ "hi true",
37
+ "1,3 2,4",
38
+ "1",
39
+ '{"a":1,"b":[2,3],"c":"x"} 3',
40
+ "1 2 true true 1",
41
+ "2 true true 1",
42
+ "b 2",
43
+ ]);
44
+ });
45
+ it("uses the console surface, inspect and base64 helpers", () => {
46
+ const source = `
47
+ console.count("x");
48
+ console.count("x");
49
+ console.countReset("x");
50
+ console.count("x");
51
+ console.group("g");
52
+ console.groupEnd();
53
+ console.assert(true, "no");
54
+ console.assert(false, "assert-msg");
55
+ console.dir({ a: 1 });
56
+ console.time("t");
57
+ console.timeLog("t");
58
+ console.timeEnd("t");
59
+ console.table([{ a: 1 }, { a: 2 }]);
60
+ console.warn("warn");
61
+ console.error("err");
62
+ console.info("info");
63
+ console.log(btoa("hello"), atob("aGVsbG8="));
64
+ const cyc: any = { a: 1 };
65
+ cyc.self = cyc;
66
+ console.log(cyc);
67
+ console.log({ b: 2, a: 1 });
68
+ console.log([1, "two", true, null, undefined, 3n]);
69
+ console.log(import.meta.url.length > 0, typeof import.meta.dirname, typeof import.meta.filename);
70
+ `;
71
+ const stdout = h
72
+ .runProgram(source, { extensions: true, timeout: TIMEOUT })
73
+ .split("\n")
74
+ .map((line) => (/^t: .*ms$/.test(line) ? "t: <time>" : line))
75
+ .join("\n");
76
+ expect(stdout.split("\n")).toEqual([
77
+ "x: 1",
78
+ "x: 2",
79
+ "x: 1",
80
+ "g",
81
+ "{ a: 1 }",
82
+ "t: <time>",
83
+ "t: <time>",
84
+ "[ { a: 1 }, { a: 2 } ]",
85
+ "info",
86
+ "aGVsbG8= hello",
87
+ "{ a: 1, self: [Circular *1] }",
88
+ "{ b: 2, a: 1 }",
89
+ "[ 1, 'two', true, null, undefined, 3n ]",
90
+ "true string string",
91
+ ]);
92
+ });
93
+ it("computes with BigInt", () => {
94
+ const source = `
95
+ console.log(BigInt("123"), BigInt(456), BigInt(true), BigInt(false), BigInt(10n));
96
+ console.log(10n + 20n, 10n - 3n, 2n * 3n, 10n / 3n, 10n % 3n, 2n ** 10n);
97
+ console.log(-5n, +5n, 5n < 10n, 5n == 5, 5n === 5);
98
+ console.log(255n & 15n, 255n | 15n, 255n ^ 15n, ~0n, 1n << 4n, 256n >> 4n);
99
+ console.log(10n > 5n, 10n >= 10n, 10n < 11n, 10n <= 9n, 5n != 6n, 5n !== 6);
100
+ console.log((123456789012345678901234567890n).toString());
101
+ console.log(Number(10n), +10n, (10n).toString(16), (255n).toString(2), (10n).toString(36));
102
+ try { BigInt(3.5); console.log("no"); } catch (e: any) { console.log("range threw"); }
103
+ try { BigInt({} as any); console.log("no"); } catch (e: any) { console.log("type threw"); }
104
+ console.log(5n ** 0n, 0n ** 5n, 2n ** 64n);
105
+ console.log((0n).toString(16), (-255n).toString(16));
106
+ console.log(BigInt(-12), (-12n).toString(), (-10n) / 3n, (-10n) % 3n);
107
+ console.log(100000000000000000000n + 1n, 99999999999999999999n * 3n);
108
+ console.log(18446744073709551616n > 18446744073709551615n, 18446744073709551615n < 18446744073709551616n, 18446744073709551616n === 18446744073709551616n);
109
+ console.log(1n << 100n, 1n << 200n, 2n ** 100n, 2n ** 200n);
110
+ console.log(-1n & 255n, -1n | 0n, -5n ^ 3n, ~255n, -256n >> 4n, -1n >> 100n);
111
+ console.log(BigInt("0xff"), BigInt("0b101"), BigInt("0o17"), BigInt(" 42 "));
112
+ try { BigInt("abc"); console.log("no"); } catch (e: any) { console.log("syntax threw"); }
113
+ console.log(BigInt("-0"), BigInt("+5"), (255n).toString(8), (255n).toString(16));
114
+ console.log(0n == 0, 0n === 0, 1n < 1, 1n > 0.5);
115
+ console.log((2n ** 64n) / 3n, (2n ** 64n) % 7n);
116
+ console.log((-(2n ** 64n)) / 3n, (-(2n ** 64n)) % 7n);
117
+ console.log((10n).valueOf(), (10n) + "");
118
+ console.log(9007199254740993n, BigInt(9007199254740993));
119
+ `;
120
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
121
+ expect(stdout.split("\n")).toEqual([
122
+ "123n 456n 1n 0n 10n",
123
+ "30n 7n 6n 3n 1n 1024n",
124
+ "-5n 5n true true false",
125
+ "15n 255n 240n -1n 16n 16n",
126
+ "true true true false true true",
127
+ "123456789012345678901234567890",
128
+ "10 10n a 11111111 a",
129
+ "range threw",
130
+ "type threw",
131
+ "1n 0n 18446744073709551616n",
132
+ "0 -ff",
133
+ "-12n -12 -3n -1n",
134
+ "100000000000000000001n 299999999999999999997n",
135
+ "true true true",
136
+ "1267650600228229401496703205376n 1606938044258990275541962092341162602522202993782792835301376n 1267650600228229401496703205376n 1606938044258990275541962092341162602522202993782792835301376n",
137
+ "255n -1n -8n -256n -16n -1n",
138
+ "255n 5n 15n 42n",
139
+ "syntax threw",
140
+ "0n 5n 377 ff",
141
+ "true false false true",
142
+ "6148914691236517205n 2n",
143
+ "-6148914691236517205n -2n",
144
+ "10n 10",
145
+ "9007199254740993n 9007199254740992n",
146
+ ]);
147
+ });
148
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
149
+ //# sourceMappingURL=runtime-coverage-globals.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-globals.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-globals.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,2BAA2B,EAC3B,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;OAkBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,eAAe;YACf,uBAAuB;YACvB,KAAK;YACL,YAAY;YACZ,YAAY;YACZ,uBAAuB;YACvB,SAAS;YACT,SAAS;YACT,GAAG;YACH,6BAA6B;YAC7B,iBAAiB;YACjB,eAAe;YACf,KAAK;SACN,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;OAwBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC;aACb,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;aAC1D,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aAC5D,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,MAAM;YACN,MAAM;YACN,MAAM;YACN,GAAG;YACH,UAAU;YACV,WAAW;YACX,WAAW;YACX,wBAAwB;YACxB,MAAM;YACN,gBAAgB;YAChB,+BAA+B;YAC/B,gBAAgB;YAChB,yCAAyC;YACzC,oBAAoB;SACrB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;OAyBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,qBAAqB;YACrB,uBAAuB;YACvB,wBAAwB;YACxB,2BAA2B;YAC3B,gCAAgC;YAChC,gCAAgC;YAChC,qBAAqB;YACrB,aAAa;YACb,YAAY;YACZ,6BAA6B;YAC7B,OAAO;YACP,kBAAkB;YAClB,+CAA+C;YAC/C,gBAAgB;YAChB,iMAAiM;YACjM,6BAA6B;YAC7B,iBAAiB;YACjB,cAAc;YACd,cAAc;YACd,uBAAuB;YACvB,yBAAyB;YACzB,2BAA2B;YAC3B,QAAQ;YACR,qCAAqC;SACtC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for `util` and `assert`.
3
+ */
4
+ export {};
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Runtime-coverage tests for `util` and `assert`.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: node-modules", (h) => {
8
+ it("exercises util helpers and predicates", () => {
9
+ const source = `
10
+ import util, {
11
+ format, formatWithOptions, inspect, isDeepStrictEqual, inherits, deprecate, promisify,
12
+ isString, isNumber, isBoolean, isUndefined, isNull, isFunction, isArray, isObject,
13
+ isBuffer, isDate, isRegExp, isPromise, isError,
14
+ } from "util";
15
+
16
+ console.log(format("%s %d %i %f %j %o %O %% %c", "s", 3.9, 4.2, 1.5, { a: 1 }, { b: 2 }, [1, 2], "css"));
17
+ console.log(format("%s", { a: 1 }), "|", format("%d", "5"), "|", format("%f", "2.5"));
18
+ console.log(format(1, "two", { three: 3 }));
19
+ console.log(format("only %s"), "|", format("%s and %d", "a"));
20
+ console.log(formatWithOptions({ colors: true }, "%s=%d", "x", 2));
21
+ console.log(inspect(undefined), inspect(null), inspect(true), inspect(1), inspect(10n), inspect("str"));
22
+ console.log(inspect([1, [2, [3, [4]]]]));
23
+ console.log(inspect({ a: 1, nested: { b: [1, 2] } }));
24
+ function f(): void {}
25
+ console.log(inspect(f));
26
+ console.log(inspect(new Date(0)));
27
+ console.log(inspect(/ab+c/gi));
28
+ console.log(isDeepStrictEqual({ a: [1, { b: 2 }] }, { a: [1, { b: 2 }] }), isDeepStrictEqual({ a: 1 }, { a: 2 }));
29
+ console.log(isDeepStrictEqual([1, 2], [1, 2, 3]), isDeepStrictEqual(NaN, NaN));
30
+ class Base {}
31
+ class Derived extends Base {}
32
+ const d = new Derived();
33
+ console.log(d instanceof Base);
34
+ const dep = deprecate(f, "old");
35
+ console.log(dep === f);
36
+ function addAsync(a: number, b: number, cb: (e: unknown, v: number) => void): void { cb(null, a + b); }
37
+ function failAsync(cb: (e: unknown, v: unknown) => void): void { cb(new Error("boom"), null); }
38
+ const add = promisify(addAsync);
39
+ add(2, 3).then((v: number) => { console.log("add", v); });
40
+ const failing = promisify(failAsync);
41
+ failing().then(() => { console.log("no"); }, (e: any) => { console.log("err", e.message); });
42
+ console.log(
43
+ isString("x"), isNumber(1), isBoolean(true), isUndefined(undefined), isNull(null),
44
+ isFunction(f), isArray([]), isObject({}), isBuffer(Buffer.from("x")), isDate(new Date()),
45
+ isRegExp(/x/), isPromise(Promise.resolve(1)), isError(new Error("e")),
46
+ );
47
+ console.log(util.format("%s!", "ns"), util.isNumber(3));
48
+ `;
49
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
50
+ expect(stdout.split("\n")).toEqual([
51
+ "s 3 4 1.500000 {\"a\":1} { b: 2 } [ 1, 2 ] % 'css'",
52
+ "{ a: 1 } | 5 | 2.500000",
53
+ "1 'two' { three: 3 }",
54
+ "only %s | a and %d",
55
+ "x=2",
56
+ "undefined null true 1 10n 'str'",
57
+ "[ 1, [ 2, [Array] ] ]",
58
+ "{ a: 1, nested: { b: [Array] } }",
59
+ "[Function]",
60
+ "[object Object]",
61
+ "[object Object]",
62
+ "true false",
63
+ "false true",
64
+ "true",
65
+ "false",
66
+ "true true true true true true true true true true true true true",
67
+ "ns! true",
68
+ "add 5",
69
+ "err boom",
70
+ ]);
71
+ });
72
+ it("exercises the assert module", () => {
73
+ const source = `
74
+ import assert, { strictEqual, deepStrictEqual, throws, doesNotThrow, ifError, match, doesNotMatch, notStrictEqual, ok, equal, notEqual, deepEqual, notDeepEqual, rejects, doesNotReject } from "node:assert";
75
+
76
+ function check(label: string, fn: () => void): void {
77
+ try {
78
+ fn();
79
+ console.log(label, "ok");
80
+ } catch (e: any) {
81
+ console.log(label, "threw", e.name);
82
+ }
83
+ }
84
+
85
+ check("ok-pass", () => assert.ok(1));
86
+ check("ok-fail", () => assert.ok(0));
87
+ check("equal-pass", () => assert.equal(1, "1"));
88
+ check("equal-fail", () => assert.equal(1, 2, "custom equal"));
89
+ check("notEqual-pass", () => assert.notEqual(1, 2));
90
+ check("notEqual-fail", () => assert.notEqual(1, "1"));
91
+ check("strictEqual-pass", () => assert.strictEqual(1, 1));
92
+ check("strictEqual-fail", () => assert.strictEqual(1, "1"));
93
+ check("notStrictEqual-pass", () => assert.notStrictEqual(1, "1"));
94
+ check("notStrictEqual-fail", () => assert.notStrictEqual(1, 1));
95
+ check("deepEqual-pass", () => assert.deepEqual({ a: [1, 2] }, { a: [1, 2] }));
96
+ check("deepEqual-fail", () => assert.deepEqual({ a: 1 }, { a: 2 }));
97
+ check("notDeepEqual-pass", () => assert.notDeepEqual({ a: 1 }, { a: 2 }));
98
+ check("notDeepEqual-fail", () => assert.notDeepEqual({ a: 1 }, { a: 1 }));
99
+ check("deepStrictEqual-pass", () => assert.deepStrictEqual([1, { b: 2 }], [1, { b: 2 }]));
100
+ check("deepStrictEqual-fail", () => assert.deepStrictEqual([1], [2]));
101
+ check("notDeepStrictEqual-pass", () => assert.notDeepStrictEqual([1], [2]));
102
+ check("throws-pass", () => assert.throws(() => { throw new Error("x"); }));
103
+ check("throws-fail", () => assert.throws(() => {}));
104
+ check("throws-nonfn", () => assert.throws(1 as any));
105
+ check("throws-message", () => assert.throws(() => { throw new Error("x"); }, "boom"));
106
+ check("doesNotThrow-pass", () => assert.doesNotThrow(() => {}));
107
+ check("doesNotThrow-fail", () => assert.doesNotThrow(() => { throw new Error("y"); }));
108
+ check("ifError-null", () => assert.ifError(null));
109
+ check("ifError-undefined", () => assert.ifError(undefined));
110
+ check("ifError-obj", () => assert.ifError(new Error("z")));
111
+ check("ifError-value", () => assert.ifError("bad"));
112
+ check("match-regexp", () => assert.match("hello", /ell/));
113
+ check("match-string", () => assert.match("hello", "ell"));
114
+ check("match-fail", () => assert.match("hello", /xyz/, "no match"));
115
+ check("doesNotMatch-pass", () => assert.doesNotMatch("hello", /xyz/));
116
+ check("doesNotMatch-fail", () => assert.doesNotMatch("hello", /ell/));
117
+ check("fail-default", () => assert.fail());
118
+ check("fail-custom", () => assert.fail("custom failure"));
119
+
120
+ strictEqual(1, 1);
121
+ deepStrictEqual({ x: 1 }, { x: 1 });
122
+ throws(() => { throw new Error("n"); });
123
+ doesNotThrow(() => {});
124
+ ifError(null);
125
+ match("abc", /b/);
126
+ doesNotMatch("abc", /z/);
127
+ notStrictEqual(1, 2);
128
+ ok(true);
129
+ equal(1, "1");
130
+ notEqual(1, 2);
131
+ deepEqual([1], [1]);
132
+ notDeepEqual([1], [2]);
133
+ rejects();
134
+ doesNotReject();
135
+ console.log("named-imports ok");
136
+ `;
137
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
138
+ expect(stdout.split("\n")).toEqual([
139
+ "ok-pass ok",
140
+ "ok-fail threw AssertionError",
141
+ "equal-pass ok",
142
+ "equal-fail threw AssertionError",
143
+ "notEqual-pass ok",
144
+ "notEqual-fail threw AssertionError",
145
+ "strictEqual-pass ok",
146
+ "strictEqual-fail threw AssertionError",
147
+ "notStrictEqual-pass ok",
148
+ "notStrictEqual-fail threw AssertionError",
149
+ "deepEqual-pass ok",
150
+ "deepEqual-fail threw AssertionError",
151
+ "notDeepEqual-pass ok",
152
+ "notDeepEqual-fail threw AssertionError",
153
+ "deepStrictEqual-pass ok",
154
+ "deepStrictEqual-fail threw AssertionError",
155
+ "notDeepStrictEqual-pass ok",
156
+ "throws-pass ok",
157
+ "throws-fail threw AssertionError",
158
+ "throws-nonfn threw AssertionError",
159
+ "throws-message ok",
160
+ "doesNotThrow-pass ok",
161
+ "doesNotThrow-fail threw AssertionError",
162
+ "ifError-null ok",
163
+ "ifError-undefined ok",
164
+ "ifError-obj threw Error",
165
+ "ifError-value threw AssertionError",
166
+ "match-regexp ok",
167
+ "match-string ok",
168
+ "match-fail threw AssertionError",
169
+ "doesNotMatch-pass ok",
170
+ "doesNotMatch-fail threw AssertionError",
171
+ "fail-default threw AssertionError",
172
+ "fail-custom threw AssertionError",
173
+ "named-imports ok",
174
+ ]);
175
+ });
176
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
177
+ //# sourceMappingURL=runtime-coverage-node-modules.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-node-modules.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-node-modules.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,gCAAgC,EAChC,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,qDAAqD;YACrD,yBAAyB;YACzB,sBAAsB;YACtB,oBAAoB;YACpB,KAAK;YACL,iCAAiC;YACjC,uBAAuB;YACvB,kCAAkC;YAClC,YAAY;YACZ,iBAAiB;YACjB,iBAAiB;YACjB,YAAY;YACZ,YAAY;YACZ,MAAM;YACN,OAAO;YACP,kEAAkE;YAClE,UAAU;YACV,OAAO;YACP,UAAU;SACX,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+Dd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,YAAY;YACZ,8BAA8B;YAC9B,eAAe;YACf,iCAAiC;YACjC,kBAAkB;YAClB,oCAAoC;YACpC,qBAAqB;YACrB,uCAAuC;YACvC,wBAAwB;YACxB,0CAA0C;YAC1C,mBAAmB;YACnB,qCAAqC;YACrC,sBAAsB;YACtB,wCAAwC;YACxC,yBAAyB;YACzB,2CAA2C;YAC3C,4BAA4B;YAC5B,gBAAgB;YAChB,kCAAkC;YAClC,mCAAmC;YACnC,mBAAmB;YACnB,sBAAsB;YACtB,wCAAwC;YACxC,iBAAiB;YACjB,sBAAsB;YACtB,yBAAyB;YACzB,oCAAoC;YACpC,iBAAiB;YACjB,iBAAiB;YACjB,iCAAiC;YACjC,sBAAsB;YACtB,wCAAwC;YACxC,mCAAmC;YACnC,kCAAkC;YAClC,kBAAkB;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for `crypto`, streams and `events`.
3
+ */
4
+ export {};
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Runtime-coverage tests for `crypto`, streams and `events`.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: streams", (h) => {
8
+ it("hashes data with crypto", () => {
9
+ const source = `
10
+ import { createHash } from "crypto";
11
+ import crypto from "node:crypto";
12
+
13
+ console.log(createHash("sha256").update("abc").digest("hex"));
14
+ console.log(createHash("sha-256").update("abc").digest("hex"));
15
+ console.log(createHash("sha1").update("abc").digest("hex"));
16
+ console.log(createHash("sha-1").update("abc").digest("hex"));
17
+ console.log(createHash("sha256").update("x".repeat(100)).digest("base64"));
18
+ const h = createHash("sha256");
19
+ h.update("ab");
20
+ h.update("c");
21
+ console.log(h.digest("hex"));
22
+ const s = createHash("sha256");
23
+ s.setEncoding("base64");
24
+ s.write("ab");
25
+ s.write("c");
26
+ s.end("d");
27
+ console.log(s.read());
28
+ const u = createHash("md5");
29
+ console.log(u.update("abc").digest("hex").length);
30
+ console.log(crypto.createHash("sha256").update("abc").digest("latin1").length);
31
+ `;
32
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
33
+ expect(stdout.split("\n")).toEqual([
34
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
35
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
36
+ "a9993e364706816aba3e25717850c26c9cd0d89d",
37
+ "a9993e364706816aba3e25717850c26c9cd0d89d",
38
+ "Cey268i878cz9vLsRPeRq+7WqZ7fDMMVGWN4mK69Utg=",
39
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
40
+ "iNQmb9TmM40TuEX88olXnSCciXgjuSF9o+Fhk28DFYk=",
41
+ "0",
42
+ "32",
43
+ ]);
44
+ });
45
+ it("drives the stream surface", () => {
46
+ const source = `
47
+ import { Readable, Writable, Duplex, Transform, PassThrough } from "stream";
48
+
49
+ const r = new Readable({});
50
+ r.push("a");
51
+ r.push("b");
52
+ console.log("read1", r.read());
53
+ r.unshift("z");
54
+ console.log("read2", r.read());
55
+ r.setEncoding("utf8");
56
+ console.log("paused", r.isPaused());
57
+ r.pause();
58
+ console.log("paused2", r.isPaused());
59
+ r.resume();
60
+ console.log("paused3", r.isPaused());
61
+ r.push(null);
62
+ console.log("read3", r.read());
63
+
64
+ const w = new Writable({ write(chunk: string, enc: string, cb: () => void) { console.log("write-fn", chunk); cb(); } });
65
+ w.write("hello");
66
+ w.cork();
67
+ w.uncork();
68
+ w.end("bye", () => { console.log("end-cb"); });
69
+
70
+ const t = new Transform((chunk: string, enc: string, cb: (e: unknown, v: string) => void) => { cb(null, chunk.toUpperCase()); });
71
+ t.on("data", (d: string) => { console.log("transform-data", d); });
72
+ t.write("abc");
73
+
74
+ const pt = new PassThrough();
75
+ pt.on("data", (d: string) => { console.log("pt-data", d); });
76
+ pt.write("pass");
77
+ pt.end();
78
+
79
+ const d = new Duplex({ write(chunk: string, enc: string, cb: () => void) { cb(); } });
80
+ d.on("data", (v: string) => { console.log("duplex-data", v); });
81
+ d.write("duplex");
82
+
83
+ const r2 = Readable.from(["x", "y"]);
84
+ r2.on("data", (v: string) => { console.log("from-data", v); });
85
+
86
+ const src = new Readable({});
87
+ src.push("p1");
88
+ src.push("p2");
89
+ const dest = new Writable({ write(c: string, e: string, cb: () => void) { console.log("pipe-dest", c); cb(); } });
90
+ dest.on("finish", () => { console.log("dest-finish"); });
91
+ src.pipe(dest);
92
+ src.push(null);
93
+
94
+ const d2 = new Readable({});
95
+ d2.on("error", (e: any) => { console.log("stream-err", e.message); });
96
+ d2.on("close", () => { console.log("stream-close"); });
97
+ d2.destroy(new Error("boom"));
98
+ `;
99
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
100
+ expect(stdout.split("\n")).toEqual([
101
+ "read1 a",
102
+ "read2 z",
103
+ "paused false",
104
+ "paused2 true",
105
+ "paused3 false",
106
+ "read3 b",
107
+ "write-fn hello",
108
+ "write-fn bye",
109
+ "end-cb",
110
+ "transform-data ABC",
111
+ "pt-data pass",
112
+ "duplex-data duplex",
113
+ "from-data x",
114
+ "from-data y",
115
+ "pipe-dest p1",
116
+ "pipe-dest p2",
117
+ "dest-finish",
118
+ "stream-err boom",
119
+ "stream-close",
120
+ ]);
121
+ });
122
+ it("drives EventEmitter listeners and events.once", () => {
123
+ const source = `
124
+ import { EventEmitter } from "events";
125
+ import events from "node:events";
126
+ const e = new EventEmitter();
127
+ e.on("a", (x: number) => { console.log("a1", x); });
128
+ e.prependListener("a", (x: number) => { console.log("a0", x); });
129
+ e.once("b", (x: number) => { console.log("b once", x); });
130
+ e.on("b", (x: number) => { console.log("b always", x); });
131
+ e.emit("a", 1);
132
+ e.emit("b", 2);
133
+ e.emit("b", 3);
134
+ console.log(e.listenerCount("b"), e.eventNames().join(","), e.listeners("b").length);
135
+ e.removeAllListeners("a");
136
+ console.log(e.listenerCount("a"));
137
+ e.setMaxListeners(20);
138
+ console.log(e.getMaxListeners());
139
+ e.on("c", () => { console.log("c"); });
140
+ e.removeAllListeners();
141
+ console.log(e.eventNames().length);
142
+ const e2 = new EventEmitter();
143
+ events.once(e2, "done").then((v: any) => { console.log("once", v[0]); });
144
+ e2.emit("done", 42);
145
+ `;
146
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
147
+ expect(stdout.split("\n")).toEqual([
148
+ "a0 1",
149
+ "a1 1",
150
+ "b once 2",
151
+ "b always 2",
152
+ "b always 3",
153
+ "1 a,b 1",
154
+ "0",
155
+ "20",
156
+ "0",
157
+ "once undefined",
158
+ ]);
159
+ });
160
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
161
+ //# sourceMappingURL=runtime-coverage-streams.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-streams.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-streams.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,2BAA2B,EAC3B,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;OAsBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,kEAAkE;YAClE,kEAAkE;YAClE,0CAA0C;YAC1C,0CAA0C;YAC1C,8CAA8C;YAC9C,kEAAkE;YAClE,8CAA8C;YAC9C,GAAG;YACH,IAAI;SACL,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,SAAS;YACT,SAAS;YACT,cAAc;YACd,cAAc;YACd,eAAe;YACf,SAAS;YACT,gBAAgB;YAChB,cAAc;YACd,QAAQ;YACR,oBAAoB;YACpB,cAAc;YACd,oBAAoB;YACpB,aAAa;YACb,aAAa;YACb,cAAc;YACd,cAAc;YACd,aAAa;YACb,iBAAiB;YACjB,cAAc;SACf,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;OAsBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,MAAM;YACN,MAAM;YACN,UAAU;YACV,YAAY;YACZ,YAAY;YACZ,SAAS;YACT,GAAG;YACH,IAAI;YACJ,GAAG;YACH,gBAAgB;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for `url`, `os`, `process` and `child_process`.
3
+ */
4
+ export {};
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Runtime-coverage tests for `url`, `os`, `process` and `child_process`.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: system", (h) => {
8
+ it("converts between file paths and file URLs", () => {
9
+ const source = `
10
+ import { pathToFileURL, fileURLToPath } from "url";
11
+ import url from "url";
12
+
13
+ const u = pathToFileURL("/tmp/a b");
14
+ console.log(u.protocol, u.href.startsWith("file://"), u.href.includes("a b"));
15
+ console.log(fileURLToPath("file:///tmp/a%20b"));
16
+ console.log(fileURLToPath("file://localhost/tmp/c"));
17
+ console.log(fileURLToPath("/tmp/plain"));
18
+ console.log(url.pathToFileURL("/tmp/x").href.startsWith("file://"));
19
+ `;
20
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
21
+ expect(stdout.split("\n")).toEqual([
22
+ "file: true true",
23
+ "/tmp/a b",
24
+ "/tmp/c",
25
+ "/tmp/plain",
26
+ "true",
27
+ ]);
28
+ });
29
+ it("reads operating-system and process information", () => {
30
+ const source = `
31
+ import os from "os";
32
+ import * as os2 from "node:os";
33
+ import process from "process";
34
+ import * as proc from "node:process";
35
+
36
+ console.log(os.platform().length > 0, os.type().length > 0, os.arch().length > 0, os.endianness().length > 0);
37
+ console.log(os.homedir().length > 0, os.tmpdir().length > 0, os.hostname().length > 0, os.release().length > 0);
38
+ console.log(os.totalmem() > 0, os.freemem() > 0, os.cpus().length > 0, os2.cpus()[0].model.length > 0);
39
+ console.log(os2.platform().length > 0);
40
+ console.log(process.platform.length > 0, process.arch.length > 0, process.pid > 0, process.ppid >= 0, process.version.length > 0);
41
+ console.log(process.cwd().length > 0, process.uptime() >= 0, process.hrtime().length === 2);
42
+ console.log(process.getuid() >= 0, process.argv.length >= 1, Object.keys(process.env).length > 0);
43
+ process.stdout.write("stdout-write\\n");
44
+ process.stderr.write("stderr-write\\n");
45
+ console.log(proc.cwd().length > 0, proc.platform.length > 0, proc.getuid() >= 0);
46
+ `;
47
+ const result = h.runProgramFull(source, { extensions: true, timeout: TIMEOUT });
48
+ expect(result.status).toBe(0);
49
+ expect(result.stdout.trim().split("\n")).toEqual([
50
+ "true true true true",
51
+ "true true true true",
52
+ "true true true true",
53
+ "true",
54
+ "true true true true true",
55
+ "true true true",
56
+ "true true true",
57
+ "stdout-write",
58
+ "true true true",
59
+ ]);
60
+ expect(result.stderr.trim()).toBe("stderr-write");
61
+ });
62
+ it("spawns child processes synchronously", () => {
63
+ const source = `
64
+ import { spawnSync } from "node:child_process";
65
+
66
+ let isChild = false;
67
+ for (const arg of process.argv) {
68
+ if (arg === "xb-child-capture") isChild = true;
69
+ }
70
+ if (isChild) {
71
+ console.log("from-child");
72
+ console.error("child-err");
73
+ console.log("x".repeat(5000));
74
+ } else {
75
+ const r = spawnSync(process.argv[0], ["xb-child-capture"], { encoding: "utf8" });
76
+ console.log("status", r.status, "out", r.stdout.trim().length, "err", r.stderr.trim());
77
+ const missing = spawnSync("definitely-not-a-real-command-xyz", [], {});
78
+ console.log("missing", missing.status !== 0);
79
+ const cd = spawnSync(process.argv[0], ["xb-child-capture"], { cwd: process.cwd() });
80
+ console.log("cwd-status", cd.status);
81
+ }
82
+ `;
83
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
84
+ expect(stdout.split("\n")).toEqual([
85
+ "status 0 out 5011 err child-err",
86
+ "missing true",
87
+ "cwd-status 0",
88
+ ]);
89
+ });
90
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
91
+ //# sourceMappingURL=runtime-coverage-system.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-system.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-system.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,0BAA0B,EAC1B,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,MAAM,GAAG;;;;;;;;;;OAUd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,iBAAiB;YACjB,UAAU;YACV,QAAQ;YACR,YAAY;YACZ,MAAM;SACP,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;OAgBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAChF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YAC/C,qBAAqB;YACrB,qBAAqB;YACrB,qBAAqB;YACrB,MAAM;YACN,0BAA0B;YAC1B,gBAAgB;YAChB,gBAAgB;YAChB,cAAc;YACd,gBAAgB;SACjB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;OAmBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,iCAAiC;YACjC,cAAc;YACd,cAAc;SACf,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * End-to-end tests for the timer globals (`setTimeout` / `setInterval` and the
3
+ * matching `clear*` functions). They are implemented on the core event loop, so
4
+ * they work without any extension and keep the process alive until no timer is
5
+ * pending.
6
+ */
7
+ export {};