一键导入
testing
Testing patterns, TDD workflow, TypeScript and Rust test conventions, sourcemap testing, E2E best practices, server cleanup for Verter
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Testing patterns, TDD workflow, TypeScript and Rust test conventions, sourcemap testing, E2E best practices, server cleanup for Verter
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Verter codebase architecture: Rust compiler modules, TypeScript packages, plugin system, LSP features, CSS analysis, MCP server, analysis types, key files index
Build dependency chains, rebuild sequences, profiling with MCP, and Analysis MCP server setup for Verter
Position encoding, span types, coordinate systems, path normalization tables for Verter's multi-layer architecture (OXC, Rust, LSP, FFI, VS Code)
Rust performance optimization patterns: batch operations, allocation hierarchy, object pooling, CodeTransform API for verter_core
| name | testing |
| description | Testing patterns, TDD workflow, TypeScript and Rust test conventions, sourcemap testing, E2E best practices, server cleanup for Verter |
IMPORTANT: After starting any dev server, preview server, or other long-running process for testing purposes, always kill it when done. This prevents stale servers from interfering with subsequent test runs (e.g., Playwright's reuseExistingServer: true will use a stale server serving old builds).
# After finishing with a server, kill it
# If started in background, use the process ID or port:
kill $(lsof -t -i:4173) # Unix
taskkill //F //PID <pid> # Windows
# Or if using pnpm/npm scripts, Ctrl+C the process
When running E2E tests or test suites where you need to inspect output, redirect output to a temp file first, then grep/read the file. This avoids re-running expensive builds and tests just to search for different patterns:
# Good: capture once, search multiple times
pnpm exec playwright test --project=preview 2>&1 | tee /tmp/e2e-output.log
# Then search as needed:
grep -i "fail\|error" /tmp/e2e-output.log
# Bad: re-running the full test suite each time you need different output
pnpm exec playwright test --project=preview 2>&1 | grep "fail"
pnpm exec playwright test --project=preview 2>&1 | grep "error" # wasteful re-run
Test locations: Unit tests are co-located as *.spec.ts next to source files. Type tests in packages/types/ use vitest --typecheck.
AI-generated tests: Add appropriate comments indicating AI assistance:
// For new test files, add a JSDoc at the top:
/**
* @ai-generated - This test file was generated with AI assistance.
* Brief description of what the tests cover.
*/
// For individual tests in existing files:
// @ai-generated - Tests X functionality with Y scenarios
it("does something", () => {
/* ... */
});
Sourcemap testing (see macros.map.spec.ts):
const { s, source, result } = processMacrosForSourcemap(code);
const map = s.generateMap({ source: "test.vue" });
Type testing best practices (packages/types/):
@ts-expect-error negative assertionany/unknown/never types from silently passing testsit("type is correctly inferred", () => {
type Result = SomeTypeHelper<Input>;
// Positive assertion - type matches expected
assertType<Result>({} as ExpectedType);
assertType<ExpectedType>({} as Result);
// @ts-expect-error - Result is not any/unknown/never
assertType<{ unrelated: true }>({} as Result);
});
When a Rust source file's inline #[cfg(test)] mod tests block exceeds ~400 lines, extract tests to a separate sibling file. Two patterns:
For standalone files (e.g., analysis.rs):
// In analysis.rs — replace the inline #[cfg(test)] mod tests { ... } block:
#[cfg(test)]
#[path = "analysis_tests.rs"]
mod analysis_tests;
For mod.rs files (e.g., ide/template/mod.rs):
// In mod.rs — loads tests.rs from the same directory:
#[cfg(test)]
mod tests;
The extracted file contains the module contents directly — use super::*;, helpers, and #[test] functions. No wrapping mod tests { } block.
cargo clippy --fix --allow-dirty --allow-staged --workspace -- -D warnings && cargo fmt --allcargo test --package verter_core --libThe parser builds a flat Vec<AstNode> arena with O(1) navigation:
pub struct TemplateAst {
nodes: Vec<AstNode>, // flat arena
root: RootNodeTemplate,
}
pub struct AstNode {
kind: AstNodeKind, // Element | Text | Comment | Interpolation
parent: Option<NodeId>, // O(1) parent lookup
index_in_parent: usize, // O(1) sibling lookup
}
ElementNode pre-computes metadata during parsing to avoid re-scanning in codegen:
tag_type: Element / Component / SlotOutlet / Templateprop_flag: Bitset of prop characteristics (has class, style, spread, etc.)children_flag: Bitset of children characteristics (has text, elements, v-if, etc.)children_mode: Enum for codegen branching (Empty, TextOnly, SingleElement, Mixed, etc.)v_condition, v_for, v_slot, v_once, v_refAll codegen tests must validate generated JS syntax:
let result = compile_sfc(source);
let tpl = result.template.unwrap();
// Parse generated code with OXC to verify valid JS
let parsed = oxc_parser::Parser::new(&alloc, &tpl.code, source_type).parse();
assert!(parsed.errors.is_empty(), "JS parse error: {:?}\n{}", parsed.errors, tpl.code);
packages/core/src/v5/process/script/plugins/ScriptPlugin interface using definePluginpackages/core/src/v5/process/script/plugins/index.tsvitest --typecheck)