quickwin 3.0.1 → 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 (163) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/package.json +1 -3
  4. package/qwin-nowasm-x86.exe +0 -0
  5. package/qwin-nowasm.exe +0 -0
  6. package/qwin-x86.exe +0 -0
  7. package/qwin.exe +0 -0
  8. package/examples/PdfCanvas.js +0 -38
  9. package/examples/PdfCanvas.tsx +0 -54
  10. package/examples/execd/main.js +0 -23379
  11. package/examples/execd/tray.js +0 -192
  12. package/examples/execd/worker.js +0 -122
  13. package/examples/pdf_preview2.js +0 -398
  14. package/examples/pdf_preview2.ts +0 -353
  15. package/examples/pdf_viewer.js +0 -22515
  16. package/examples/pdf_viewer.tsx +0 -228
  17. package/examples/test_gallery.js +0 -18692
  18. package/examples/test_gallery.tsx +0 -291
  19. package/examples/test_react_lazy.js +0 -18560
  20. package/examples/test_react_lazy.tsx +0 -65
  21. package/examples/test_react_listbox.js +0 -18562
  22. package/examples/test_react_listbox.tsx +0 -73
  23. package/examples/test_root_window.js +0 -18532
  24. package/examples/test_root_window.tsx +0 -41
  25. package/examples/test_tab.js +0 -18563
  26. package/examples/test_tab.tsx +0 -77
  27. package/examples/tray_demo.js +0 -86
  28. package/examples/tray_demo.tsx +0 -89
  29. package/test/add.wasm +0 -0
  30. package/test/bench_ffi_callraw.js +0 -235
  31. package/test/bench_ffi_callraw.ts +0 -235
  32. package/test/bench_ffi_overhead.js +0 -139
  33. package/test/bench_ffi_overhead.ts +0 -141
  34. package/test/bench_sendmessage.js +0 -104
  35. package/test/bench_sendmessage.ts +0 -100
  36. package/test/bench_sendmessage_nonnull.js +0 -187
  37. package/test/bench_sendmessage_nonnull.ts +0 -188
  38. package/test/complex.wasm +0 -0
  39. package/test/complex_imports.wasm +0 -0
  40. package/test/debug/http_server_e2e.js +0 -31
  41. package/test/debug/minwasm.js +0 -52
  42. package/test/debug/mupdf_debug.js +0 -86
  43. package/test/debug/wasm.js +0 -122
  44. package/test/debug/wasm_export_debug.js +0 -54
  45. package/test/debug/wasm_names.js +0 -36
  46. package/test/example.pdf +0 -0
  47. package/test/global_imports.wasm +0 -0
  48. package/test/import_func.wasm +0 -0
  49. package/test/imports.wasm +0 -0
  50. package/test/mupdf-cdn.js +0 -40
  51. package/test/mupdf-cdn.ts +0 -43
  52. package/test/run.js +0 -111
  53. package/test/run.ts +0 -116
  54. package/test/sjlj.wasm +0 -0
  55. package/test/test_basic.js +0 -7
  56. package/test/test_basic.ts +0 -9
  57. package/test/test_basic_fetch.js +0 -63
  58. package/test/test_basic_fetch.ts +0 -59
  59. package/test/test_brotli.js +0 -48
  60. package/test/test_brotli.ts +0 -52
  61. package/test/test_fetch_cache.js +0 -169
  62. package/test/test_fetch_cache.ts +0 -187
  63. package/test/test_ffi.js +0 -157
  64. package/test/test_ffi.ts +0 -170
  65. package/test/test_ffi_abi.js +0 -290
  66. package/test/test_ffi_abi.ts +0 -274
  67. package/test/test_ffi_array.js +0 -116
  68. package/test/test_ffi_array.ts +0 -141
  69. package/test/test_ffi_bind.js +0 -656
  70. package/test/test_ffi_bind.ts +0 -670
  71. package/test/test_ffi_struct.js +0 -779
  72. package/test/test_ffi_struct.ts +0 -828
  73. package/test/test_ffi_struct_layout.js +0 -495
  74. package/test/test_ffi_struct_layout.ts +0 -543
  75. package/test/test_ffi_user32.js +0 -103
  76. package/test/test_ffi_user32.ts +0 -113
  77. package/test/test_ffi_windows.js +0 -172
  78. package/test/test_ffi_windows.ts +0 -187
  79. package/test/test_files.js +0 -102
  80. package/test/test_files.ts +0 -121
  81. package/test/test_frame_encoding.js +0 -128
  82. package/test/test_frame_encoding.ts +0 -132
  83. package/test/test_gdi_draw.js +0 -681
  84. package/test/test_gdi_draw.ts +0 -725
  85. package/test/test_helper.js +0 -91
  86. package/test/test_helper.ts +0 -88
  87. package/test/test_http_import.js +0 -96
  88. package/test/test_http_import.ts +0 -93
  89. package/test/test_http_server.js +0 -214
  90. package/test/test_http_server.ts +0 -211
  91. package/test/test_import_dir.js +0 -4
  92. package/test/test_import_dir.ts +0 -5
  93. package/test/test_ipv6.js +0 -134
  94. package/test/test_ipv6.ts +0 -130
  95. package/test/test_jsx.js +0 -1314
  96. package/test/test_meta_url.js +0 -3
  97. package/test/test_meta_url.ts +0 -4
  98. package/test/test_mupdf_render.js +0 -51
  99. package/test/test_mupdf_render.ts +0 -55
  100. package/test/test_mupdf_twice.js +0 -62
  101. package/test/test_mupdf_twice.ts +0 -65
  102. package/test/test_mupdf_wasm.js +0 -39
  103. package/test/test_mupdf_wasm.ts +0 -32
  104. package/test/test_net_event.js +0 -57
  105. package/test/test_net_event.ts +0 -56
  106. package/test/test_net_fetch.js +0 -384
  107. package/test/test_net_fetch.ts +0 -373
  108. package/test/test_net_websocket.js +0 -180
  109. package/test/test_net_websocket.ts +0 -164
  110. package/test/test_polyfill.js +0 -144
  111. package/test/test_polyfill.ts +0 -159
  112. package/test/test_printer.js +0 -137
  113. package/test/test_printer.ts +0 -148
  114. package/test/test_proc.js +0 -141
  115. package/test/test_proc.ts +0 -163
  116. package/test/test_react_complex.js +0 -18678
  117. package/test/test_react_counter.js +0 -18555
  118. package/test/test_react_flex.js +0 -18871
  119. package/test/test_react_hidden.js +0 -18560
  120. package/test/test_react_listview_link.js +0 -18590
  121. package/test/test_react_notify.js +0 -18797
  122. package/test/test_react_render.js +0 -18550
  123. package/test/test_registry.js +0 -74
  124. package/test/test_registry.ts +0 -95
  125. package/test/test_sysinfo.js +0 -122
  126. package/test/test_sysinfo.ts +0 -141
  127. package/test/test_url.js +0 -173
  128. package/test/test_url.ts +0 -183
  129. package/test/test_wasm_basic.js +0 -85
  130. package/test/test_wasm_basic.ts +0 -73
  131. package/test/test_wasm_import_global.js +0 -41
  132. package/test/test_wasm_import_global.ts +0 -45
  133. package/test/test_wasm_sjlj.js +0 -145
  134. package/test/test_wasm_sjlj.ts +0 -125
  135. package/test/test_wasm_types.js +0 -97
  136. package/test/test_wasm_types.ts +0 -124
  137. package/test/test_wolfssl_read.js +0 -203
  138. package/test/test_wolfssl_read.ts +0 -184
  139. package/test/test_worker.js +0 -21
  140. package/test/test_worker.ts +0 -24
  141. package/test/test_worker_concurrent.js +0 -45
  142. package/test/test_worker_concurrent.ts +0 -56
  143. package/test/test_worker_data_url.js +0 -46
  144. package/test/test_worker_data_url.ts +0 -51
  145. package/test/test_worker_fetch.js +0 -26
  146. package/test/test_worker_fetch.ts +0 -27
  147. package/test/test_worker_net.js +0 -69
  148. package/test/test_worker_net.ts +0 -66
  149. package/test/test_worker_wasm_concurrent.js +0 -44
  150. package/test/test_worker_wasm_concurrent.ts +0 -45
  151. package/test/types.wasm +0 -0
  152. package/test/worker_fetch.js +0 -13
  153. package/test/worker_fetch.ts +0 -13
  154. package/test/worker_helper.js +0 -1
  155. package/test/worker_helper.ts +0 -1
  156. package/test/worker_http.js +0 -18
  157. package/test/worker_http.ts +0 -20
  158. package/test/worker_import_lib.js +0 -12
  159. package/test/worker_import_lib.ts +0 -13
  160. package/test/worker_module.js +0 -16
  161. package/test/worker_module.ts +0 -17
  162. package/test/worker_wasm_concurrent.js +0 -22
  163. package/test/worker_wasm_concurrent.ts +0 -22
