Skip to content

Instantly share code, notes, and snippets.

@up1
Last active April 22, 2026 06:43
Show Gist options
  • Select an option

  • Save up1/fddb054f3a6a1796f4f2d23acdf68626 to your computer and use it in GitHub Desktop.

Select an option

Save up1/fddb054f3a6a1796f4f2d23acdf68626 to your computer and use it in GitHub Desktop.
Testing with Bun
# Upgrade
$bun upgrade
$bun -version
1.3.13
# Create a new project
$bun init demo
✓ Select a project template: Blank
+ .gitignore
+ CLAUDE.md
+ .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc -> CLAUDE.md
+ index.ts
+ tsconfig.json (for editor autocomplete)
+ README.md
To get started, run:
bun run index.ts
bun install v1.3.13 (bf2e2cec)
+ @types/bun@1.3.12
+ typescript@5.9.3 (v6.0.3 available)
5 packages installed [2.91s]
# Run tests with isolation (fresh global per file)
$bun test --isolate ./tests
# Run tests in parallel across all CPU cores
$bun test --parallel ./tests
# Run tests in parallel with 8 workers
$bun test --parallel=8 ./tests
# In a GitHub Actions matrix with 3 jobs:
$bun test --shard=1/3
$bun test --shard=2/3
$bun test --shard=3/3
# Run tests affected by uncommitted changes (unstaged + staged + untracked)
$bun test --changed
# Run tests affected by changes since a specific commit, branch, or tag
$bun test --changed=HEAD~1
$bun test --changed=main
# Combine with --watch to re-filter on every restart
$bun test --changed --watch
await using view = new Bun.WebView({ width: 1024, height: 600 });
await view.navigate("https://seleniumbase.io/coffee/");
await view.click("div[data-test='Espresso']");
var textCart = await view.evaluate(
`document.querySelector("#app > ul > li:nth-child(2) > a").textContent`,
);
if (textCart !== "cart (1)") {
throw new Error(`Expected text to be "cart (1)", but got "${textCart}"`);
}
const png = await view.screenshot({ format: "jpeg", quality: 90 });
await Bun.write("page.jpg", png);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment