quickwin 1.0.2 → 1.1.1

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 (78) hide show
  1. package/README.en.md +204 -204
  2. package/README.md +203 -203
  3. package/examples/PdfCanvas.tsx +83 -83
  4. package/examples/exec_server.ts +35 -35
  5. package/examples/pdf_preview2.ts +375 -375
  6. package/examples/pdf_viewer.tsx +279 -279
  7. package/examples/test_gallery.tsx +285 -285
  8. package/examples/test_react_lazy.tsx +63 -63
  9. package/examples/test_react_listbox.tsx +71 -71
  10. package/examples/test_root_window.tsx +41 -41
  11. package/examples/test_tab.tsx +75 -75
  12. package/examples/tray_demo.tsx +81 -81
  13. package/lib/assert.ts +6 -6
  14. package/lib/cache-utils.ts +40 -40
  15. package/lib/dumpRects.ts +25 -25
  16. package/lib/fetch.ts +502 -502
  17. package/lib/http-common.ts +399 -399
  18. package/lib/http-server.ts +424 -424
  19. package/lib/polyfill.ts +171 -171
  20. package/lib/react-qw/components/index.ts +17 -17
  21. package/lib/react-qw/index.ts +90 -90
  22. package/lib/react-qw/jsx.d.ts +34 -34
  23. package/lib/react-qw/layout.ts +111 -111
  24. package/lib/react-qw/props.ts +36 -36
  25. package/lib/react-qw/reconciler.ts +373 -373
  26. package/lib/stream.ts +21 -21
  27. package/lib/text-codec.ts +171 -171
  28. package/lib/text-measure.ts +54 -54
  29. package/lib/url.ts +201 -201
  30. package/lib/vendor/web-streams/ponyfill.d.mts +829 -829
  31. package/lib/vendor/web-streams/ponyfill.mjs +8 -8
  32. package/lib/websocket.js +8 -0
  33. package/lib/websocket.ts +563 -555
  34. package/package.json +50 -44
  35. package/qwin-nowasm-x86.exe +0 -0
  36. package/qwin-nowasm.exe +0 -0
  37. package/qwin-x86.exe +0 -0
  38. package/qwin.exe +0 -0
  39. package/test/run.ts +96 -96
  40. package/test/test_basic.ts +9 -9
  41. package/test/test_basic_fetch.ts +33 -33
  42. package/test/test_brotli.ts +52 -52
  43. package/test/test_fetch_cache.ts +187 -187
  44. package/test/test_ffi.ts +174 -174
  45. package/test/test_frame_encoding.ts +132 -132
  46. package/test/test_helper.ts +80 -80
  47. package/test/test_http_import.ts +74 -74
  48. package/test/test_http_server.ts +136 -136
  49. package/test/test_import_dir.ts +5 -5
  50. package/test/test_ipv6.ts +129 -129
  51. package/test/test_meta_url.ts +4 -4
  52. package/test/test_mupdf_render.ts +74 -74
  53. package/test/test_mupdf_twice.ts +81 -81
  54. package/test/test_mupdf_wasm.ts +30 -30
  55. package/test/test_net_event.ts +55 -55
  56. package/test/test_net_fetch.ts +238 -238
  57. package/test/test_net_websocket.ts +164 -164
  58. package/test/test_polyfill.ts +159 -159
  59. package/test/test_url.ts +183 -183
  60. package/test/test_wasm_basic.ts +73 -73
  61. package/test/test_wasm_import_global.ts +45 -45
  62. package/test/test_wasm_sjlj.ts +125 -125
  63. package/test/test_wasm_types.ts +124 -124
  64. package/test/test_worker.ts +24 -24
  65. package/test/test_worker_fetch.ts +27 -27
  66. package/test/test_worker_net.ts +54 -54
  67. package/test/test_worker_wasm_concurrent.ts +45 -45
  68. package/test/worker_fetch.ts +13 -13
  69. package/test/worker_helper.ts +1 -1
  70. package/test/worker_http.ts +20 -20
  71. package/test/worker_import_lib.ts +13 -13
  72. package/test/worker_module.ts +17 -17
  73. package/test/worker_wasm_concurrent.ts +22 -22
  74. package/tsconfig.json +27 -27
  75. package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -571
  76. package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -2749
  77. package/vendor/mupdf-wasm/mupdf.d.ts +939 -939
  78. package/vendor/mupdf-wasm/mupdf.js +3317 -3317