@@ -1,211 +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 { Tester } from './test_helper.js'
6
- import { createServer } from '../lib/http-server.js'
7
- import '../lib/fetch.js'
8
- import { FdEvent } from '../constants'
9
-
10
- // ── Minimal raw HTTP client for testing ──
11
-
12
- function httpSend(host: string, port: number, raw: string, nResponses = 1): Promise<string> {
13
- return new Promise((resolve, reject) => {
14
- const s = sock.socket()
15
- if (s < 0) { reject(new Error('socket create failed')); return }
16
- let buf = ''
17
- let done = false
18
- const timer = os.setTimeout(() => {
19
- if (!done) { done = true; sock.closesocket(s); reject(new Error('timeout: ' + buf)) }
20
- }, 10000)
21
- sock.set_on_event(s, (event) => {
22
- if (done) return
23
- if (event.lNetworkEvents & FdEvent.FD_CONNECT) {
24
- const err = event.iErrorCode[0]
25
- if (err !== 0) {
26
- done = true
27
- os.clearTimeout(timer)
28
- sock.closesocket(s)
29
- reject(new Error('connect error ' + err))
30
- return
31
- }
32
- const bytes = new TextEncoder().encode(raw)
33
- sock.send(s, bytes.buffer)
34
- }
35
- if (event.lNetworkEvents & FdEvent.FD_READ) {
36
- while (true) {
37
- const d = sock.recv(s, 8192) as unknown as ArrayBuffer | number
38
- if (typeof d === 'number') break
39
- if (!d || d.byteLength === 0) break
40
- buf += new TextDecoder().decode(new Uint8Array(d))
41
- }
42
- const count = (buf.match(/HTTP\/1\.1 /g) || []).length
43
- if (count >= nResponses) {
44
- done = true
45
- os.clearTimeout(timer)
46
- sock.closesocket(s)
47
- resolve(buf)
48
- }
49
- }
50
- if (event.lNetworkEvents & FdEvent.FD_CLOSE) {
51
- if (!done) { done = true; os.clearTimeout(timer); sock.closesocket(s); resolve(buf) }
52
- }
53
- })
54
- sock.connect(s, host, port)
55
- })
56
- }
57
-
58
- // ── Test suite ──
59
-
60
- export const suite = {
61
- name: 'http-server',
62
- run: async (t: Tester) => {
63
- const requests: string[] = []
64
- const server = createServer(async (req) => {
65
- const url = new URL(req.url)
66
- const path = url.pathname
67
- requests.push(req.method + ' ' + path)
68
- if (path === '/') {
69
- return new Response('hello ' + (url.searchParams.get('name') || ''), { headers: { 'Content-Type': 'text/plain' } })
70
- } else if (path === '/echo') {
71
- return new Response(req.method + ':' + await req.text(), { headers: { 'Content-Type': 'text/plain' } })
72
- } else if (path === '/json') {
73
- return new Response(JSON.stringify({ method: req.method, q: Object.fromEntries(url.searchParams) }), { headers: { 'Content-Type': 'application/json' } })
74
- } else if (path === '/stream') {
75
- // length unknown: server must send chunked frames
76
- return new Response(new ReadableStream({
77
- start(control) {
78
- control.enqueue(new TextEncoder().encode('chunkA/'))
79
- control.enqueue(new TextEncoder().encode('chunkB'))
80
- control.close()
81
- }
82
- }), { headers: { 'Content-Type': 'text/plain' } })
83
- } else if (path === '/file') {
84
- // length known: server streams raw bytes with Content-Length
85
- return new Response(new ReadableStream({
86
- start(control) {
87
- control.enqueue(new TextEncoder().encode('chunkA/'))
88
- control.enqueue(new TextEncoder().encode('chunkB'))
89
- control.close()
90
- }
91
- }), { headers: { 'Content-Type': 'text/plain', 'Content-Length': '13' } })
92
- } else if (path === '/stream-trailer') {
93
- // chunked stream with trailing headers (Node addTrailers
94
- // semantics: `Trailer` declaration + frames, then the footer)
95
- return new Response(new ReadableStream({
96
- start(control) {
97
- control.enqueue(new TextEncoder().encode('chunkA/'))
98
- control.enqueue(new TextEncoder().encode('chunkB'))
99
- control.close()
100
- }
101
- }), {
102
- headers: { 'Content-Type': 'text/plain', 'Trailer': 'X-Exit-Code' },
103
- trailers: Promise.resolve({ 'X-Exit-Code': '3' })
104
- })
105
- } else {
106
- return new Response('not found', { status: 404 })
107
- }
108
- })
109
-
110
- const rc = server.listen(0, '127.0.0.1')
111
- t.checkTrue('listen ok', rc === 0)
112
- const addr = server.address()
113
- if (!addr) { t.check('address', 'non-null', 'null'); return }
114
- t.checkTrue('bound port > 0', addr.port > 0)
115
- const port = addr.port
116
-
117
- // ── GET with query ──
118
- t.section('GET with query')
119
- 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')
120
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0)
121
- t.checkTrue('body = hello world', r.endsWith('hello world'))
122
- t.checkTrue('content-type text', r.toLowerCase().indexOf('content-type: text/plain') >= 0)
123
- t.checkTrue('static body gets content-length', r.toLowerCase().indexOf('content-length: 11') >= 0)
124
-
125
- // ── streaming chunked response (length unknown) ──
126
- t.section('streaming chunked response')
127
- r = await httpSend('127.0.0.1', port, 'GET /stream HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n')
128
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0)
129
- t.checkTrue('transfer-encoding chunked', r.toLowerCase().indexOf('transfer-encoding: chunked') >= 0)
130
- t.checkTrue('no content-length', r.toLowerCase().indexOf('content-length:') < 0)
131
- t.checkTrue('chunk frames + terminator', r.indexOf('7\r\nchunkA/\r\n6\r\nchunkB\r\n0\r\n\r\n') >= 0)
132
-
133
- // ── streaming raw response with known length ──
134
- t.section('streaming known-length response')
135
- r = await httpSend('127.0.0.1', port, 'GET /file 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('content-length 13', r.toLowerCase().indexOf('content-length: 13') >= 0)
138
- t.checkTrue('no chunked encoding', r.toLowerCase().indexOf('transfer-encoding: chunked') < 0)
139
- t.checkTrue('streamed raw body', r.includes('chunkA/chunkB'))
140
- t.checkTrue('no chunk frame headers', r.indexOf('7\r\nchunkA/') < 0)
141
-
142
- // ── HEAD of a streamed body: headers only, empty body ──
143
- t.section('HEAD streaming response')
144
- r = await httpSend('127.0.0.1', port, 'HEAD /stream HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n')
145
- t.checkTrue('HEAD 200', r.indexOf('HTTP/1.1 200') === 0)
146
- t.checkTrue('HEAD content-length 13', r.toLowerCase().indexOf('content-length: 13') >= 0)
147
- const headBodyIdx = r.indexOf('\r\n\r\n')
148
- t.checkTrue('HEAD empty body', r.slice(headBodyIdx + 4).length === 0)
149
-
150
- // ── streaming chunked response with trailing headers ──
151
- t.section('streaming trailer response')
152
- r = await httpSend('127.0.0.1', port, 'GET /stream-trailer HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n')
153
- t.checkTrue('200 status', r.indexOf('HTTP/1.1 200') === 0)
154
- t.checkTrue('trailer declared in head', r.toLowerCase().indexOf('trailer: x-exit-code') >= 0)
155
- t.checkTrue('terminator carries trailer', r.indexOf('0\r\nX-Exit-Code: 3\r\n\r\n') >= 0)
156
- 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)
157
-
158
- // ── fetch client consumes chunked response with trailer footer ──
159
- t.section('fetch consumes trailer response')
160
- {
161
- const rr = await fetch(`http://127.0.0.1:${port}/stream-trailer`)
162
- t.checkTrue('status 200', rr.status === 200)
163
- t.checkTrue('body decoded without trailer', await rr.text() === 'chunkA/chunkB')
164
- }
165
-
166
- // ── POST with body ──
167
- t.section('POST with body')
168
- 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')
169
- t.checkTrue('echo body', r.endsWith('POST:payload'))
170
-
171
- // ── POST with chunked request body ──
172
- t.section('chunked request body')
173
- const chunkedRaw = 'POST /echo HTTP/1.1\r\nHost: x\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n' +
174
- '3\r\nabc\r\n4\r\ndefg\r\n0\r\n\r\n'
175
- r = await httpSend('127.0.0.1', port, chunkedRaw)
176
- t.checkTrue('chunked decoded', r.endsWith('POST:abcdefg'))
177
-
178
- // ── 404 ──
179
- t.section('404')
180
- r = await httpSend('127.0.0.1', port, 'GET /missing HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n')
181
- t.checkTrue('404 status', r.indexOf('HTTP/1.1 404') === 0)
182
- t.checkTrue('404 body', r.endsWith('not found'))
183
-
184
- // ── HEAD (headers present, empty body) ──
185
- t.section('HEAD')
186
- r = await httpSend('127.0.0.1', port, 'HEAD / HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n')
187
- t.checkTrue('HEAD 200', r.indexOf('HTTP/1.1 200') === 0)
188
- t.checkTrue('HEAD content-length present', r.toLowerCase().indexOf('content-length: 6') >= 0)
189
- const bodyIdx = r.indexOf('\r\n\r\n')
190
- t.checkTrue('HEAD empty body', r.slice(bodyIdx + 4).length === 0)
191
-
192
- // ── keep-alive: two requests on one connection ──
193
- t.section('keep-alive pipelining')
194
- const pipelined = 'GET /?name=a HTTP/1.1\r\nHost: x\r\n\r\n' +
195
- 'GET /?name=b HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n'
196
- r = await httpSend('127.0.0.1', port, pipelined, 2)
197
- t.checkTrue('two responses received', r.indexOf('hello a') >= 0 && r.indexOf('hello b') >= 0)
198
- t.checkTrue('connection close on last', r.toLowerCase().indexOf('connection: close') >= 0)
199
-
200
- // ── server received expected requests ──
201
- t.section('request log')
202
- t.check('total requests', 12, requests.length)
203
- t.checkTrue('saw GET /', requests.indexOf('GET /') >= 0)
204
- t.checkTrue('saw POST /echo', requests.indexOf('POST /echo') >= 0)
205
-
206
- server.close()
207
- t.check('closed ok', true, true)
208
-
209
- std.printf(' (http-server suite done, %d requests)\n', requests.length)
210
- },
211
- }
@@ -1,4 +0,0 @@
1
- import '../lib/fetch.js';
2
- import * as os from 'os';
3
- const parent = os.Worker.parent;
4
- parent.postMessage({ type: 'loaded' });
@@ -1,5 +0,0 @@
1
- import '../lib/fetch.js'
2
- import * as os from 'os'
3
-
4
- const parent = os.Worker.parent
5
- parent.postMessage({ type: 'loaded' })
package/test/test_ipv6.js DELETED
@@ -1,134 +0,0 @@
1
- import * as sock from 'sock';
2
- import * as std from 'std';
3
- import * as os from 'os';
4
- import '../lib/fetch.js';
5
- import '../lib/websocket.js';
6
- const HTTP_PORT = 18923;
7
- const HTTPS_PORT = 18924;
8
- export const suite = {
9
- name: 'ipv6',
10
- run: async (t) => {
11
- function assert(name, ok) {
12
- if (ok) {
13
- t.ok++;
14
- std.printf(' PASS: %s\n', name);
15
- }
16
- else {
17
- t.fail++;
18
- std.printf(' FAIL: %s\n', name);
19
- }
20
- }
21
- // ── 1. sock.resolve ──
22
- t.section('sock.resolve ::1');
23
- {
24
- const ip = sock.resolve('::1');
25
- assert('resolve ::1 returns ::1', ip === '::1');
26
- }
27
- // ── 2. Raw socket IPv6 ──
28
- t.section('raw socket ::1 HTTP GET');
29
- await new Promise((resolve, reject) => {
30
- const s = sock.socket();
31
- if (s === null || s < 0) {
32
- t.fail++;
33
- reject(new Error('socket() failed'));
34
- return;
35
- }
36
- let connected = false, gotData = false;
37
- sock.set_on_event(s, (event) => {
38
- if (event.lNetworkEvents & 16 /* FdEvent.FD_CONNECT */) {
39
- if (event.iErrorCode[0] === 0) {
40
- connected = true;
41
- t.ok++;
42
- const req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n";
43
- const buf = new ArrayBuffer(req.length);
44
- const v = new Uint8Array(buf);
45
- for (let i = 0; i < req.length; i++)
46
- v[i] = req.charCodeAt(i);
47
- sock.send(s, buf);
48
- }
49
- else {
50
- sock.closesocket(s);
51
- reject(new Error('connect error: ' + event.iErrorCode[0]));
52
- }
53
- }
54
- if (event.lNetworkEvents & 1 /* FdEvent.FD_READ */ && connected && !gotData) {
55
- const data = sock.recv(s, 4096);
56
- if (data && data.byteLength > 0) {
57
- gotData = true;
58
- t.ok++;
59
- }
60
- }
61
- if (event.lNetworkEvents & 32 /* FdEvent.FD_CLOSE */) {
62
- sock.closesocket(s);
63
- if (gotData && connected)
64
- resolve();
65
- else
66
- reject(new Error('test incomplete'));
67
- }
68
- });
69
- sock.connect(s, '::1', HTTP_PORT);
70
- });
71
- // ── 3. fetch HTTP IPv6 ──
72
- t.section('fetch http://[::1]');
73
- {
74
- const r = await fetch(`http://[::1]:${HTTP_PORT}/`, { timeout: 5000 });
75
- assert('fetch IPv6 HTTP status 200', r.status === 200);
76
- const body = await r.text();
77
- assert('fetch IPv6 HTTP body', body === 'hello from test server');
78
- }
79
- // ── 4. fetch HTTPS IPv6 ──
80
- t.section('fetch https://[::1]');
81
- {
82
- const r = await fetch(`https://[::1]:${HTTPS_PORT}/`, { timeout: 5000, rejectUnauthorized: false });
83
- assert('fetch IPv6 HTTPS status 200', r.status === 200);
84
- const body = await r.text();
85
- assert('fetch IPv6 HTTPS body', body === 'hello from test server');
86
- }
87
- // ── 5. WebSocket IPv6 ──
88
- t.section('ws://[::1] echo');
89
- await new Promise((resolve, reject) => {
90
- const ws = new WebSocket(`ws://[::1]:${HTTP_PORT}/`);
91
- const timeoutId = os.setTimeout(() => reject(new Error('WS IPv6 timeout')), 10000);
92
- ws.onopen = () => {
93
- t.ok++;
94
- ws.send('hello ipv6');
95
- };
96
- ws.onmessage = (evt) => {
97
- t.ok++;
98
- assert('WS IPv6 echo matches', evt.data === 'hello ipv6');
99
- ws.close();
100
- };
101
- ws.onclose = () => {
102
- os.clearTimeout(timeoutId);
103
- resolve();
104
- };
105
- ws.onerror = () => {
106
- os.clearTimeout(timeoutId);
107
- reject(new Error('WS IPv6 error'));
108
- };
109
- });
110
- // ── 6. WebSocket WSS IPv6 ──
111
- t.section('wss://[::1] echo');
112
- await new Promise((resolve, reject) => {
113
- const ws = new WebSocket(`wss://[::1]:${HTTPS_PORT}/`, { rejectUnauthorized: false });
114
- const timeoutId = os.setTimeout(() => reject(new Error('WSS IPv6 timeout')), 10000);
115
- ws.onopen = () => {
116
- t.ok++;
117
- ws.send('hello wss ipv6');
118
- };
119
- ws.onmessage = (evt) => {
120
- t.ok++;
121
- assert('WSS IPv6 echo matches', evt.data === 'hello wss ipv6');
122
- ws.close();
123
- };
124
- ws.onclose = () => {
125
- os.clearTimeout(timeoutId);
126
- resolve();
127
- };
128
- ws.onerror = () => {
129
- os.clearTimeout(timeoutId);
130
- reject(new Error('WSS IPv6 error'));
131
- };
132
- });
133
- }
134
- };
package/test/test_ipv6.ts DELETED
@@ -1,130 +0,0 @@
1
- import * as sock from 'sock'
2
- import * as std from 'std'
3
- import * as os from 'os'
4
- import '../lib/fetch.js'
5
- import '../lib/websocket.js'
6
- import { Tester } from './test_helper.js'
7
- import { FdEvent } from '../constants'
8
-
9
- const HTTP_PORT = 18923
10
- const HTTPS_PORT = 18924
11
-
12
- export const suite = {
13
- name: 'ipv6',
14
- run: async (t: Tester) => {
15
- function assert(name: string, ok: boolean): void {
16
- if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
17
- else { t.fail++; std.printf(' FAIL: %s\n', name) }
18
- }
19
-
20
- // ── 1. sock.resolve ──
21
- t.section('sock.resolve ::1')
22
- {
23
- const ip = sock.resolve('::1')
24
- assert('resolve ::1 returns ::1', ip === '::1')
25
- }
26
-
27
- // ── 2. Raw socket IPv6 ──
28
- t.section('raw socket ::1 HTTP GET')
29
- await new Promise<void>((resolve, reject) => {
30
- const s = sock.socket()
31
- if (s === null || s < 0) { t.fail++; reject(new Error('socket() failed')); return }
32
-
33
- let connected = false, gotData = false
34
-
35
- sock.set_on_event(s, (event: { lNetworkEvents: number; iErrorCode: number[] }) => {
36
- if (event.lNetworkEvents & FdEvent.FD_CONNECT) {
37
- if (event.iErrorCode[0] === 0) {
38
- connected = true; t.ok++
39
- const req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"
40
- const buf = new ArrayBuffer(req.length)
41
- const v = new Uint8Array(buf)
42
- for (let i = 0; i < req.length; i++) v[i] = req.charCodeAt(i)
43
- sock.send(s, buf)
44
- } else {
45
- sock.closesocket(s)
46
- reject(new Error('connect error: ' + event.iErrorCode[0]))
47
- }
48
- }
49
- if (event.lNetworkEvents & FdEvent.FD_READ && connected && !gotData) {
50
- const data = sock.recv(s, 4096)
51
- if (data && data.byteLength > 0) { gotData = true; t.ok++ }
52
- }
53
- if (event.lNetworkEvents & FdEvent.FD_CLOSE) {
54
- sock.closesocket(s)
55
- if (gotData && connected) resolve()
56
- else reject(new Error('test incomplete'))
57
- }
58
- })
59
- sock.connect(s, '::1', HTTP_PORT)
60
- })
61
-
62
- // ── 3. fetch HTTP IPv6 ──
63
- t.section('fetch http://[::1]')
64
- {
65
- const r = await fetch(`http://[::1]:${HTTP_PORT}/`, { timeout: 5000 })
66
- assert('fetch IPv6 HTTP status 200', r.status === 200)
67
- const body = await r.text()
68
- assert('fetch IPv6 HTTP body', body === 'hello from test server')
69
- }
70
-
71
- // ── 4. fetch HTTPS IPv6 ──
72
- t.section('fetch https://[::1]')
73
- {
74
- const r = await fetch(`https://[::1]:${HTTPS_PORT}/`, { timeout: 5000, rejectUnauthorized: false })
75
- assert('fetch IPv6 HTTPS status 200', r.status === 200)
76
- const body = await r.text()
77
- assert('fetch IPv6 HTTPS body', body === 'hello from test server')
78
- }
79
-
80
- // ── 5. WebSocket IPv6 ──
81
- t.section('ws://[::1] echo')
82
- await new Promise<void>((resolve, reject) => {
83
- const ws = new WebSocket(`ws://[::1]:${HTTP_PORT}/`)
84
- const timeoutId = os.setTimeout(() => reject(new Error('WS IPv6 timeout')), 10000)
85
-
86
- ws.onopen = () => {
87
- t.ok++
88
- ws.send('hello ipv6')
89
- }
90
- ws.onmessage = (evt) => {
91
- t.ok++
92
- assert('WS IPv6 echo matches', evt.data === 'hello ipv6')
93
- ws.close()
94
- }
95
- ws.onclose = () => {
96
- os.clearTimeout(timeoutId)
97
- resolve()
98
- }
99
- ws.onerror = () => {
100
- os.clearTimeout(timeoutId)
101
- reject(new Error('WS IPv6 error'))
102
- }
103
- })
104
-
105
- // ── 6. WebSocket WSS IPv6 ──
106
- t.section('wss://[::1] echo')
107
- await new Promise<void>((resolve, reject) => {
108
- const ws = new WebSocket(`wss://[::1]:${HTTPS_PORT}/`, { rejectUnauthorized: false })
109
- const timeoutId = os.setTimeout(() => reject(new Error('WSS IPv6 timeout')), 10000)
110
-
111
- ws.onopen = () => {
112
- t.ok++
113
- ws.send('hello wss ipv6')
114
- }
115
- ws.onmessage = (evt) => {
116
- t.ok++
117
- assert('WSS IPv6 echo matches', evt.data === 'hello wss ipv6')
118
- ws.close()
119
- }
120
- ws.onclose = () => {
121
- os.clearTimeout(timeoutId)
122
- resolve()
123
- }
124
- ws.onerror = () => {
125
- os.clearTimeout(timeoutId)
126
- reject(new Error('WSS IPv6 error'))
127
- }
128
- })
129
- }
130
- }