writing-bundler-tests
This skill assists developers in configuring and executing tests for bundling, minification, and code transformation utilities.
Install
mkdir -p .claude/skills/writing-bundler-tests && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2596" && unzip -o skill.zip -d .claude/skills/writing-bundler-tests && rm skill.zipInstalls to .claude/skills/writing-bundler-tests
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Guides writing bundler tests using itBundled/expectBundled in test/bundler/. Use when creating or modifying bundler, transpiler, or code transformation tests.Key capabilities
- →Test Bun's bundler using itBundled()
- →Configure test files and entry points
- →Specify bundler options like format, target, and minification
- →Verify runtime behavior including stdout, stderr, and exit codes
- →Check for bundle errors and warnings
- →Perform post-bundle assertions on output files
How it works
The skill uses itBundled() to define bundler tests, specifying input files, bundler options, and expected runtime or bundle outcomes.
Inputs & outputs
When to use writing-bundler-tests
- →Writing bundler integration tests
- →Testing transpiler output for specific code transformations
- →Verifying minification and tree-shaking results
About this skill
Writing Bundler Tests
Bundler tests use itBundled() from test/bundler/expectBundled.ts to test Bun's bundler.
Basic Usage
import { describe } from "bun:test";
import { itBundled, dedent } from "./expectBundled";
describe("bundler", () => {
itBundled("category/TestName", {
files: {
"index.js": `console.log("hello");`,
},
run: {
stdout: "hello",
},
});
});
Test ID format: category/TestName (e.g., banner/CommentBanner, minify/Empty)
File Setup
{
files: {
"index.js": `console.log("test");`,
"lib.ts": `export const foo = 123;`,
"nested/file.js": `export default {};`,
},
entryPoints: ["index.js"], // defaults to first file
runtimeFiles: { // written AFTER bundling
"extra.js": `console.log("added later");`,
},
}
Bundler Options
{
outfile: "/out.js",
outdir: "/out",
format: "esm" | "cjs" | "iife",
target: "bun" | "browser" | "node",
// Minification
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
// Code manipulation
banner: "// copyright",
footer: "// end",
define: { "PROD": "true" },
external: ["lodash"],
// Advanced
sourceMap: "inline" | "external",
splitting: true,
treeShaking: true,
drop: ["console"],
}
Runtime Verification
{
run: {
stdout: "expected output", // exact match
stdout: /regex/, // pattern match
partialStdout: "contains this", // substring
stderr: "error output",
exitCode: 1,
env: { NODE_ENV: "production" },
runtime: "bun" | "node",
// Runtime errors
error: "ReferenceError: x is not defined",
},
}
Bundle Errors/Warnings
{
bundleErrors: {
"/file.js": ["error message 1", "error message 2"],
},
bundleWarnings: {
"/file.js": ["warning message"],
},
}
Dead Code Elimination (DCE)
Add markers in source code:
// KEEP - this should survive
const used = 1;
// REMOVE - this should be eliminated
const unused = 2;
{
dce: true,
dceKeepMarkerCount: 5, // expected KEEP markers
}
Capture Pattern
Verify exact transpilation with capture():
itBundled("string/Folding", {
files: {
"index.ts": `capture(\`\${1 + 1}\`);`,
},
capture: ['"2"'], // expected captured value
minifySyntax: true,
});
Post-Bundle Assertions
{
onAfterBundle(api) {
api.expectFile("out.js").toContain("console.log");
api.assertFileExists("out.js");
const content = api.readFile("out.js");
expect(content).toMatchSnapshot();
const values = api.captureFile("out.js");
expect(values).toEqual(["2"]);
},
}
Common Patterns
Simple output verification:
itBundled("banner/Comment", {
banner: "// copyright",
files: { "a.js": `console.log("Hello")` },
onAfterBundle(api) {
api.expectFile("out.js").toContain("// copyright");
},
});
Multi-file CJS/ESM interop:
itBundled("cjs/ImportSyntax", {
files: {
"entry.js": `import lib from './lib.cjs'; console.log(lib);`,
"lib.cjs": `exports.foo = 'bar';`,
},
run: { stdout: '{"foo":"bar"}' },
});
Error handling:
itBundled("edgecase/InvalidLoader", {
files: { "index.js": `...` },
bundleErrors: {
"index.js": ["Unsupported loader type"],
},
});
Test Organization
test/bundler/
├── bundler_banner.test.ts
├── bundler_string.test.ts
├── bundler_minify.test.ts
├── bundler_cjs.test.ts
├── bundler_edgecase.test.ts
├── bundler_splitting.test.ts
├── css/
├── transpiler/
└── expectBundled.ts
Running Tests
bun bd test test/bundler/bundler_banner.test.ts
BUN_BUNDLER_TEST_FILTER="banner/Comment" bun bd test bundler_banner.test.ts
BUN_BUNDLER_TEST_DEBUG=1 bun bd test bundler_minify.test.ts
Key Points
- Use
dedentfor readable multi-line code - File paths are relative (e.g.,
/index.js) - Use
capture()to verify exact transpilation results - Use
.toMatchSnapshot()for complex outputs - Pass array to
runfor multiple test scenarios
How it compares
This approach provides a structured, declarative way to test bundler behavior and output compared to manual bundling and inspection.
Compared to similar skills
writing-bundler-tests side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| writing-bundler-tests (this skill) | 2 | 7mo | Review | Intermediate |
| vitest | 41 | 6mo | No flags | Intermediate |
| svelte-expert | 11 | 9mo | No flags | Intermediate |
| implementing-cards | 7 | 2mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by oven-sh
View all by oven-sh →You might also like
vitest
antfu
Vitest fast unit testing framework powered by Vite with Jest-compatible API. Use when writing tests, mocking, configuring coverage, or working with test filtering and fixtures.
svelte-expert
Raudbjorn
Expert Svelte/SvelteKit development assistant for building components, utilities, and applications. Use when creating Svelte components, SvelteKit applications, implementing reactive patterns, handling state management, working with stores, transitions, animations, or any Svelte/SvelteKit development task. Includes comprehensive documentation access, code validation with svelte-autofixer, and playground link generation.
implementing-cards
bcollazo
Fill out the implementation of effects of different attacks, abilities, and trainer cards in this Pokemon TCG Pocket engine codebase.
zod-4
prowler-cloud
Zod 4 schema validation patterns. Trigger: When creating or updating Zod v4 schemas for validation/parsing (forms, request payloads, adapters), including v3 -> v4 migration patterns.
csharp-pro
sickn33
Write modern C# code with advanced features like records, pattern matching, and async/await. Optimizes .NET applications, implements enterprise patterns, and ensures comprehensive testing. Use PROACTIVELY for C# refactoring, performance optimization, or complex .NET solutions.
write-unit-tests
tldraw
Writing unit and integration tests for the tldraw SDK. Use when creating new tests, adding test coverage, or fixing failing tests in packages/editor or packages/tldraw. Covers Vitest patterns, TestEditor usage, and test file organization.