Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100// What node:zlib refuses, and why: the runtime's own surface, so not a Node golden.// What it does (builtin-zlib-*.cjs) is checked against Node in builtins-golden.spec.ts.import { test, expect } from "@playwright/test";import { guestLines } from "./guest";
test("every *Sync form refuses until the WASM residue lands", async ({ page }) => { const lines = await guestLines(page, { "/app/main.cjs": [ 'const zlib = require("node:zlib");', 'for (const f of ["gzipSync", "gunzipSync", "deflateSync", "inflateSync", "deflateRawSync", "inflateRawSync", "unzipSync", "brotliCompressSync", "zstdDecompressSync"]) {', ' try { zlib[f](Buffer.from("x")); console.log(f, "returned"); } catch (e) { console.log(f, e.code, /node:zlib/.test(e.message), e.message.slice(e.message.indexOf("supported (") + 11, -1)); }', "}", ].join("\n"), }, "/app/main.cjs"); const residue = "synchronous zlib arrives with the WASM residue (DESIGN step 5)"; expect(lines).toEqual([ `gzipSync ERR_NIB_UNSUPPORTED true ${residue}`, `gunzipSync ERR_NIB_UNSUPPORTED true ${residue}`, `deflateSync ERR_NIB_UNSUPPORTED true ${residue}`, `inflateSync ERR_NIB_UNSUPPORTED true ${residue}`, `deflateRawSync ERR_NIB_UNSUPPORTED true ${residue}`, `inflateRawSync ERR_NIB_UNSUPPORTED true ${residue}`, `unzipSync ERR_NIB_UNSUPPORTED true ${residue}`, "brotliCompressSync ERR_NIB_UNSUPPORTED true brotli is not a CompressionStream format, and synchronous zlib arrives with the WASM residue (DESIGN step 5)", "zstdDecompressSync ERR_NIB_UNSUPPORTED true zstd is not a CompressionStream format, and synchronous zlib arrives with the WASM residue (DESIGN step 5)", ]);});
test("brotli and zstd refuse in every form, naming the missing browser format", async ({ page }) => { const lines = await guestLines(page, { "/app/main.cjs": [ 'const zlib = require("node:zlib");', 'for (const f of ["brotliCompress", "brotliDecompress", "createBrotliCompress", "createBrotliDecompress", "zstdCompress", "createZstdDecompress"]) {', ' try { zlib[f](Buffer.from("x"), () => {}); console.log(f, "returned"); } catch (e) { console.log(f, e.code, e.message); }', "}", ].join("\n"), }, "/app/main.cjs"); expect(lines).toEqual([ "brotliCompress ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib brotliCompress() is not supported (brotli is not a CompressionStream format)", "brotliDecompress ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib brotliDecompress() is not supported (brotli is not a CompressionStream format)", "createBrotliCompress ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib createBrotliCompress() is not supported (brotli is not a CompressionStream format)", "createBrotliDecompress ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib createBrotliDecompress() is not supported (brotli is not a CompressionStream format)", "zstdCompress ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib zstdCompress() is not supported (zstd is not a CompressionStream format)", "createZstdDecompress ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib createZstdDecompress() is not supported (zstd is not a CompressionStream format)", ]);});
test("dictionary and a non-default windowBits refuse; level, memLevel and strategy are accepted", async ({ page }) => { const lines = await guestLines(page, { "/app/main.cjs": [ 'const zlib = require("node:zlib");', "const tries = [", ' ["deflate", { dictionary: Buffer.from("dict") }],', ' ["gzip", { windowBits: 9 }],', ' ["inflate", { windowBits: 12 }],', ' ["gunzip", { windowBits: 0 }],', ' ["gzip", { windowBits: 15, level: 9, memLevel: 1, strategy: 1 }],', "];", "for (const [f, opts] of tries) {", ' try { zlib[f](Buffer.from("x"), opts, (e) => console.log(f, JSON.stringify(opts), "callback", e && e.code)); }', ' catch (e) { console.log(f, JSON.stringify(opts), e.code, e.message); }', "}", ].join("\n"), }, "/app/main.cjs"); expect(lines).toEqual([ 'deflate {"dictionary":{"type":"Buffer","data":[100,105,99,116]}} ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib the dictionary option is not supported (CompressionStream takes no preset dictionary)', 'gzip {"windowBits":9} ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib windowBits 9 is not supported (CompressionStream fixes the window at 15 bits)', 'inflate {"windowBits":12} ERR_NIB_UNSUPPORTED ERR_NIB_UNSUPPORTED: node:zlib windowBits 12 is not supported (CompressionStream fixes the window at 15 bits)', 'gunzip {"windowBits":0} callback Z_BUF_ERROR', 'gzip {"windowBits":15,"level":9,"memLevel":1,"strategy":1} callback null', ]);});
test("streams refuse the options and controls CompressionStream lacks", async ({ page }) => { const lines = await guestLines(page, { "/app/main.cjs": [ 'const zlib = require("node:zlib");', "const attempts = {", ' "createDeflate dictionary": () => zlib.createDeflate({ dictionary: Buffer.from("d") }),', ' "createInflateRaw windowBits": () => zlib.createInflateRaw({ windowBits: 10 }),', ' "new BrotliCompress": () => new zlib.BrotliCompress(),', ' "flush": () => zlib.createGzip().flush(),', ' "params": () => zlib.createGzip().params(1, 0),', ' "reset": () => zlib.createGunzip().reset(),', "};", "for (const [label, f] of Object.entries(attempts)) {", ' try { f(); console.log(label, "returned"); } catch (e) { console.log(label, e.code, e.message.slice(e.message.indexOf("supported (") + 11, -1)); }', "}", ].join("\n"), }, "/app/main.cjs"); expect(lines).toEqual([ "createDeflate dictionary ERR_NIB_UNSUPPORTED CompressionStream takes no preset dictionary", "createInflateRaw windowBits ERR_NIB_UNSUPPORTED CompressionStream fixes the window at 15 bits", "new BrotliCompress ERR_NIB_UNSUPPORTED brotli is not a CompressionStream format", "flush ERR_NIB_UNSUPPORTED CompressionStream cannot flush mid-stream", "params ERR_NIB_UNSUPPORTED CompressionStream options are fixed at creation", "reset ERR_NIB_UNSUPPORTED a CompressionStream cannot be reset", ]);});