Bun

指南測試執行器

bun test 中更新快照

Bun 的測試執行器透過 .toMatchSnapshot() 支援 Jest 風格的快照測試。

snap.test.ts
import { test, expect } from "bun:test";

test("snapshot", () => {
  expect({ foo: "bar" }).toMatchSnapshot();
});

第一次執行此測試時,Bun 會在名為 __snapshots__ 的目錄中將快照檔案寫入磁碟,該目錄與測試檔案位於同一位置。

test
├── __snapshots__
│   └── snap.test.ts.snap
└── snap.test.ts

若要重新產生快照,請使用 --update-snapshots 標記。

bun test --update-snapshots
bun test v1.2.5 (9c68abdb)

test/snap.test.ts:
✓ snapshot [0.86ms]

 1 pass
 0 fail
 snapshots: +1 added # the snapshot was regenerated
 1 expect() calls
Ran 1 tests across 1 files. [102.00ms]

請參閱文件 > 測試執行器 > 快照以取得關於 Bun 測試執行器快照的完整文件。