Loading...
Loading...
Guide for testing workflows and code generation commands in Biome. Use when running tests, managing snapshots, creating changesets, or generating code. Examples:<example>User needs to run snapshot tests for a lint rule</example><example>User wants to create a changeset for a PR</example><example>User needs to regenerate analyzer code after changes</example>
npx skill4agent add biomejs/biome testing-codegeninstajust install-toolscargo-instacorepack enablepnpm install# 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// 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");just qt biome_js_analyze// 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 = HtmlParseOptions::from(&source_type);
let root = parse_html(code, options);
let syntax = root.syntax();
dbg!(&syntax, root.diagnostics(), root.has_errors());
}just qt biome_html_parserdbg!HtmlAttributeSvelteBindDirectiveHtmlStringHtmlTextExpressioncargo test# 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 nextestarsq# Test specific rule by name
just test-lintrule noVar
# Run from analyzer crate
cd crates/biome_js_analyze
cargo testtests/specs/{group}/{rule}/tests/specs/nursery/noVar/
├── invalid.js # Code that triggers the rule
├── valid.js # Code that doesn't trigger
└── options.json # Optional: rule configuration.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"
}
}
}
}
}
}just gen-analyzer# Specific language
just gen-grammar html
# Multiple languages
just gen-grammar html css
# All languages
just gen-grammarjust gen-formatter htmljust gen-bindingsjust gen-alljust readyjust f # Format Rust and TOML
just l # Lint codejust new-changeset@biomejs/biomepatchminormajornextFixed [#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-docdbg!()fn some_function() -> &'static str {
let some_variable = "debug_value";
dbg!(&some_variable); // Prints during test
some_variable
}cargo test test_name -- --show-outputvalid.jsinvalid.jsoptions.json.jsoncjust#[ignore]cargo test -- --ignoredjust qt <package>inner_string_text()text_trimmed()let binding = value; binding.method()// 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... |
|---|---|
| |
Lint rules in | |
Formatter in | |
| Configuration types | |
| Before committing | |
| Full rebuild | |
CONTRIBUTING.mdcrates/biome_analyze/CONTRIBUTING.mdCONTRIBUTING.md