鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

writing-bundler-tests

提供对打包器、转译器及代码变换功能的测试支持,通过定义文件结构、运行时行为与构建选项来验证输出结果,确保代码转换逻辑正确并捕获预期的副作用,适用于构建流程中各类场景的精确断言。

测试与安全
访问 GitHub
文档Skills.MD
name
writing-bundler-tests
description
Guides writing bundler tests using itBundled/expectBundled in test/bundler/. Use when creating or modifying bundler, transpiler, or code transformation tests.

Writing Bundler Tests

Bundler tests use itBundled() from test/bundler/expectBundled.ts to test Bun's bundler.

Basic Usage

▼
typescript
复制代码
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

▼
typescript
复制代码
{ 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

▼
typescript
复制代码
{ 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

▼
typescript
复制代码
{ 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

▼
typescript
复制代码
{ bundleErrors: { "/file.js": ["error message 1", "error message 2"], }, bundleWarnings: { "/file.js": ["warning message"], }, }

Dead Code Elimination (DCE)

Add markers in source code:

▼
javascript
复制代码
// KEEP - this should survive const used = 1; // REMOVE - this should be eliminated const unused = 2;
▼
typescript
复制代码
{ dce: true, dceKeepMarkerCount: 5, // expected KEEP markers }

Capture Pattern

Verify exact transpilation with capture():

▼
typescript
复制代码
itBundled("string/Folding", { files: { "index.ts": `capture(\`\${1 + 1}\`);`, }, capture: ['"2"'], // expected captured value minifySyntax: true, });

Post-Bundle Assertions

▼
typescript
复制代码
{ 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:

▼
typescript
复制代码
itBundled("banner/Comment", { banner: "// copyright", files: { "a.js": `console.log("Hello")` }, onAfterBundle(api) { api.expectFile("out.js").toContain("// copyright"); }, });

Multi-file CJS/ESM interop:

▼
typescript
复制代码
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:

▼
typescript
复制代码
itBundled("edgecase/InvalidLoader", { files: { "index.js": `...` }, bundleErrors: { "index.js": ["Unsupported loader type"], }, });

Test Organization

▼
text
复制代码
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

▼
bash
复制代码
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 dedent for 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 run for multiple test scenarios
测试与安全

快捷安装

复制到终端去安装 Skill

npxskillsaddoven-sh/bun--skill"writing-bundler-tests"
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
debug
debug 是一个系统化定位软件缺陷根因的技能,适用于用户报告 'fix'、'broken'、'error' 等问题或测试意外失败时。它通过可验证的假设、最小复现、因果链分析和回归测试,确保在修复前准确定位根本原因。
webapp-testing
提供本地 Web 应用的端到端测试能力,支持页面导航、元素交互、表单填写、动态等待、断言验证、截图捕获、浏览器日志收集及网络请求拦截,适用于前端功能验证与 UI 行为调试。
tdd-process
严格遵循测试驱动开发的红绿重构循环,强制执行先写测试、失败要有意义、实现最小化、验证全覆盖的全流程,确保每次代码变更都由可执行的测试用例驱动并经编译、检查与全量验证确认。
smoke-test
自动化创建 Mastra 项目并完成 Studio 全流程冒烟测试,涵盖项目初始化、环境配置、本地服务启动及 Chrome 浏览器中对 Agents、Tools、Workflows、Scorers 等核心模块的功能验证与截图记录。
property-based-testing
通过生成随机输入验证代码在各类边界条件下的行为一致性,适用于序列化、解析、归一化及纯函数等场景,能有效发现隐含缺陷并提升测试覆盖率,尤其适合需要高可靠性的算法与智能合约验证。