package/package.json CHANGED
@@ -1,44 +1,50 @@
1
- {
2
- "type": "module",
3
- "name": "quickwin",
4
- "version": "1.0.2",
5
- "description": "QuickJS Win32 runtime — GUI, networking, WASM, FFI, and more",
6
- "bin": {
7
- "quickwin": "qwin.exe",
8
- "quickwin-nowasm": "qwin-nowasm.exe",
9
- "qwin": "qwin.exe",
10
- "qwin-nowasm": "qwin-nowasm.exe"
11
- },
12
- "files": [
13
- "qwin.exe",
14
- "qwin-nowasm.exe",
15
- "lib/",
16
- "test/",
17
- "examples/",
18
- "vendor/",
19
- "quickwin.d.ts",
20
- "quickwin_const.d.ts",
21
- "tsconfig.json",
22
- "README.md",
23
- "README.en.md"
24
- ],
25
- "license": "MIT",
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/xna00/quickwin.git"
29
- },
30
- "devDependencies": {
31
- "@types/node": "^24.13.2",
32
- "@types/react": "^19.2.17",
33
- "@types/react-reconciler": "^0.33.0",
34
- "@types/ws": "^8.18.1",
35
- "esbuild": "^0.28.0",
36
- "typescript": "^7.0.2"
37
- },
38
- "dependencies": {
39
- "react": "^19.2.7",
40
- "react-reconciler": "^0.33.0",
41
- "web-streams-polyfill": "^4.3.0",
42
- "ws": "^8.21.0"
43
- }
44
- }
1
+ {
2
+ "type": "module",
3
+ "name": "quickwin",
4
+ "version": "1.1.1",
5
+ "description": "QuickJS Win32 runtime — GUI, networking, WASM, FFI, and more",
6
+ "bin": {
7
+ "quickwin": "qwin.exe",
8
+ "quickwin-nowasm": "qwin-nowasm.exe",
9
+ "qwin": "qwin.exe",
10
+ "qwin-nowasm": "qwin-nowasm.exe",
11
+ "quickwin-x86": "qwin-x86.exe",
12
+ "quickwin-nowasm-x86": "qwin-nowasm-x86.exe",
13
+ "qwin-x86": "qwin-x86.exe",
14
+ "qwin-nowasm-x86": "qwin-nowasm-x86.exe"
15
+ },
16
+ "files": [
17
+ "qwin.exe",
18
+ "qwin-nowasm.exe",
19
+ "qwin-x86.exe",
20
+ "qwin-nowasm-x86.exe",
21
+ "lib/",
22
+ "test/",
23
+ "examples/",
24
+ "vendor/",
25
+ "quickwin.d.ts",
26
+ "quickwin_const.d.ts",
27
+ "tsconfig.json",
28
+ "README.md",
29
+ "README.en.md"
30
+ ],
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/xna00/quickwin.git"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^24.13.2",
38
+ "@types/react": "^19.2.17",
39
+ "@types/react-reconciler": "^0.33.0",
40
+ "@types/ws": "^8.18.1",
41
+ "esbuild": "^0.28.0",
42
+ "typescript": "^7.0.2"
43
+ },
44
+ "dependencies": {
45
+ "react": "^19.2.7",
46
+ "react-reconciler": "^0.33.0",
47
+ "web-streams-polyfill": "^4.3.0",
48
+ "ws": "^8.21.0"
49
+ }
50
+ }
Binary file
package/qwin-nowasm.exe CHANGED
Binary file
package/qwin-x86.exe ADDED
Binary file
package/qwin.exe CHANGED
Binary file
package/test/run.ts CHANGED
@@ -1,96 +1,96 @@
1
- import * as std from 'std'
2
- import { Tester } from './test_helper.js'
3
-
4
- declare var scriptArgs: string[]
5
-
6
- function formatDuration(ms: number): string {
7
- if (ms >= 1000) return (ms / 1000).toFixed(2) + 's'
8
- return ms + 'ms'
9
- }
10
-
11
- const BOLD = '\x1b[1m'
12
- const GREEN = '\x1b[32m'
13
- const RED = '\x1b[31m'
14
- const RESET = '\x1b[0m'
15
-
16
- const suiteDefs = [
17
- { name: 'basic', file: './test_basic.js', tags: [] },
18
- { name: 'basic-fetch', file: './test_basic_fetch.js', tags: [] },
19
- { name: 'ipv6', file: './test_ipv6.js', tags: ['net'] },
20
- { name: 'url', file: './test_url.js', tags: [] },
21
- { name: 'wasm-basic', file: './test_wasm_basic.js', tags: ['wasm'] },
22
- { name: 'wasm-types', file: './test_wasm_types.js', tags: ['wasm'] },
23
- { name: 'wasm-import-global', file: './test_wasm_import_global.js', tags: ['wasm'] },
24
- { name: 'wasm-sjlj', file: './test_wasm_sjlj.js', tags: ['wasm'] },
25
- { name: 'wasm-frame-encoding', file: './test_frame_encoding.js', tags: ['wasm'] },
26
- { name: 'mupdf-wasm', file: './test_mupdf_wasm.js', tags: ['wasm', 'mupdf'] },
27
- { name: 'mupdf-twice', file: './test_mupdf_twice.js', tags: ['wasm', 'mupdf'] },
28
- { name: 'mupdf-render', file: './test_mupdf_render.js', tags: ['wasm', 'mupdf'] },
29
- { name: 'ffi', file: './test_ffi.js', tags: [] },
30
- { name: 'net-fetch', file: './test_net_fetch.js', tags: ['net'] },
31
- { name: 'net-websocket', file: './test_net_websocket.js', tags: ['net'] },
32
- { name: 'net-event', file: './test_net_event.js', tags: ['net'] },
33
- { name: 'http-server', file: './test_http_server.js', tags: ['net'] },
34
- { name: 'http-import', file: './test_http_import.js', tags: ['net'] },
35
- { name: 'fetch-cache', file: './test_fetch_cache.js', tags: ['net'] },
36
- { name: 'polyfill', file: './test_polyfill.js', tags: [] },
37
- { name: 'brotli', file: './test_brotli.js', tags: [] },
38
- { name: 'worker', file: './test_worker.js', tags: [] },
39
- { name: 'worker-wasm', file: './test_worker_wasm_concurrent.js', tags: ['wasm'] },
40
- { name: 'worker-http', file: './test_worker_net.js', tags: ['net'] },
41
- { name: 'worker-fetch', file: './test_worker_fetch.js', tags: ['net'] }
42
- ]
43
-
44
- async function main(): Promise<void> {
45
- const filter = scriptArgs.length > 1 ? scriptArgs[1] : ''
46
-
47
- std.printf('%s====== QuickWin Test Runner ======%s\n', BOLD, RESET)
48
- if (filter) std.printf('Filter: %s\n', filter)
49
-
50
- const results: { name: string, ok: number, fail: number, elapsed: number }[] = []
51
- let totalOk = 0, totalFail = 0
52
-
53
- for (const def of suiteDefs) {
54
- if (filter) {
55
- if (filter.startsWith('-')) {
56
- const excludeTag = filter.slice(1)
57
- if (def.tags.indexOf(excludeTag) >= 0) continue
58
- } else {
59
- if (def.name.indexOf(filter) < 0) continue
60
- }
61
- }
62
-
63
- let mod: any
64
- try {
65
- mod = await import(def.file)
66
- } catch (e) {
67
- continue
68
- }
69
- if (!mod.suite) continue
70
-
71
- const t = new Tester()
72
- std.printf('\n%s--- %s ---%s\n', BOLD, def.name, RESET)
73
- const suiteStart = Date.now()
74
- try {
75
- await mod.suite.run(t)
76
- } catch (e) {
77
- std.printf(' %sSUITE FAILED:%s %s\n', RED, RESET, String(e))
78
- t.fail++
79
- }
80
- const suiteElapsed = Date.now() - suiteStart
81
- t.summary()
82
- results.push({ name: def.name, ok: t.ok, fail: t.fail, elapsed: suiteElapsed })
83
- totalOk += t.ok
84
- totalFail += t.fail
85
- }
86
-
87
- const color = totalFail > 0 ? RED : GREEN
88
- std.printf('\n%s====== Test Results ======%s\n', BOLD, RESET)
89
- for (const r of results) {
90
- const c = r.fail > 0 ? RED : GREEN
91
- std.printf(' %s%-18s %s%d/%d passed %s(%s)%s\n', c, r.name, RESET, r.ok, r.ok + r.fail, c, formatDuration(r.elapsed), RESET)
92
- }
93
- std.printf('%s====== Summary: %d/%d passed ======%s\n', color, totalOk, totalOk + totalFail, RESET)
94
- }
95
-
96
- main()
1
+ import * as std from 'std'
2
+ import { Tester } from './test_helper.js'
3
+
4
+ declare var scriptArgs: string[]
5
+
6
+ function formatDuration(ms: number): string {
7
+ if (ms >= 1000) return (ms / 1000).toFixed(2) + 's'
8
+ return ms + 'ms'
9
+ }
10
+
11
+ const BOLD = '\x1b[1m'
12
+ const GREEN = '\x1b[32m'
13
+ const RED = '\x1b[31m'
14
+ const RESET = '\x1b[0m'
15
+
16
+ const suiteDefs = [
17
+ { name: 'basic', file: './test_basic.js', tags: [] },
18
+ { name: 'basic-fetch', file: './test_basic_fetch.js', tags: [] },
19
+ { name: 'ipv6', file: './test_ipv6.js', tags: ['net'] },
20
+ { name: 'url', file: './test_url.js', tags: [] },
21
+ { name: 'wasm-basic', file: './test_wasm_basic.js', tags: ['wasm'] },
22
+ { name: 'wasm-types', file: './test_wasm_types.js', tags: ['wasm'] },
23
+ { name: 'wasm-import-global', file: './test_wasm_import_global.js', tags: ['wasm'] },
24
+ { name: 'wasm-sjlj', file: './test_wasm_sjlj.js', tags: ['wasm'] },
25
+ { name: 'wasm-frame-encoding', file: './test_frame_encoding.js', tags: ['wasm'] },
26
+ { name: 'mupdf-wasm', file: './test_mupdf_wasm.js', tags: ['wasm', 'mupdf'] },
27
+ { name: 'mupdf-twice', file: './test_mupdf_twice.js', tags: ['wasm', 'mupdf'] },
28
+ { name: 'mupdf-render', file: './test_mupdf_render.js', tags: ['wasm', 'mupdf'] },
29
+ { name: 'ffi', file: './test_ffi.js', tags: [] },
30
+ { name: 'net-fetch', file: './test_net_fetch.js', tags: ['net'] },
31
+ { name: 'net-websocket', file: './test_net_websocket.js', tags: ['net'] },
32
+ { name: 'net-event', file: './test_net_event.js', tags: ['net'] },
33
+ { name: 'http-server', file: './test_http_server.js', tags: ['net'] },
34
+ { name: 'http-import', file: './test_http_import.js', tags: ['net'] },
35
+ { name: 'fetch-cache', file: './test_fetch_cache.js', tags: ['net'] },
36
+ { name: 'polyfill', file: './test_polyfill.js', tags: [] },
37
+ { name: 'brotli', file: './test_brotli.js', tags: [] },
38
+ { name: 'worker', file: './test_worker.js', tags: [] },
39
+ { name: 'worker-wasm', file: './test_worker_wasm_concurrent.js', tags: ['wasm'] },
40
+ { name: 'worker-http', file: './test_worker_net.js', tags: ['net'] },
41
+ { name: 'worker-fetch', file: './test_worker_fetch.js', tags: ['net'] }
42
+ ]
43
+
44
+ async function main(): Promise<void> {
45
+ const filter = scriptArgs.length > 1 ? scriptArgs[1] : ''
46
+
47
+ std.printf('%s====== QuickWin Test Runner ======%s\n', BOLD, RESET)
48
+ if (filter) std.printf('Filter: %s\n', filter)
49
+
50
+ const results: { name: string, ok: number, fail: number, elapsed: number }[] = []
51
+ let totalOk = 0, totalFail = 0
52
+
53
+ for (const def of suiteDefs) {
54
+ if (filter) {
55
+ if (filter.startsWith('-')) {
56
+ const excludeTag = filter.slice(1)
57
+ if (def.tags.indexOf(excludeTag) >= 0) continue
58
+ } else {
59
+ if (def.name.indexOf(filter) < 0) continue
60
+ }
61
+ }
62
+
63
+ let mod: any
64
+ try {
65
+ mod = await import(def.file)
66
+ } catch (e) {
67
+ continue
68
+ }
69
+ if (!mod.suite) continue
70
+
71
+ const t = new Tester()
72
+ std.printf('\n%s--- %s ---%s\n', BOLD, def.name, RESET)
73
+ const suiteStart = Date.now()
74
+ try {
75
+ await mod.suite.run(t)
76
+ } catch (e) {
77
+ std.printf(' %sSUITE FAILED:%s %s\n', RED, RESET, String(e))
78
+ t.fail++
79
+ }
80
+ const suiteElapsed = Date.now() - suiteStart
81
+ t.summary()
82
+ results.push({ name: def.name, ok: t.ok, fail: t.fail, elapsed: suiteElapsed })
83
+ totalOk += t.ok
84
+ totalFail += t.fail
85
+ }
86
+
87
+ const color = totalFail > 0 ? RED : GREEN
88
+ std.printf('\n%s====== Test Results ======%s\n', BOLD, RESET)
89
+ for (const r of results) {
90
+ const c = r.fail > 0 ? RED : GREEN
91
+ std.printf(' %s%-18s %s%d/%d passed %s(%s)%s\n', c, r.name, RESET, r.ok, r.ok + r.fail, c, formatDuration(r.elapsed), RESET)
92
+ }
93
+ std.printf('%s====== Summary: %d/%d passed ======%s\n', color, totalOk, totalOk + totalFail, RESET)
94
+ }
95
+
96
+ main()
@@ -1,9 +1,9 @@
1
- import { Tester } from './test_helper.js'
2
-
3
- export const suite = {
4
- name: 'basic',
5
- run: (t: Tester) => {
6
- t.section('smoke')
7
- t.check('hello', true, true)
8
- }
9
- }
1
+ import { Tester } from './test_helper.js'
2
+
3
+ export const suite = {
4
+ name: 'basic',
5
+ run: (t: Tester) => {
6
+ t.section('smoke')
7
+ t.check('hello', true, true)
8
+ }
9
+ }
@@ -1,33 +1,33 @@
1
- import * as std from 'std'
2
- import '../lib/fetch.js'
3
- import { Tester } from './test_helper.js'
4
-
5
- const PORT = 18923
6
- const URL127 = `http://127.0.0.1:${PORT}/`
7
- const URLLocalhost = `http://localhost:${PORT}/`
8
-
9
- export const suite = {
10
- name: 'basic-fetch',
11
- run: async (t: Tester) => {
12
- function assert(name: string, ok: boolean): void {
13
- if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
14
- else { t.fail++; std.printf(' FAIL: %s\n', name) }
15
- }
16
-
17
- t.section('fetch 127.0.0.1')
18
- {
19
- const r = await fetch(URL127)
20
- assert('status 200', r.status === 200)
21
- const body = await r.text()
22
- assert('body = hello from test server', body === 'hello from test server')
23
- }
24
-
25
- t.section('fetch localhost')
26
- {
27
- const r = await fetch(URLLocalhost)
28
- assert('status 200', r.status === 200)
29
- const body = await r.text()
30
- assert('body = hello from test server', body === 'hello from test server')
31
- }
32
- }
33
- }
1
+ import * as std from 'std'
2
+ import '../lib/fetch.js'
3
+ import { Tester } from './test_helper.js'
4
+
5
+ const PORT = 18923
6
+ const URL127 = `http://127.0.0.1:${PORT}/`
7
+ const URLLocalhost = `http://localhost:${PORT}/`
8
+
9
+ export const suite = {
10
+ name: 'basic-fetch',
11
+ run: async (t: Tester) => {
12
+ function assert(name: string, ok: boolean): void {
13
+ if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
14
+ else { t.fail++; std.printf(' FAIL: %s\n', name) }
15
+ }
16
+
17
+ t.section('fetch 127.0.0.1')
18
+ {
19
+ const r = await fetch(URL127)
20
+ assert('status 200', r.status === 200)
21
+ const body = await r.text()
22
+ assert('body = hello from test server', body === 'hello from test server')
23
+ }
24
+
25
+ t.section('fetch localhost')
26
+ {
27
+ const r = await fetch(URLLocalhost)
28
+ assert('status 200', r.status === 200)
29
+ const body = await r.text()
30
+ assert('body = hello from test server', body === 'hello from test server')
31
+ }
32
+ }
33
+ }
@@ -1,52 +1,52 @@
1
- import * as brotli from 'brotli'
2
- import { Tester } from './test_helper.js'
3
-
4
- function abToString(buf: ArrayBuffer): string {
5
- const bytes = new Uint8Array(buf)
6
- let s = ''
7
- for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]!)
8
- return s
9
- }
10
-
11
- // pre-compressed with brotli CLI: "hello brotli! this is a test of decompression"
12
- const COMPRESSED_HEX = 'a16001c0ef4cb07142bdbbe12588185985d055995ca6b1bdb52083f4028dc6e59c8660a24efa701549c30701'
13
-
14
- function hexToArrayBuffer(hex: string): ArrayBuffer {
15
- const bytes = new Uint8Array(hex.length / 2)
16
- for (let i = 0; i < hex.length; i += 2)
17
- bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16)
18
- return bytes.buffer as ArrayBuffer
19
- }
20
-
21
- export const suite = {
22
- name: 'brotli',
23
- run: (t: Tester) => {
24
- t.section('decompress function exists')
25
- t.checkTrue('decompress is function', typeof brotli.decompress === 'function')
26
-
27
- t.section('decompress known string')
28
- const compressed = hexToArrayBuffer(COMPRESSED_HEX)
29
- const decompressed = brotli.decompress(compressed)
30
- t.checkTrue('returns ArrayBuffer', decompressed instanceof ArrayBuffer)
31
- const result = abToString(decompressed)
32
- t.check('roundtrip', 'hello brotli! this is a test of decompression', result)
33
-
34
- t.section('invalid data throws')
35
- let threw = false
36
- try {
37
- brotli.decompress(new ArrayBuffer(10))
38
- } catch (e) {
39
- threw = true
40
- }
41
- t.checkTrue('throws on invalid brotli data', threw)
42
-
43
- t.section('non-ArrayBuffer throws')
44
- let threw2 = false
45
- try {
46
- ;(brotli as any).decompress('not a buffer')
47
- } catch (e) {
48
- threw2 = true
49
- }
50
- t.checkTrue('throws on non-ArrayBuffer', threw2)
51
- }
52
- }
1
+ import * as brotli from 'brotli'
2
+ import { Tester } from './test_helper.js'
3
+
4
+ function abToString(buf: ArrayBuffer): string {
5
+ const bytes = new Uint8Array(buf)
6
+ let s = ''
7
+ for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]!)
8
+ return s
9
+ }
10
+
11
+ // pre-compressed with brotli CLI: "hello brotli! this is a test of decompression"
12
+ const COMPRESSED_HEX = 'a16001c0ef4cb07142bdbbe12588185985d055995ca6b1bdb52083f4028dc6e59c8660a24efa701549c30701'
13
+
14
+ function hexToArrayBuffer(hex: string): ArrayBuffer {
15
+ const bytes = new Uint8Array(hex.length / 2)
16
+ for (let i = 0; i < hex.length; i += 2)
17
+ bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16)
18
+ return bytes.buffer as ArrayBuffer
19
+ }
20
+
21
+ export const suite = {
22
+ name: 'brotli',
23
+ run: (t: Tester) => {
24
+ t.section('decompress function exists')
25
+ t.checkTrue('decompress is function', typeof brotli.decompress === 'function')
26
+
27
+ t.section('decompress known string')
28
+ const compressed = hexToArrayBuffer(COMPRESSED_HEX)
29
+ const decompressed = brotli.decompress(compressed)
30
+ t.checkTrue('returns ArrayBuffer', decompressed instanceof ArrayBuffer)
31
+ const result = abToString(decompressed)
32
+ t.check('roundtrip', 'hello brotli! this is a test of decompression', result)
33
+
34
+ t.section('invalid data throws')
35
+ let threw = false
36
+ try {
37
+ brotli.decompress(new ArrayBuffer(10))
38
+ } catch (e) {
39
+ threw = true
40
+ }
41
+ t.checkTrue('throws on invalid brotli data', threw)
42
+
43
+ t.section('non-ArrayBuffer throws')
44
+ let threw2 = false
45
+ try {
46
+ ;(brotli as any).decompress('not a buffer')
47
+ } catch (e) {
48
+ threw2 = true
49
+ }
50
+ t.checkTrue('throws on non-ArrayBuffer', threw2)
51
+ }
52
+ }