import { gc as bunGC, unsafe } from "bun"; import { heapStats } from "bun:jsc"; import path from "path"; import fs from "fs"; import os from "os"; export const bunEnv: any = { ...process.env, GITHUB_ACTIONS: "false", BUN_DEBUG_QUIET_LOGS: "1", NO_COLOR: "1", FORCE_COLOR: undefined, }; export function bunExe() { return process.execPath; } export function gc(force = true) { bunGC(force); } /** * The garbage collector is not 100% deterministic * * We want to assert that SOME of the objects are collected * But we cannot reliably assert that ALL of them are collected * * Therefore, we check that the count is less than or equal to the expected count * * @param type * @param count * @param maxWait * @returns */ export async function expectMaxObjectTypeCount( expect: typeof import("bun:test").expect, type: string, count: number, maxWait = 1000, ) { gc(); if (heapStats().objectTypeCounts[type] <= count) return; gc(true); for (const wait = 20; maxWait > 0; maxWait -= wait) { if (heapStats().objectTypeCounts[type] <= count) break; await new Promise(resolve => setTimeout(resolve, wait)); gc(); } expect(heapStats().objectTypeCounts[type]).toBeLessThanOrEqual(count); } // we must ensure that finalizers are run // so that the reference-counting logic is exercised export function gcTick(trace = false) { trace && console.trace(""); // console.trace("hello"); gc(); return new Promise(resolve => setTimeout(resolve, 0)); } export function withoutAggressiveGC(block: () => unknown) { if (!unsafe.gcAggressionLevel) return block(); const origGC = unsafe.gcAggressionLevel(); unsafe.gcAggressionLevel(0); try { return block(); } finally { unsafe.gcAggressionLevel(origGC); } } export function hideFromStackTrace(block: CallableFunction) { Object.defineProperty(block, "name", { value: "::bunternal::", configurable: true, enumerable: true, writable: true, }); } export function tempDirWithFiles(basename: string, files: Record) { const dir = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), basename + "_")); for (const [name, contents] of Object.entries(files)) { fs.writeFileSync(path.join(dir, name), contents); } return dir; } export function bunRun(file: string, env?: Record) { const result = Bun.spawnSync([bunExe(), file], { cwd: path.dirname(file), env: { ...bunEnv, NODE_ENV: undefined, ...env, }, }); if (!result.success) throw new Error(result.stderr.toString("utf8")); return { stdout: result.stdout.toString("utf8").trim(), stderr: result.stderr.toString("utf8").trim(), }; } export function bunTest(file: string, env?: Record) { const result = Bun.spawnSync([bunExe(), "test", path.basename(file)], { cwd: path.dirname(file), env: { ...bunEnv, NODE_ENV: undefined, ...env, }, }); if (!result.success) throw new Error(result.stderr.toString("utf8")); return { stdout: result.stdout.toString("utf8").trim(), stderr: result.stderr.toString("utf8").trim(), }; } export function bunRunAsScript(dir: string, script: string, env?: Record) { const result = Bun.spawnSync([bunExe(), `run`, `${script}`], { cwd: dir, env: { ...bunEnv, NODE_ENV: undefined, ...env, }, }); if (!result.success) throw new Error(result.stderr.toString("utf8")); return { stdout: result.stdout.toString("utf8").trim(), stderr: result.stderr.toString("utf8").trim(), }; } ts Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-06-20Group zsh completion options by type (#194)Gravatar Alexander Kuznetsov 1-28/+16
2022-06-17Import most of `MessageEvent` from WebKitGravatar Jarred Sumner 18-12/+1410
2022-06-15some more testsGravatar Jarred Sumner 2-10/+62
2022-06-15Update WebKitGravatar Jarred Sumner 1-0/+0
2022-06-15[web standards] Add `CloseEvent` from WebKitGravatar Jarred Sumner 9-6/+636
2022-06-15Fix lazy loading internal streamsGravatar Jarred Sumner 13-360/+424
2022-06-15direct streams mostly workjarred/directGravatar Jarred Sumner 26-1167/+1782
2022-06-15wip direct streamsGravatar Jarred Sumner 24-398/+2276
2022-06-12ArrayBufferSink works and it's good.Gravatar Jarred Sumner 26-170/+2054
2022-06-12Fix build issueGravatar Jarred Sumner 2-0/+6
2022-06-12Delete broken submoduleGravatar Jarred Sumner 1-0/+0
2022-06-10Update Dockerfile.baseGravatar Jarred Sumner 1-1/+1
2022-06-10Update WebKitGravatar Jarred Sumner 1-0/+0
2022-06-10Update event_loop.zigGravatar Jarred Sumner 1-0/+1
2022-06-10Missing errno on linuxGravatar Jarred Sumner 1-3/+1
2022-06-10Update js_parser.zigGravatar Jarred Sumner 1-21/+200
2022-06-10Update MakefileGravatar Jarred Sumner 1-4/+4
2022-06-10wip fix linux buildGravatar Jarred Sumner 1-9/+11
2022-06-10Don't show generic crash info when given invalid bunfig.tomlGravatar Jarred Sumner 1-0/+4
2022-06-10Update logger.zigGravatar Jarred Sumner 1-0/+4
2022-06-10Show tracingGravatar Jarred Sumner 1-1/+1
2022-06-10Update bunfig.zigGravatar Jarred Sumner 1-0/+1
2022-06-10Update jest.zigGravatar Jarred Sumner 1-6/+9
2022-06-09Update bun.d.tsGravatar Jarred Sumner 1-2/+5
2022-06-09Add typesGravatar Jarred Sumner 1-2/+32
2022-06-09`new Response(stream).arrayBuffer()` + 3 moreGravatar Jarred Sumner 16-39/+478
2022-06-09fix some memory leaks with stringsGravatar Jarred Sumner 4-28/+45
2022-06-09Support console.log(myBigInt)Gravatar Jarred Sumner 1-1/+6
2022-06-09Fix defaultProps with JSX optimizationGravatar Jarred Sumner 6-34/+73
2022-06-09small perf improvements to encodingGravatar Jarred Sumner 1-43/+37
2022-06-07Update event_loop.zigGravatar Jarred Sumner 1-1/+2