Skip to content

Use Bun native file IO and spawn in the tests #734

Closed as not planned
Closed as not planned

Description

@mathiasrw

Today

The tests run with Bun, but most of them use the Node APIs for files and processes:

  • fs.readFileSync and fs.writeFileSync: 322 calls in 38 test files.
  • spawnSync from child_process: test/js/halt.test.js, test/js/fix/691.test.js, test/js/fix/692.test.js and test/js/fix/700.test.js.

Change

Use the Bun native APIs in all test code:

  • await Bun.write(file, data) in place of fs.writeFileSync(file, data)
  • await Bun.file(file).text() in place of fs.readFileSync(file, 'utf8')
  • Bun.spawnSync([...]) in place of spawnSync(...)

fs stays for what Bun has no native API for, like mkdirSync, readdirSync, chmodSync and utimesSync.

Good to know

  • Bun.write and Bun.file().text() are async, so the tests that use them must be async.
  • Bun.spawnSync gives stdout as a buffer and the exit code as exitCode (not status).
  • New test code already uses the Bun APIs (like test/js/fix/703.test.js and test/js/fix/726.test.js).

Activity

  1. mathiasrw commented on Oct 23, 2026

    @mathiasrw
    OwnerAuthor

    The part about processes is done in #779: no test uses spawnSync any more. The CLI tests run with Bun's $, and fix/736 uses Bun.spawn.

    The part about files is dropped. The tests run in about a second, so Bun.write and Bun.file give no speed, and they are async, so each of the 400+ calls would need an await. Bun also has no native readdirSync, mkdirSync, chmodSync or utimesSync, so fs stays anyway. So the tests go the other way: fs with the sync functions is the one way to handle files in tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions