passsy / extend-existing-testsr3
Extend Existing Tests
PublicBefore creating a new test file or test helper class, check whether an existing one already covers that unit and extend it instead.
tests, run by the registry7 passed · slowest 4.1 ms
- The advice links to wellactually.dev
✓fires2.4 ms
fires when the agent creates a new test file
write test/price_test.dartfired: the file
void main() {
test('adds', () {});
}✓fires2.4 ms
asks the file question once for a new file full of classes
write test/clock_test.dartfired: the file
class ClockHarness {}
void main() {
test('adds', () {});
}✓quiet4.1 ms
stays quiet on a write over an existing test file
write test/price_test.dartstayed quiet
class PriceHarness {}
void main() {
test('adds', () {});
}✓skips0.0 ms
stays quiet on a new lib file
write lib/price.dartno handler of the detector wants this event
int price() => 1;
✓fires3.0 ms
fires when an edit adds a class to an existing test file
write test/auth_test.dart · wrote lines 1, 2, 3fired: line 1
class AuthHarness {}
void main() {
test('adds', () {});
}✓quiet2.5 ms
stays quiet on an edit inside a test without a new class
write test/auth_test.dart · wrote line 4stayed quiet
class AuthHarness {}
void main() {
test('adds', () {});
}✓skips0.0 ms
stays quiet on a class added to a lib file and on reads
write lib/auth.dart · wrote line 1no handler of the detector wants this event
class AuthService {}
int price() => 1;
read test/auth_test.dartno handler of the detector wants this event
class AuthHarness {}
void main() {
test('adds', () {});
}detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, read, source, write } from "@wellactually/sdk/v3/test";
const newTest = source`
void main() {
test('adds', () {});
}
`;
test("fires when the agent creates a new test file", () => {
expect(detect(write("test/price_test.dart", newTest, { isNew: true }))).toEqual([{}]);
});
test("asks the file question once for a new file full of classes", () => {
const code = `class ClockHarness {}\n\n${newTest}`;
expect(detect(write("test/clock_test.dart", code, { isNew: true }))).toEqual([{}]);
});
test("stays quiet on a write over an existing test file", () => {
expect(detect(write("test/price_test.dart", `class PriceHarness {}\n\n${newTest}`))).toEqual([]);
});
test("stays quiet on a new lib file", () => {
expect(detect(write("lib/price.dart", "int price() => 1;\n", { isNew: true }))).toEqual([]);
});
test("fires when an edit adds a class to an existing test file", () => {
const after = `class AuthHarness {}\n\n${newTest}`;
expect(detect(edit("test/auth_test.dart", after, { written: "class AuthHarness {}\n\n" }))).toEqual([{ line: 1 }]);
});
test("stays quiet on an edit inside a test without a new class", () => {
const after = `class AuthHarness {}\n\n${newTest}`;
expect(detect(edit("test/auth_test.dart", after, { written: " test('adds', () {});" }))).toEqual([]);
});
test("stays quiet on a class added to a lib file and on reads", () => {
const code = "class AuthService {}\nint price() => 1;\n";
expect(detect(edit("lib/auth.dart", code, { written: "class AuthService {}" }))).toEqual([]);
expect(detect(read("test/auth_test.dart", `class AuthHarness {}\n${newTest}`))).toEqual([]);
});