quickwin 3.0.0 → 3.0.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 (253) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/lib/abort.d.ts +21 -0
  4. package/lib/assert.d.ts +2 -0
  5. package/lib/bitmap.d.ts +7 -0
  6. package/lib/cache-utils.d.ts +6 -0
  7. package/lib/certs.d.ts +1 -0
  8. package/lib/dpi.d.ts +9 -0
  9. package/lib/dumpRects.d.ts +2 -0
  10. package/lib/exec-log.d.ts +23 -0
  11. package/lib/fetch.d.ts +4 -0
  12. package/lib/ffi/bind.d.ts +70 -0
  13. package/lib/ffi/ctype.d.ts +117 -0
  14. package/lib/ffi/index.d.ts +2 -0
  15. package/lib/ffi/struct.d.ts +174 -0
  16. package/lib/http-common.d.ts +143 -0
  17. package/lib/http-server.d.ts +59 -0
  18. package/lib/polyfill.d.ts +22 -0
  19. package/lib/react-qw/components/Button.d.ts +9 -0
  20. package/lib/react-qw/components/CheckBox.d.ts +11 -0
  21. package/lib/react-qw/components/ComboBox.d.ts +11 -0
  22. package/lib/react-qw/components/DateTimePicker.d.ts +15 -0
  23. package/lib/react-qw/components/Input.d.ts +15 -0
  24. package/lib/react-qw/components/Link.d.ts +12 -0
  25. package/lib/react-qw/components/ListBox.d.ts +13 -0
  26. package/lib/react-qw/components/ListView.d.ts +37 -0
  27. package/lib/react-qw/components/PathPicker.d.ts +23 -0
  28. package/lib/react-qw/components/ProgressBar.d.ts +9 -0
  29. package/lib/react-qw/components/RadioButton.d.ts +11 -0
  30. package/lib/react-qw/components/ScrollView.d.ts +9 -0
  31. package/lib/react-qw/components/Slider.d.ts +12 -0
  32. package/lib/react-qw/components/Tab.d.ts +14 -0
  33. package/lib/react-qw/components/Tooltip.d.ts +7 -0
  34. package/lib/react-qw/components/TreeView.d.ts +18 -0
  35. package/lib/react-qw/components/index.d.ts +16 -0
  36. package/lib/react-qw/index.d.ts +24 -0
  37. package/lib/react-qw/layout.d.ts +29 -0
  38. package/lib/react-qw/nmhdr.d.ts +1 -0
  39. package/lib/react-qw/props.d.ts +2 -0
  40. package/lib/react-qw/reconciler.d.ts +21 -0
  41. package/lib/stream.d.ts +20 -0
  42. package/lib/text-codec.d.ts +39 -0
  43. package/lib/text-measure.d.ts +14 -0
  44. package/lib/url.d.ts +54 -0
  45. package/lib/websocket.d.ts +73 -0
  46. package/lib/windows/{advapi32.ts → advapi32.d.ts} +6 -21
  47. package/lib/windows/comctl32.d.ts +14 -0
  48. package/lib/windows/comdlg32.d.ts +4 -0
  49. package/lib/windows/{gdi32.ts → gdi32.d.ts} +161 -98
  50. package/lib/windows/{kernel32.ts → kernel32.d.ts} +138 -115
  51. package/lib/windows/{msimg32.ts → msimg32.d.ts} +11 -14
  52. package/lib/windows/ntdll.d.ts +5 -0
  53. package/lib/windows/ole32.d.ts +3 -0
  54. package/lib/windows/{psapi.ts → psapi.d.ts} +9 -18
  55. package/lib/windows/{shell32.ts → shell32.d.ts} +25 -24
  56. package/lib/windows/structs.d.ts +3141 -0
  57. package/lib/windows/{user32.ts → user32.d.ts} +196 -193
  58. package/lib/windows/version.d.ts +27 -0
  59. package/lib/windows/{winspool.ts → winspool.d.ts} +18 -32
  60. package/package.json +15 -8
  61. package/qwin-nowasm-x86.exe +0 -0
  62. package/qwin-nowasm.exe +0 -0
  63. package/qwin-x86.exe +0 -0
  64. package/qwin.exe +0 -0
  65. package/examples/PdfCanvas.js +0 -38
  66. package/examples/PdfCanvas.tsx +0 -54
  67. package/examples/execd/main.js +0 -23379
  68. package/examples/execd/tray.js +0 -192
  69. package/examples/execd/worker.js +0 -122
  70. package/examples/pdf_preview2.js +0 -398
  71. package/examples/pdf_preview2.ts +0 -353
  72. package/examples/pdf_viewer.js +0 -22515
  73. package/examples/pdf_viewer.tsx +0 -228
  74. package/examples/test_gallery.js +0 -18692
  75. package/examples/test_gallery.tsx +0 -291
  76. package/examples/test_react_lazy.js +0 -18560
  77. package/examples/test_react_lazy.tsx +0 -65
  78. package/examples/test_react_listbox.js +0 -18562
  79. package/examples/test_react_listbox.tsx +0 -73
  80. package/examples/test_root_window.js +0 -18532
  81. package/examples/test_root_window.tsx +0 -41
  82. package/examples/test_tab.js +0 -18563
  83. package/examples/test_tab.tsx +0 -77
  84. package/examples/tray_demo.js +0 -86
  85. package/examples/tray_demo.tsx +0 -89
  86. package/lib/abort.ts +0 -69
  87. package/lib/assert.ts +0 -7
  88. package/lib/bitmap.ts +0 -39
  89. package/lib/cache-utils.ts +0 -40
  90. package/lib/certs.ts +0 -258
  91. package/lib/dpi.ts +0 -31
  92. package/lib/dumpRects.ts +0 -34
  93. package/lib/exec-log.ts +0 -30
  94. package/lib/fetch.ts +0 -589
  95. package/lib/ffi/bind.ts +0 -540
  96. package/lib/ffi/ctype.ts +0 -371
  97. package/lib/ffi/index.ts +0 -6
  98. package/lib/ffi/struct.ts +0 -780
  99. package/lib/http-common.ts +0 -441
  100. package/lib/http-server.ts +0 -604
  101. package/lib/polyfill.ts +0 -171
  102. package/lib/react-qw/components/index.ts +0 -17
  103. package/lib/react-qw/index.ts +0 -96
  104. package/lib/react-qw/layout.ts +0 -111
  105. package/lib/react-qw/nmhdr.ts +0 -7
  106. package/lib/react-qw/props.ts +0 -41
  107. package/lib/react-qw/reconciler.ts +0 -379
  108. package/lib/stream.ts +0 -22
  109. package/lib/text-codec.ts +0 -171
  110. package/lib/text-measure.ts +0 -44
  111. package/lib/url.ts +0 -201
  112. package/lib/websocket.ts +0 -600
  113. package/lib/windows/comctl32.ts +0 -20
  114. package/lib/windows/comdlg32.ts +0 -10
  115. package/lib/windows/ntdll.ts +0 -11
  116. package/lib/windows/ole32.ts +0 -9
  117. package/lib/windows/structs.ts +0 -807
  118. package/lib/windows/version.ts +0 -35
  119. package/test/add.wasm +0 -0
  120. package/test/bench_ffi_callraw.js +0 -235
  121. package/test/bench_ffi_callraw.ts +0 -235
  122. package/test/bench_ffi_overhead.js +0 -139
  123. package/test/bench_ffi_overhead.ts +0 -141
  124. package/test/bench_sendmessage.js +0 -104
  125. package/test/bench_sendmessage.ts +0 -100
  126. package/test/bench_sendmessage_nonnull.js +0 -187
  127. package/test/bench_sendmessage_nonnull.ts +0 -188
  128. package/test/complex.wasm +0 -0
  129. package/test/complex_imports.wasm +0 -0
  130. package/test/debug/http_server_e2e.js +0 -31
  131. package/test/debug/minwasm.js +0 -52
  132. package/test/debug/mupdf_debug.js +0 -86
  133. package/test/debug/wasm.js +0 -122
  134. package/test/debug/wasm_export_debug.js +0 -54
  135. package/test/debug/wasm_names.js +0 -36
  136. package/test/example.pdf +0 -0
  137. package/test/global_imports.wasm +0 -0
  138. package/test/import_func.wasm +0 -0
  139. package/test/imports.wasm +0 -0
  140. package/test/mupdf-cdn.js +0 -40
  141. package/test/mupdf-cdn.ts +0 -43
  142. package/test/run.js +0 -111
  143. package/test/run.ts +0 -116
  144. package/test/sjlj.wasm +0 -0
  145. package/test/test_basic.js +0 -7
  146. package/test/test_basic.ts +0 -9
  147. package/test/test_basic_fetch.js +0 -63
  148. package/test/test_basic_fetch.ts +0 -59
  149. package/test/test_brotli.js +0 -48
  150. package/test/test_brotli.ts +0 -52
  151. package/test/test_fetch_cache.js +0 -169
  152. package/test/test_fetch_cache.ts +0 -187
  153. package/test/test_ffi.js +0 -157
  154. package/test/test_ffi.ts +0 -170
  155. package/test/test_ffi_abi.js +0 -290
  156. package/test/test_ffi_abi.ts +0 -274
  157. package/test/test_ffi_array.js +0 -116
  158. package/test/test_ffi_array.ts +0 -141
  159. package/test/test_ffi_bind.js +0 -656
  160. package/test/test_ffi_bind.ts +0 -670
  161. package/test/test_ffi_struct.js +0 -779
  162. package/test/test_ffi_struct.ts +0 -828
  163. package/test/test_ffi_struct_layout.js +0 -495
  164. package/test/test_ffi_struct_layout.ts +0 -543
  165. package/test/test_ffi_user32.js +0 -103
  166. package/test/test_ffi_user32.ts +0 -113
  167. package/test/test_ffi_windows.js +0 -172
  168. package/test/test_ffi_windows.ts +0 -187
  169. package/test/test_files.js +0 -102
  170. package/test/test_files.ts +0 -121
  171. package/test/test_frame_encoding.js +0 -128
  172. package/test/test_frame_encoding.ts +0 -132
  173. package/test/test_gdi_draw.js +0 -681
  174. package/test/test_gdi_draw.ts +0 -725
  175. package/test/test_helper.js +0 -91
  176. package/test/test_helper.ts +0 -88
  177. package/test/test_http_import.js +0 -96
  178. package/test/test_http_import.ts +0 -93
  179. package/test/test_http_server.js +0 -214
  180. package/test/test_http_server.ts +0 -211
  181. package/test/test_import_dir.js +0 -4
  182. package/test/test_import_dir.ts +0 -5
  183. package/test/test_ipv6.js +0 -134
  184. package/test/test_ipv6.ts +0 -130
  185. package/test/test_jsx.js +0 -1314
  186. package/test/test_meta_url.js +0 -3
  187. package/test/test_meta_url.ts +0 -4
  188. package/test/test_mupdf_render.js +0 -51
  189. package/test/test_mupdf_render.ts +0 -55
  190. package/test/test_mupdf_twice.js +0 -62
  191. package/test/test_mupdf_twice.ts +0 -65
  192. package/test/test_mupdf_wasm.js +0 -39
  193. package/test/test_mupdf_wasm.ts +0 -32
  194. package/test/test_net_event.js +0 -57
  195. package/test/test_net_event.ts +0 -56
  196. package/test/test_net_fetch.js +0 -384
  197. package/test/test_net_fetch.ts +0 -373
  198. package/test/test_net_websocket.js +0 -180
  199. package/test/test_net_websocket.ts +0 -164
  200. package/test/test_polyfill.js +0 -144
  201. package/test/test_polyfill.ts +0 -159
  202. package/test/test_printer.js +0 -137
  203. package/test/test_printer.ts +0 -148
  204. package/test/test_proc.js +0 -141
  205. package/test/test_proc.ts +0 -163
  206. package/test/test_react_complex.js +0 -18678
  207. package/test/test_react_counter.js +0 -18555
  208. package/test/test_react_flex.js +0 -18871
  209. package/test/test_react_hidden.js +0 -18560
  210. package/test/test_react_listview_link.js +0 -18590
  211. package/test/test_react_notify.js +0 -18797
  212. package/test/test_react_render.js +0 -18550
  213. package/test/test_registry.js +0 -74
  214. package/test/test_registry.ts +0 -95
  215. package/test/test_sysinfo.js +0 -122
  216. package/test/test_sysinfo.ts +0 -141
  217. package/test/test_url.js +0 -173
  218. package/test/test_url.ts +0 -183
  219. package/test/test_wasm_basic.js +0 -85
  220. package/test/test_wasm_basic.ts +0 -73
  221. package/test/test_wasm_import_global.js +0 -41
  222. package/test/test_wasm_import_global.ts +0 -45
  223. package/test/test_wasm_sjlj.js +0 -145
  224. package/test/test_wasm_sjlj.ts +0 -125
  225. package/test/test_wasm_types.js +0 -97
  226. package/test/test_wasm_types.ts +0 -124
  227. package/test/test_wolfssl_read.js +0 -203
  228. package/test/test_wolfssl_read.ts +0 -184
  229. package/test/test_worker.js +0 -21
  230. package/test/test_worker.ts +0 -24
  231. package/test/test_worker_concurrent.js +0 -45
  232. package/test/test_worker_concurrent.ts +0 -56
  233. package/test/test_worker_data_url.js +0 -46
  234. package/test/test_worker_data_url.ts +0 -51
  235. package/test/test_worker_fetch.js +0 -26
  236. package/test/test_worker_fetch.ts +0 -27
  237. package/test/test_worker_net.js +0 -69
  238. package/test/test_worker_net.ts +0 -66
  239. package/test/test_worker_wasm_concurrent.js +0 -44
  240. package/test/test_worker_wasm_concurrent.ts +0 -45
  241. package/test/types.wasm +0 -0
  242. package/test/worker_fetch.js +0 -13
  243. package/test/worker_fetch.ts +0 -13
  244. package/test/worker_helper.js +0 -1
  245. package/test/worker_helper.ts +0 -1
  246. package/test/worker_http.js +0 -18
  247. package/test/worker_http.ts +0 -20
  248. package/test/worker_import_lib.js +0 -12
  249. package/test/worker_import_lib.ts +0 -13
  250. package/test/worker_module.js +0 -16
  251. package/test/worker_module.ts +0 -17
  252. package/test/worker_wasm_concurrent.js +0 -22
  253. package/test/worker_wasm_concurrent.ts +0 -22
