Files
core/test/bun/compression.test.ts
T
chrnx 86d6954f72
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 31s
CI / runtimes (edge) (pull_request) Successful in 23s
CI / runtimes (deno) (pull_request) Successful in 34s
test(runtimes): close the 1c exit-gate cells for health and compression on Deno and Bun
The CARD-22 gate audit found these runtime cells without tests:

- CARD-17 T1-T3 (booting, ok, degraded) existed only on Node. Add them
  on Deno and Bun. T1 goes through app.fetch, because serveDeno and
  serveBun boot before they bind. T2 and T3 go through a real listener
  and assert the response body, not only the status.
- CARD-16 T6 (encodings ['gzip'] with a br-only client gives identity)
  was missing on Deno and Bun.
- CARD-16 T8 on Deno and Bun lacked the handler-set content-encoding
  case and the 204 case.

A negative run of T6 against compression: true fails with 'encoded as
br', so the check can tell the two cases apart.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-30 10:26:30 -05:00

47 lines
1.9 KiB
TypeScript

// CARD-16 (#112) under the real Bun runtime: `Bun.serve` does not compress by itself, so every
// encoding here is core's, through `node:zlib`. Run with: npm run test:bun
import 'reflect-metadata';
import { test } from 'bun:test';
import { serveBun } from '../../src/bun.ts';
import { compressionApp } from '../fixtures/compression-app.ts';
import { checks, gzipOnlyRefusesBr, serverDoesNotCompress, ticksDuringGzip } from '../fixtures/compression-checks.ts';
for (const [name, run] of Object.entries(checks)) {
test(`compression on Bun.serve: ${name}`, async () => {
const server = await serveBun(compressionApp({ compression: true, etag: true }), { hostname: '127.0.0.1', port: 0 });
try {
await run(server.port);
} finally {
await server.close({ timeoutMs: 1000 });
}
});
}
test("compression on Bun.serve: T6 encodings ['gzip'] and a br-only client → identity", async () => {
const server = await serveBun(compressionApp({ compression: { encodings: ['gzip'] } }), { hostname: '127.0.0.1', port: 0 });
try {
await gzipOnlyRefusesBr(server.port);
} finally {
await server.close({ timeoutMs: 1000 });
}
});
// The documented Bun facts (CARD-16; `guides/runtimes.md`).
test('documented: Bun.serve does not compress by itself (core compression off → identity)', async () => {
const server = await serveBun(compressionApp(), { hostname: '127.0.0.1', port: 0 });
try {
await serverDoesNotCompress(server.port);
} finally {
await server.close({ timeoutMs: 1000 });
}
});
test("documented: node:zlib's async gzip is off the main thread on Bun", async () => {
const { ms, ticks } = await ticksDuringGzip();
if (ms < 50) throw new Error(`gzip took ${Math.round(ms)} ms — too fast to tell; enlarge the input`);
if (ticks < ms / 4) throw new Error(`only ${ticks} ticks in ${Math.round(ms)} ms: Bun blocked the loop — update the docs`);
});