重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
testing-codegen by biomejs/biome
npx skills add https://github.com/biomejs/biome --skill testing-codegen此技能用于测试、代码生成和准备贡献。涵盖使用 insta 的快照测试、代码生成命令和变更集创建。
just install-tools(安装 cargo-insta)corepack enable 和 pnpm install# 运行所有测试
cargo test
# 运行特定 crate 的测试
cd crates/biome_js_analyze
cargo test
# 运行特定测试
cargo test quick_test
# 显示测试输出(用于 dbg! 宏)
cargo test quick_test -- --show-output
# 使用 just 运行测试(使用 CI 测试运行器)
just test
# 使用 just 测试特定 crate
just test-crate biome_cli
开发过程中的快速迭代:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// 在 crates/biome_js_analyze/tests/quick_test.rs 中
// 修改 quick_test 函数:
const SOURCE: &str = r#"
const x = 1;
var y = 2;
"#;
let rule_filter = RuleFilter::Rule("nursery", "noVar");
运行:
just qt biome_js_analyze
重要提示: 在实现解析器或处理嵌入式语言时检查 AST 结构,请使用此方法代替构建完整的 Biome 二进制文件——它快得多!
// 在 crates/biome_html_parser/tests/quick_test.rs 中
// 修改 quick_test 函数:
#[test]
pub fn quick_test() {
let code = r#"<button on:click={handleClick}>Click</button>"#;
let source_type = HtmlFileSource::svelte();
let options = HtmlParserOptions::from(&source_type);
let root = parse_html(code, options);
let syntax = root.syntax();
dbg!(&syntax, root.diagnostics(), root.has_errors());
}
运行:
just qt biome_html_parser
dbg! 输出显示完整的 AST 树结构,帮助你理解:
HtmlAttribute 与 SvelteBindDirective)HtmlString(引号)还是 HtmlTextExpression(花括号)运行测试并生成快照:
cargo test
审查生成/变更的快照:
# 交互式审查(推荐)
cargo insta review
# 接受所有变更
cargo insta accept
# 拒绝所有变更
cargo insta reject
# 审查特定测试
cargo insta review --test-runner nextest
快照命令:
a - 接受快照r - 拒绝快照s - 跳过快照q - 退出# 按名称测试特定规则
just test-lintrule noVar
# 从分析器 crate 运行
cd crates/biome_js_analyze
cargo test
单文件测试 - 放置在与语言对应的 *_analyze crate 下的 tests/specs/{group}/{rule}/ 目录中:
tests/specs/nursery/noVar/
├── invalid.js # 应生成诊断信息的代码
├── valid.js # 不应生成诊断信息的代码
└── options.json # 可选:规则配置
文件和文件夹命名约定(重要):
在文件名或父文件夹名中使用 valid 或 invalid 来指示预期行为。
名称中包含 valid(但不包含 invalid)的文件/文件夹预期不产生诊断信息。
名称中包含 invalid 的文件/文件夹预期产生诊断信息。
在文件夹内测试用例时,使用 valid/invalid 作为文件夹名称的前缀,例如 validResolutionReact/invalidResolutionReact
tests/specs/nursery/noShadow/ ├── invalid.js # 应生成诊断信息 ├── valid.js # 不应生成诊断信息 ├── validResolutionReact/ └───── file.js # 应生成诊断信息 └── file2.js # 不应生成诊断信息
多个测试用例 - 使用包含数组的 .jsonc 文件:
// tests/specs/nursery/noVar/invalid.jsonc
[
"var x = 1;",
"var y = 2; var z = 3;",
"for (var i = 0; i < 10; i++) {}"
]
测试特定选项 - 创建 options.json:
{
"linter": {
"rules": {
"nursery": {
"noVar": {
"level": "error",
"options": {
"someOption": "value"
}
}
}
}
}
}
每个测试规范文件必须以一个顶层注释开头,声明其是否预期产生诊断信息。测试运行器(biome_test_utils 中的 assert_diagnostics_expectation_comment)强制执行此规则,如果违反规则则会 panic。
使用被测语言支持的任意注释语法编写标记文本。对于完全不支持注释的语言,请依赖文件/文件夹命名约定(valid/invalid)。
对于名称包含 "valid"(但不包含 "invalid")的文件:
注释是强制性的——如果缺失,测试会 panic。
对于名称包含 "invalid"(或其他名称)的文件:
注释强烈建议添加,并且在存在时也会被强制执行:如果注释说 should generate diagnostics 但没有出现诊断信息,测试会 panic。
测试运行器强制执行的规则:
| 文件名包含 | 注释存在? | 行为 |
|---|---|---|
| "valid"(非 "invalid") | should not generate diagnostics | 无诊断信息则通过 |
| "valid"(非 "invalid") | should generate diagnostics | 有诊断信息则通过 |
| "valid"(非 "invalid") | 缺失 | PANIC — 注释是强制性的 |
| "invalid" 或中性名称 | should not generate diagnostics | 无诊断信息则通过 |
| "invalid" 或中性名称 | should generate diagnostics | 有诊断信息则通过 |
| "invalid" 或中性名称 | 缺失 | 无强制执行(但仍建议添加) |
重要细节:
foo.js、bar.ts)不需要注释,因为它们不被运行器视为"有效的测试文件"。.snap、.json、.jsonc、.svelte、.vue、.astro、.html。修改分析器/lint 规则后(开发期间):
just gen-rules # 更新 *_analyze crate 中的规则注册
just gen-configuration # 更新配置模式
这些轻量级命令生成足够的代码以编译和测试而无错误。
完整的分析器代码生成(可选 — CI 自动修复会处理此操作):
just gen-analyzer
这是一个复合命令,运行 gen-rules、gen-configuration、gen-migrate、gen-bindings、lint-rules 和 format。你通常不需要在本地运行此命令——当你打开 PR 时,CI 自动修复作业会自动执行。
修改语法(.ungram 文件)后:
# 特定语言
just gen-grammar html
# 多种语言
just gen-grammar html css
# 所有语言
just gen-grammar
修改格式化器后:
just gen-formatter html
修改配置后:
just gen-bindings
生成 TypeScript 类型和 JSON 模式。
完整代码生成(很少需要):
just gen-all
提交前:
just ready
运行完整的代码生成 + 格式化 + lint(需要时间)。
或单独运行:
just f # 格式化 Rust 和 TOML
just l # Lint 代码
对于用户可见的变更(错误修复、新功能):
just new-changeset
这会提示输入:
@biomejs/biomepatch - 错误修复minor - 新功能major - 破坏性变更(需要针对 next 分支)变更集编写指南:
Fixed [#issue](link): ...[useConst](https://biomejs.dev/linter/rules/use-const/)示例变更集:
---
"@biomejs/biome": patch
---
Fixed [#1234](https://github.com/biomejs/biome/issues/1234): The rule [
`noVar`](https://biomejs.dev/linter/rules/no-var/) now correctly handles variables in for loops.
Biome now analyzes the scope of loop variables properly.
编辑变更集 - 文件创建在 .changeset/ 目录中,直接编辑它们。
测试文档注释中的代码示例:
just test-doc
在 Rust 代码中使用 dbg!() 宏:
fn some_function() -> &'static str {
let some_variable = "debug_value";
dbg!(&some_variable); // 在测试期间打印
some_variable
}
运行并显示输出:
cargo test test_name -- --show-output
valid.js 和 invalid.js 文件options.json 适用于该文件夹中的所有测试.jsonc 数组:用于脚本上下文中的多个快速测试用例(无导入/导出)just 命令(与 CI 匹配)#[ignore],使用 cargo test -- --ignored 运行just qt <package> 运行 quick_test 并检查 AST,而不是完整的 Biome 构建(快得多)有关一般的 Biome 开发技巧(字符串提取、借用检查器模式、遗留语法),请参阅 biome-developer 技能。
// 规则文件中的快照测试
#[test]
fn test_rule() {
assert_lint_rule! {
noVar,
invalid => [
"var x = 1;",
"var y = 2;",
],
valid => [
"const x = 1;",
"let y = 2;",
]
}
}
// 快速测试模式
#[test]
#[ignore] // 使用时取消注释
fn quick_test() {
const SOURCE: &str = r#"
var x = 1;
"#;
let rule_filter = RuleFilter::Rule("nursery", "noVar");
// 使用此配置运行测试
}
| 当你修改... | 开发期间运行... | 完整生成(可选,CI 执行) |
|---|---|---|
.ungram 语法文件 | just gen-grammar <lang> | — |
*_analyze 中的 Lint 规则 | just gen-rules && just gen-configuration | just gen-analyzer |
*_formatter 中的格式化器 | just gen-formatter <lang> | — |
| 配置类型 | just gen-bindings | — |
| 提交前 | just f && just l | — |
| 完整重建 | — | just gen-all(慢) |
CONTRIBUTING.md § Testingcrates/biome_analyze/CONTRIBUTING.md § TestingCONTRIBUTING.md § Changelog每周安装次数
41
仓库
GitHub Stars
24.0K
首次出现
2026年2月18日
安全审计
安装于
opencode41
github-copilot41
codex41
kimi-cli41
gemini-cli41
amp41
Use this skill for testing, code generation, and preparing contributions. Covers snapshot testing with insta, code generation commands, and changeset creation.
just install-tools (installs cargo-insta)corepack enable and pnpm install in repo root# Run all tests
cargo test
# Run tests for specific crate
cd crates/biome_js_analyze
cargo test
# Run specific test
cargo test quick_test
# Show test output (for dbg! macros)
cargo test quick_test -- --show-output
# Run tests with just (uses CI test runner)
just test
# Test specific crate with just
just test-crate biome_cli
Fast iteration during development:
// In crates/biome_js_analyze/tests/quick_test.rs
// Modify the quick_test function:
const SOURCE: &str = r#"
const x = 1;
var y = 2;
"#;
let rule_filter = RuleFilter::Rule("nursery", "noVar");
Run:
just qt biome_js_analyze
IMPORTANT: Use this instead of building full Biome binary for syntax inspection - it's much faster!
For inspecting AST structure when implementing parsers or working with embedded languages:
// In crates/biome_html_parser/tests/quick_test.rs
// Modify the quick_test function:
#[test]
pub fn quick_test() {
let code = r#"<button on:click={handleClick}>Click</button>"#;
let source_type = HtmlFileSource::svelte();
let options = HtmlParserOptions::from(&source_type);
let root = parse_html(code, options);
let syntax = root.syntax();
dbg!(&syntax, root.diagnostics(), root.has_errors());
}
Run:
just qt biome_html_parser
The dbg! output shows the full AST tree structure, helping you understand:
HtmlAttribute vs SvelteBindDirective)HtmlString (quotes) or HtmlTextExpression (curly braces)Run tests and generate snapshots:
cargo test
Review generated/changed snapshots:
# Interactive review (recommended)
cargo insta review
# Accept all changes
cargo insta accept
# Reject all changes
cargo insta reject
# Review for specific test
cargo insta review --test-runner nextest
Snapshot commands:
a - accept snapshotr - reject snapshots - skip snapshotq - quit# Test specific rule by name
just test-lintrule noVar
# Run from analyzer crate
cd crates/biome_js_analyze
cargo test
Single file tests - Place in tests/specs/{group}/{rule}/ under the appropriate *_analyze crate for the language:
tests/specs/nursery/noVar/
├── invalid.js # Code that should generate diagnostics
├── valid.js # Code that should not generate diagnostics
└── options.json # Optional: rule configuration
File and folder naming conventions (IMPORTANT):
Use valid or invalid in file names or parent folder names to indicate expected behaviour.
Files/folders with valid in the name (but not invalid) are expected to produce no diagnostics.
Files/folders with invalid in the name are expected to produce diagnostics.
When testing cases inside a folder, prefix the name of folder using valid/invalid e.g. validResolutionReact/invalidResolutionReact
Multiple test cases - Use .jsonc files with arrays:
// tests/specs/nursery/noVar/invalid.jsonc
[
"var x = 1;",
"var y = 2; var z = 3;",
"for (var i = 0; i < 10; i++) {}"
]
Test-specific options - Create options.json:
{
"linter": {
"rules": {
"nursery": {
"noVar": {
"level": "error",
"options": {
"someOption": "value"
}
}
}
}
}
}
Every test spec file must begin with a top-level comment declaring whether it expects diagnostics. The test runner (assert_diagnostics_expectation_comment in biome_test_utils) enforces this and panics if the rules are violated.
Write the marker text using whatever comment syntax the language under test supports. For languages that do not support comments at all, rely on the file/folder naming convention (valid/invalid) instead.
For files whose name contains "valid" (but not "invalid"):
The comment is mandatory — the test panics if it is absent.
For files whose name contains "invalid" (or other names):
The comment is strongly recommended and is also enforced when present: if the comment says should generate diagnostics but no diagnostics appear, the test panics.
Rules enforced by the test runner:
| File name contains | Comment present? | Behaviour |
|---|---|---|
| "valid" (not "invalid") | should not generate diagnostics | Passes if no diagnostics |
| "valid" (not "invalid") | should generate diagnostics | Passes if diagnostics present |
| "valid" (not "invalid") | absent | PANIC — comment is mandatory |
| "invalid" or neutral name | should not generate diagnostics | Passes if no diagnostics |
| "invalid" or neutral name | should generate diagnostics |
Important details:
foo.js, bar.ts) that don't contain "valid" or "invalid" in their name do not require a comment, since they are not considered "valid test files" by the runner..snap, .json, .jsonc, .svelte, .vue, .astro, .html.After modifying analyzers/lint rules (during development):
just gen-rules # Updates rule registrations in *_analyze crates
just gen-configuration # Updates configuration schemas
These lightweight commands generate enough code to compile and test without errors.
Full analyzer codegen (optional — CI autofix handles this):
just gen-analyzer
This is a composite command that runs gen-rules, gen-configuration, gen-migrate, gen-bindings, lint-rules, and format. You typically don't need to run this locally — the CI autofix job does it automatically when you open a PR.
After modifying grammar (.ungram files):
# Specific language
just gen-grammar html
# Multiple languages
just gen-grammar html css
# All languages
just gen-grammar
After modifying formatters:
just gen-formatter html
After modifying configuration:
just gen-bindings
Generates TypeScript types and JSON schema.
Full codegen (rarely needed):
just gen-all
Before committing:
just ready
Runs full codegen + format + lint (takes time).
Or run individually:
just f # Format Rust and TOML
just l # Lint code
For user-visible changes (bug fixes, new features):
just new-changeset
This prompts for:
@biomejs/biomepatch - Bug fixesminor - New featuresmajor - Breaking changes (requires targeting next branch)Changeset writing guidelines:
Fixed [#issue](link): ...[useConst](https://biomejs.dev/linter/rules/use-const/)Example changeset:
---
"@biomejs/biome": patch
---
Fixed [#1234](https://github.com/biomejs/biome/issues/1234): The rule [
`noVar`](https://biomejs.dev/linter/rules/no-var/) now correctly handles variables in for loops.
Biome now analyzes the scope of loop variables properly.
Edit changeset - Files created in .changeset/ directory, edit them directly.
Test code examples in documentation comments:
just test-doc
Use dbg!() macro in Rust code:
fn some_function() -> &'static str {
let some_variable = "debug_value";
dbg!(&some_variable); // Prints during test
some_variable
}
Run with output:
cargo test test_name -- --show-output
valid.js and invalid.js filesoptions.json applies to all tests in that folder.jsonc arrays: Use for multiple quick test cases in script context (no imports/exports)just commands when possible (matches CI)#[ignore] for slow tests, run with cargo test -- --ignoredFor general Biome development tips (string extraction, borrow checker patterns, legacy syntax), see the biome-developer skill.
// Snapshot test in rule file
#[test]
fn test_rule() {
assert_lint_rule! {
noVar,
invalid => [
"var x = 1;",
"var y = 2;",
],
valid => [
"const x = 1;",
"let y = 2;",
]
}
}
// Quick test pattern
#[test]
#[ignore] // Uncomment when using
fn quick_test() {
const SOURCE: &str = r#"
var x = 1;
"#;
let rule_filter = RuleFilter::Rule("nursery", "noVar");
// Test runs with this configuration
}
| When you modify... | Run during dev... | Full (optional, CI does this) |
|---|---|---|
.ungram grammar files | just gen-grammar <lang> | — |
Lint rules in *_analyze | just gen-rules && just gen-configuration | just gen-analyzer |
Formatter in *_formatter | just gen-formatter <lang> |
CONTRIBUTING.md § Testingcrates/biome_analyze/CONTRIBUTING.md § TestingCONTRIBUTING.md § ChangelogWeekly Installs
41
Repository
GitHub Stars
24.0K
First Seen
Feb 18, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode41
github-copilot41
codex41
kimi-cli41
gemini-cli41
amp41
测试策略完整指南:单元/集成/E2E测试金字塔与自动化实践
11,200 周安装
tests/specs/nursery/noShadow/ ├── invalid.js # should generate diagnostics ├── valid.js # should not generate diagnostics ├── validResolutionReact/ └───── file.js # should generate diagnostics └── file2.js # should not generate diagnostics
| Passes if diagnostics present |
| "invalid" or neutral name | absent | No enforcement (but add it anyway) |
just qt <package> to run quick_test and inspect AST, NOT full Biome builds (much faster)| — |
| Configuration types | just gen-bindings | — |
| Before committing | just f && just l | — |
| Full rebuild | — | just gen-all (slow) |