@@ -1,91 +0,0 @@
1
- import * as std from 'std';
2
- const GREEN = '\x1b[32m';
3
- const RED = '\x1b[31m';
4
- const YELLOW = '\x1b[33m';
5
- const BOLD = '\x1b[1m';
6
- const RESET = '\x1b[0m';
7
- function formatDuration(ms) {
8
- if (ms >= 1000)
9
- return (ms / 1000).toFixed(2) + 's';
10
- return ms + 'ms';
11
- }
12
- export function readWasmFile(path) {
13
- const base = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
14
- const parts = (base + path).split('/');
15
- const out = [];
16
- for (const p of parts) {
17
- if (p === '..')
18
- out.pop();
19
- else if (p !== '.')
20
- out.push(p);
21
- }
22
- let filePath = out.join('/').slice(7);
23
- if (filePath.length >= 3 && filePath[1] === ':')
24
- filePath = filePath.slice(1);
25
- const fp = std.open(filePath, 'rb');
26
- if (!fp)
27
- return null;
28
- fp.seek(0, 2);
29
- const size = fp.tell();
30
- fp.seek(0, 0);
31
- const buffer = new ArrayBuffer(size);
32
- fp.read(buffer, 0, size);
33
- fp.close();
34
- return buffer;
35
- }
36
- export class Tester {
37
- ok = 0;
38
- fail = 0;
39
- skip = 0;
40
- startTime = Date.now();
41
- sectionStart = this.startTime;
42
- lastSection = '';
43
- section(name) {
44
- const now = Date.now();
45
- if (this.lastSection) {
46
- const elapsed = now - this.sectionStart;
47
- std.printf(' (%s)\n', formatDuration(elapsed));
48
- }
49
- this.sectionStart = now;
50
- this.lastSection = name;
51
- std.printf('\n%s=== %s ===%s\n', BOLD, name, RESET);
52
- }
53
- check(name, expected, actual) {
54
- if (typeof expected === 'number' && typeof actual === 'number') {
55
- if (Math.abs(expected - actual) < 0.0001) {
56
- this.ok++;
57
- std.printf(' %sPASS:%s %s = %s\n', GREEN, RESET, name, String(actual));
58
- }
59
- else {
60
- this.fail++;
61
- std.printf(' %sFAIL:%s %s = %s (expected %s)\n', RED, RESET, name, String(actual), String(expected));
62
- }
63
- }
64
- else if (expected === actual) {
65
- this.ok++;
66
- std.printf(' %sPASS:%s %s = %s\n', GREEN, RESET, name, String(actual));
67
- }
68
- else {
69
- this.fail++;
70
- std.printf(' %sFAIL:%s %s = %s (expected %s)\n', RED, RESET, name, String(actual), String(expected));
71
- }
72
- }
73
- checkTrue(name, actual) {
74
- this.check(name, true, actual);
75
- }
76
- skipCase(name) {
77
- this.skip++;
78
- std.printf(' %sSKIP:%s %s\n', YELLOW, RESET, name);
79
- }
80
- summary() {
81
- const now = Date.now();
82
- if (this.lastSection) {
83
- const elapsed = now - this.sectionStart;
84
- std.printf(' (%s)\n', formatDuration(elapsed));
85
- }
86
- const total = now - this.startTime;
87
- const color = this.fail > 0 ? RED : GREEN;
88
- const skipped = this.skip > 0 ? ` (${this.skip} skipped)` : '';
89
- std.printf('\n%s%d/%d passed%s (%s)%s\n', color, this.ok, this.ok + this.fail, skipped, formatDuration(total), RESET);
90
- }
91
- }
@@ -1,88 +0,0 @@
1
- import * as std from 'std'
2
-
3
- const GREEN = '\x1b[32m'
4
- const RED = '\x1b[31m'
5
- const YELLOW = '\x1b[33m'
6
- const BOLD = '\x1b[1m'
7
- const RESET = '\x1b[0m'
8
-
9
- function formatDuration(ms: number): string {
10
- if (ms >= 1000) return (ms / 1000).toFixed(2) + 's'
11
- return ms + 'ms'
12
- }
13
-
14
- export function readWasmFile(path: string): ArrayBuffer | null {
15
- const base = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1)
16
- const parts = (base + path).split('/')
17
- const out: string[] = []
18
- for (const p of parts) {
19
- if (p === '..') out.pop()
20
- else if (p !== '.') out.push(p)
21
- }
22
- let filePath = out.join('/').slice(7)
23
- if (filePath.length >= 3 && filePath[1] === ':') filePath = filePath.slice(1)
24
- const fp = std.open(filePath, 'rb')
25
- if (!fp) return null
26
- fp.seek(0, 2)
27
- const size = fp.tell()
28
- fp.seek(0, 0)
29
- const buffer = new ArrayBuffer(size)
30
- fp.read(buffer, 0, size)
31
- fp.close()
32
- return buffer
33
- }
34
-
35
- export class Tester {
36
- ok = 0
37
- fail = 0
38
- skip = 0
39
- private startTime = Date.now()
40
- private sectionStart = this.startTime
41
- private lastSection = ''
42
-
43
- section(name: string): void {
44
- const now = Date.now()
45
- if (this.lastSection) {
46
- const elapsed = now - this.sectionStart
47
- std.printf(' (%s)\n', formatDuration(elapsed))
48
- }
49
- this.sectionStart = now
50
- this.lastSection = name
51
- std.printf('\n%s=== %s ===%s\n', BOLD, name, RESET)
52
- }
53
-
54
- check(name: string, expected: unknown, actual: unknown): void {
55
- if (typeof expected === 'number' && typeof actual === 'number') {
56
- if (Math.abs(expected - actual) < 0.0001) {
57
- this.ok++; std.printf(' %sPASS:%s %s = %s\n', GREEN, RESET, name, String(actual))
58
- } else {
59
- this.fail++; std.printf(' %sFAIL:%s %s = %s (expected %s)\n', RED, RESET, name, String(actual), String(expected))
60
- }
61
- } else if (expected === actual) {
62
- this.ok++; std.printf(' %sPASS:%s %s = %s\n', GREEN, RESET, name, String(actual))
63
- } else {
64
- this.fail++; std.printf(' %sFAIL:%s %s = %s (expected %s)\n', RED, RESET, name, String(actual), String(expected))
65
- }
66
- }
67
-
68
- checkTrue(name: string, actual: boolean): void {
69
- this.check(name, true, actual)
70
- }
71
-
72
- skipCase(name: string): void {
73
- this.skip++
74
- std.printf(' %sSKIP:%s %s\n', YELLOW, RESET, name)
75
- }
76
-
77
- summary(): void {
78
- const now = Date.now()
79
- if (this.lastSection) {
80
- const elapsed = now - this.sectionStart
81
- std.printf(' (%s)\n', formatDuration(elapsed))
82
- }
83
- const total = now - this.startTime
84
- const color = this.fail > 0 ? RED : GREEN
85
- const skipped = this.skip > 0 ? ` (${this.skip} skipped)` : ''
86
- std.printf('\n%s%d/%d passed%s (%s)%s\n', color, this.ok, this.ok + this.fail, skipped, formatDuration(total), RESET)
87
- }
88
- }
@@ -1,96 +0,0 @@
1
- import * as std from 'std';
2
- import * as os from 'os';
3
- import { parseIni } from '../lib/cache-utils.js';
4
- function getCacheDir() {
5
- // import.meta.url: file:///C:/.../_build/test/file.js
6
- const url = import.meta.url;
7
- // Strip file:// (7 chars), giving /C:/.../
8
- let path = url.slice(7);
9
- // Remove leading / before drive letter
10
- if (path.length >= 3 && path[1] === ':')
11
- path = path.slice(1);
12
- // path now: C:/Users/Docker/quickwin/_build/test/file.js
13
- // Go up to _build/
14
- const idx = path.lastIndexOf('/');
15
- if (idx < 0)
16
- return '_cache';
17
- const buildDir = path.slice(0, idx); // .../_build/test
18
- const idx2 = buildDir.lastIndexOf('/');
19
- if (idx2 < 0)
20
- return '_cache';
21
- return buildDir.slice(0, idx2 + 1) + '_cache'; // .../_build/_cache
22
- }
23
- export const suite = {
24
- name: 'http-import',
25
- run: async (t) => {
26
- function assert(name, ok) {
27
- if (ok) {
28
- t.ok++;
29
- std.printf(' PASS: %s\n', name);
30
- }
31
- else {
32
- t.fail++;
33
- std.printf(' FAIL: %s\n', name);
34
- }
35
- }
36
- const url = 'https://esm.sh/left-pad@1.3.0';
37
- const cacheDir = getCacheDir();
38
- t.section('list cache before');
39
- const [before, err] = os.readdir(cacheDir);
40
- if (err !== 0) {
41
- std.printf(' cache dir: %s (error %d, will be created on first request)\n', cacheDir, err);
42
- }
43
- t.section('import module');
44
- let mod;
45
- try {
46
- mod = await import(url);
47
- }
48
- catch (e) {
49
- assert('import succeeds', false);
50
- std.printf(' ERROR: %s\n', String(e));
51
- return;
52
- }
53
- assert('import succeeds', true);
54
- assert('default is function', typeof mod.default === 'function');
55
- assert('left-pad works', mod.default('hello', 8) === ' hello');
56
- t.section('check cache');
57
- const [after, err2] = os.readdir(cacheDir);
58
- assert('cache dir readable', err2 === 0);
59
- if (err2 !== 0)
60
- return;
61
- assert('cache has body files', after.some(function (f) { return f.endsWith('.body'); }));
62
- assert('cache has meta files', after.some(function (f) { return f.endsWith('.meta'); }));
63
- t.section('repeat https import (fresh url, forces TLS)');
64
- // http_get_sync() short-circuits on a warm disk cache, so a second
65
- // import of the same URL would never build a TLS connection. Use a
66
- // distinct query string to force a real handshake into the
67
- // process-wide CA store, then import once more to confirm repeated
68
- // loadTrustedCerts() calls keep verifying.
69
- const url2 = 'https://esm.sh/left-pad@1.3.0?twice=1';
70
- let mod2;
71
- try {
72
- mod2 = await import(url2);
73
- assert('repeat import succeeds', true);
74
- assert('repeat default is function', typeof mod2.default === 'function');
75
- assert('repeat left-pad works', mod2.default('hello', 8) === ' hello');
76
- }
77
- catch (e) {
78
- assert('repeat import succeeds', false);
79
- std.printf(' ERROR: %s\n', String(e));
80
- }
81
- for (const f of after) {
82
- if (f.endsWith('.meta') && (err !== 0 || before.indexOf(f) < 0)) {
83
- std.printf(' meta: %s\n', f);
84
- const fp = std.open(cacheDir + '/' + f, 'r');
85
- if (fp) {
86
- const metaStr = fp.readAsString();
87
- fp.close();
88
- if (metaStr) {
89
- const ini = parseIni(metaStr);
90
- std.printf(' storedAt: %s, maxAge: %s\n', ini.meta.storedAt || '?', ini.meta.maxAge || '?');
91
- }
92
- }
93
- }
94
- }
95
- }
96
- };
@@ -1,93 +0,0 @@
1
- import * as std from 'std'
2
- import * as os from 'os'
3
- import { Tester } from './test_helper.js'
4
- import { parseIni } from '../lib/cache-utils.js'
5
-
6
- function getCacheDir(): string {
7
- // import.meta.url: file:///C:/.../_build/test/file.js
8
- const url = import.meta.url
9
- // Strip file:// (7 chars), giving /C:/.../
10
- let path = url.slice(7)
11
- // Remove leading / before drive letter
12
- if (path.length >= 3 && path[1] === ':') path = path.slice(1)
13
- // path now: C:/Users/Docker/quickwin/_build/test/file.js
14
- // Go up to _build/
15
- const idx = path.lastIndexOf('/')
16
- if (idx < 0) return '_cache'
17
- const buildDir = path.slice(0, idx) // .../_build/test
18
- const idx2 = buildDir.lastIndexOf('/')
19
- if (idx2 < 0) return '_cache'
20
- return buildDir.slice(0, idx2 + 1) + '_cache' // .../_build/_cache
21
- }
22
-
23
- export const suite = {
24
- name: 'http-import',
25
- run: async (t: Tester) => {
26
- function assert(name: string, ok: boolean): void {
27
- if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
28
- else { t.fail++; std.printf(' FAIL: %s\n', name) }
29
- }
30
-
31
- const url = 'https://esm.sh/left-pad@1.3.0'
32
- const cacheDir = getCacheDir()
33
-
34
- t.section('list cache before')
35
- const [before, err] = os.readdir(cacheDir)
36
- if (err !== 0) {
37
- std.printf(' cache dir: %s (error %d, will be created on first request)\n', cacheDir, err)
38
- }
39
-
40
- t.section('import module')
41
- let mod: any
42
- try {
43
- mod = await import(url)
44
- } catch (e) {
45
- assert('import succeeds', false)
46
- std.printf(' ERROR: %s\n', String(e))
47
- return
48
- }
49
- assert('import succeeds', true)
50
- assert('default is function', typeof mod.default === 'function')
51
- assert('left-pad works', mod.default('hello', 8) === ' hello')
52
-
53
- t.section('check cache')
54
- const [after, err2] = os.readdir(cacheDir)
55
- assert('cache dir readable', err2 === 0)
56
- if (err2 !== 0) return
57
- assert('cache has body files', after.some(function(f: string) { return f.endsWith('.body') }))
58
- assert('cache has meta files', after.some(function(f: string) { return f.endsWith('.meta') }))
59
-
60
- t.section('repeat https import (fresh url, forces TLS)')
61
- // http_get_sync() short-circuits on a warm disk cache, so a second
62
- // import of the same URL would never build a TLS connection. Use a
63
- // distinct query string to force a real handshake into the
64
- // process-wide CA store, then import once more to confirm repeated
65
- // loadTrustedCerts() calls keep verifying.
66
- const url2 = 'https://esm.sh/left-pad@1.3.0?twice=1'
67
- let mod2: any
68
- try {
69
- mod2 = await import(url2)
70
- assert('repeat import succeeds', true)
71
- assert('repeat default is function', typeof mod2.default === 'function')
72
- assert('repeat left-pad works', mod2.default('hello', 8) === ' hello')
73
- } catch (e) {
74
- assert('repeat import succeeds', false)
75
- std.printf(' ERROR: %s\n', String(e))
76
- }
77
-
78
- for (const f of after) {
79
- if (f.endsWith('.meta') && (err !== 0 || before.indexOf(f) < 0)) {
80
- std.printf(' meta: %s\n', f)
81
- const fp = std.open(cacheDir + '/' + f, 'r')
82
- if (fp) {
83
- const metaStr = fp.readAsString()
84
- fp.close()
85
- if (metaStr) {
86
- const ini = parseIni(metaStr)
87
- std.printf(' storedAt: %s, maxAge: %s\n', ini.meta.storedAt || '?', ini.meta.maxAge || '?')
88
- }
89
- }
90
- }
91
- }
92
- }
93
- }
@@ -1,214 +0,0 @@
1
- import './test_helper.js';
2
- import * as std from 'std';
3
- import * as os from 'os';
4
- import * as sock from 'sock';
5
- import { createServer } from '../lib/http-server.js';
6
- import '../lib/fetch.js';
7
- // ── Minimal raw HTTP client for testing ──
8
- function httpSend(host, port, raw, nResponses = 1) {
9
- return new Promise((resolve, reject) => {
10
- const s = sock.socket();
11
- if (s < 0) {
12
- reject(new Error('socket create failed'));
13
- return;
14
- }
15
- let buf = '';
16
- let done = false;
17
- const timer = os.setTimeout(() => {
18
- if (!done) {
19
- done = true;
20
- sock.closesocket(s);
21
- reject(new Error('timeout: ' + buf));
22
- }
23
- }, 10000);
24
- sock.set_on_event(s, (event) => {
25
- if (done)
26
- return;
27
- if (event.lNetworkEvents & 16 /* FdEvent.FD_CONNECT */) {
28
- const err = event.iErrorCode[0];
29
- if (err !== 0) {
30
- done = true;
31
- os.clearTimeout(timer);
32
- sock.closesocket(s);
33
- reject(new Error('connect error ' + err));
34
- return;
35
- }
36
- const bytes = new TextEncoder().encode(raw);
37
- sock.send(s, bytes.buffer);
38
- }
39
- if (event.lNetworkEvents & 1 /* FdEvent.FD_READ */) {
40
- while (true) {
41
- const d = sock.recv(s, 8192);
42
- if (typeof d === 'number')
43
- break;
44
- if (!d || d.byteLength === 0)
45
- break;
46
- buf += new TextDecoder().decode(new Uint8Array(d));
47
- }
48
- const count = (buf.match(/HTTP\/1\.1 /g) || []).length;
49
- if (count >= nResponses) {
50
- done = true;
51
- os.clearTimeout(timer);
52
- sock.closesocket(s);
53
- resolve(buf);
54
- }
55
- }
56
- if (event.lNetworkEvents & 32 /* FdEvent.FD_CLOSE */) {
57
- if (!done) {
58
- done = true;
59
- os.clearTimeout(timer);
60
- sock.closesocket(s);
61
- resolve(buf);
62
- }
63
- }
64
- });
65
- sock.connect(s, host, port);
66
- });
67
- }
68
- // ── Test suite ──
69
- export const suite = {
70
- name: 'http-server',
71
- run: async (t) => {
72
- const requests = [];
73
- const server = createServer(async (req) => {
74
- const url = new URL(req.url);
75
- const path = url.pathname;
76
- requests.push(req.method + ' ' + path);
77
- if (path === '/') {
78
- return new Response('hello ' + (url.searchParams.get('name') || ''), { headers: { 'Content-Type': 'text/plain' } });
79
- }
80
- else if (path === '/echo') {
81
- return new Response(req.method + ':' + await req.text(), { headers: { 'Content-Type': 'text/plain' } });
82
- }
83
- else if (path === '/json') {
84
- return new Response(JSON.stringify({ method: req.method, q: Object.fromEntries(url.searchParams) }), { headers: { 'Content-Type': 'application/json' } });
85
- }
86
- else if (path === '/stream') {
87
- // length unknown: server must send chunked frames
88
- return new Response(new ReadableStream({
89
- start(control) {
90
- control.enqueue(new TextEncoder().encode('chunkA/'));
91
- control.enqueue(new TextEncoder().encode('chunkB'));
92
- control.close();
93
- }
94
- }), { headers: { 'Content-Type': 'text/plain' } });
95
- }
96
- else if (path === '/file') {
97
- // length known: server streams raw bytes with Content-Length
98
- return new Response(new ReadableStream({
99
- start(control) {
100
- control.enqueue(new TextEncoder().encode('chunkA/'));
101
- control.enqueue(new TextEncoder().encode('chunkB'));
102
- control.close();
103
- }
104
- }), { headers: { 'Content-Type': 'text/plain', 'Content-Length': '13' } });
105
- }
106
- else if (path === '/stream-trailer') {
107
- // chunked stream with trailing headers (Node addTrailers
108
- // semantics: `Trailer` declaration + frames, then the footer)
109
- return new Response(new ReadableStream({
110
- start(control) {
111
- control.enqueue(new TextEncoder().encode('chunkA/'));
112
- control.enqueue(new TextEncoder().encode('chunkB'));
113
- control.close();
114
- }
115
- }), {
116
- headers: { 'Content-Type': 'text/plain', 'Trailer': 'X-Exit-Code' },
117
- trailers: Promise.resolve({ 'X-Exit-Code': '3' })
118
- });
119
- }
120
- else {
121
- return new Response('not found', { status: 404 });
122
- }
123
- });
124
- const rc = server.listen(0, '127.0.0.1');
125
- t.checkTrue('listen ok', rc === 0);
126
- const addr = server.address();
127
- if (!addr) {
128
- t.check('address', 'non-null', 'null');
129
- return;
130
- }
131
- t.checkTrue('bound port > 0', addr.port > 0);
132
- const port = addr.port;
133
- // ── GET with query ──
134
- t.section('GET with query');
135
- let r = await httpSend('127.0.0.1', port, 'GET /?name=world HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
136
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0);
137
- t.checkTrue('body = hello world', r.endsWith('hello world'));
138
- t.checkTrue('content-type text', r.toLowerCase().indexOf('content-type: text/plain') >= 0);
139
- t.checkTrue('static body gets content-length', r.toLowerCase().indexOf('content-length: 11') >= 0);
140
- // ── streaming chunked response (length unknown) ──
141
- t.section('streaming chunked response');
142
- r = await httpSend('127.0.0.1', port, 'GET /stream HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
143
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0);
144
- t.checkTrue('transfer-encoding chunked', r.toLowerCase().indexOf('transfer-encoding: chunked') >= 0);
145
- t.checkTrue('no content-length', r.toLowerCase().indexOf('content-length:') < 0);
146
- t.checkTrue('chunk frames + terminator', r.indexOf('7\r\nchunkA/\r\n6\r\nchunkB\r\n0\r\n\r\n') >= 0);
147
- // ── streaming raw response with known length ──
148
- t.section('streaming known-length response');
149
- r = await httpSend('127.0.0.1', port, 'GET /file HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
150
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0);
151
- t.checkTrue('content-length 13', r.toLowerCase().indexOf('content-length: 13') >= 0);
152
- t.checkTrue('no chunked encoding', r.toLowerCase().indexOf('transfer-encoding: chunked') < 0);
153
- t.checkTrue('streamed raw body', r.includes('chunkA/chunkB'));
154
- t.checkTrue('no chunk frame headers', r.indexOf('7\r\nchunkA/') < 0);
155
- // ── HEAD of a streamed body: headers only, empty body ──
156
- t.section('HEAD streaming response');
157
- r = await httpSend('127.0.0.1', port, 'HEAD /stream HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
158
- t.checkTrue('HEAD 200', r.indexOf('HTTP/1.1 200') === 0);
159
- t.checkTrue('HEAD content-length 13', r.toLowerCase().indexOf('content-length: 13') >= 0);
160
- const headBodyIdx = r.indexOf('\r\n\r\n');
161
- t.checkTrue('HEAD empty body', r.slice(headBodyIdx + 4).length === 0);
162
- // ── streaming chunked response with trailing headers ──
163
- t.section('streaming trailer response');
164
- r = await httpSend('127.0.0.1', port, 'GET /stream-trailer HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
165
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0);
166
- t.checkTrue('trailer declared in head', r.toLowerCase().indexOf('trailer: x-exit-code') >= 0);
167
- t.checkTrue('terminator carries trailer', r.indexOf('0\r\nX-Exit-Code: 3\r\n\r\n') >= 0);
168
- t.checkTrue('trailer footer after body', r.indexOf('7\r\nchunkA/\r\n6\r\nchunkB\r\n0\r\nX-Exit-Code: 3\r\n\r\n') >= 0);
169
- // ── fetch client consumes chunked response with trailer footer ──
170
- t.section('fetch consumes trailer response');
171
- {
172
- const rr = await fetch(`http://127.0.0.1:${port}/stream-trailer`);
173
- t.checkTrue('status 200', rr.status === 200);
174
- t.checkTrue('body decoded without trailer', await rr.text() === 'chunkA/chunkB');
175
- }
176
- // ── POST with body ──
177
- t.section('POST with body');
178
- r = await httpSend('127.0.0.1', port, 'POST /echo HTTP/1.1\r\nHost: x\r\nContent-Length: 7\r\nConnection: close\r\n\r\npayload');
179
- t.checkTrue('echo body', r.endsWith('POST:payload'));
180
- // ── POST with chunked request body ──
181
- t.section('chunked request body');
182
- const chunkedRaw = 'POST /echo HTTP/1.1\r\nHost: x\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n' +
183
- '3\r\nabc\r\n4\r\ndefg\r\n0\r\n\r\n';
184
- r = await httpSend('127.0.0.1', port, chunkedRaw);
185
- t.checkTrue('chunked decoded', r.endsWith('POST:abcdefg'));
186
- // ── 404 ──
187
- t.section('404');
188
- r = await httpSend('127.0.0.1', port, 'GET /missing HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
189
- t.checkTrue('404 status', r.indexOf('HTTP/1.1 404') === 0);
190
- t.checkTrue('404 body', r.endsWith('not found'));
191
- // ── HEAD (headers present, empty body) ──
192
- t.section('HEAD');
193
- r = await httpSend('127.0.0.1', port, 'HEAD / HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n');
194
- t.checkTrue('HEAD 200', r.indexOf('HTTP/1.1 200') === 0);
195
- t.checkTrue('HEAD content-length present', r.toLowerCase().indexOf('content-length: 6') >= 0);
196
- const bodyIdx = r.indexOf('\r\n\r\n');
197
- t.checkTrue('HEAD empty body', r.slice(bodyIdx + 4).length === 0);
198
- // ── keep-alive: two requests on one connection ──
199
- t.section('keep-alive pipelining');
200
- const pipelined = 'GET /?name=a HTTP/1.1\r\nHost: x\r\n\r\n' +
201
- 'GET /?name=b HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n';
202
- r = await httpSend('127.0.0.1', port, pipelined, 2);
203
- t.checkTrue('two responses received', r.indexOf('hello a') >= 0 && r.indexOf('hello b') >= 0);
204
- t.checkTrue('connection close on last', r.toLowerCase().indexOf('connection: close') >= 0);
205
- // ── server received expected requests ──
206
- t.section('request log');
207
- t.check('total requests', 12, requests.length);
208
- t.checkTrue('saw GET /', requests.indexOf('GET /') >= 0);
209
- t.checkTrue('saw POST /echo', requests.indexOf('POST /echo') >= 0);
210
- server.close();
211
- t.check('closed ok', true, true);
212
- std.printf(' (http-server suite done, %d requests)\n', requests.length);
213
- },
214
- };