Tests should be well-structured with clear separation of concerns, proper grouping, and appropriate cleanup mechanisms. Separate different types of tests (performance vs functional), use descriptive test blocks, and ensure proper isolation to prevent side effects between tests.
Tests should be well-structured with clear separation of concerns, proper grouping, and appropriate cleanup mechanisms. Separate different types of tests (performance vs functional), use descriptive test blocks, and ensure proper isolation to prevent side effects between tests.
Key practices:
Example structure:
describe("doc builders", () => {
test("Invalid usage", () => {
// test invalid scenarios
});
test("Valid usage", () => {
// test valid scenarios
});
});
test("node version error", async () => {
const originalProcessVersion = process.version;
try {
Object.defineProperty(process, "version", { value: "v8.0.0" });
const result = await runPrettier("cli", ["--help"]);
// assertions
} finally {
Object.defineProperty(process, "version", {
value: originalProcessVersion
});
}
});
This approach prevents test pollution, improves maintainability, and ensures reliable test execution across different environments.
Enter the URL of a public GitHub repository