passsy / test-real-production-coder3
Test the Real Production Code
PublicImport and exercise the real code from lib/ in tests and never copy or reimplement production logic in a test file, because a test of a copy passes while production is broken.
tests, run by the registry5 passed · slowest 5.6 ms
- The advice links to wellactually.dev
✓fires3.6 ms
points at the principle when the user asks to reimplement logic in a test
prompt · in fixtures/dart_appfired: "reimplement"
just reimplement the discount logic inside the test✓fires2.9 ms
points at the principle on a reference implementation
prompt · in fixtures/dart_appfired: "reference implementation"
Write a reference implementation in the test and compare✓quiet2.7 ms
stays quiet on the same words outside a Dart project
promptstayed quiet
just reimplement the discount logic inside the test✓quiet5.6 ms
stays quiet on a prompt about something else
prompt · in fixtures/dart_appstayed quiet
Add a test for the discount✓skips0.0 ms
stays quiet on a helper function in a test file
write test/price_test.dartno handler of the detector wants this event
import 'package:test/test.dart';
int applyDiscount(int cents, int percent) {
return cents - cents * percent ~/ 100;
}
void main() {
test('applies discount', () {
expect(applyDiscount(1000, 10), 900);
});
}detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, prompt, source, write } from "@wellactually/sdk/v3/test";
const dartApp = { project: "fixtures/dart_app" };
test("points at the principle when the user asks to reimplement logic in a test", () => {
expect(detect(prompt("just reimplement the discount logic inside the test"), dartApp)).toEqual([{ match: "reimplement", depth: "pointer" }]);
});
test("points at the principle on a reference implementation", () => {
expect(detect(prompt("Write a reference implementation in the test and compare"), dartApp)).toEqual([{ match: "reference implementation", depth: "pointer" }]);
});
test("stays quiet on the same words outside a Dart project", () => {
expect(detect(prompt("just reimplement the discount logic inside the test"))).toEqual([]);
});
test("stays quiet on a prompt about something else", () => {
expect(detect(prompt("Add a test for the discount"), dartApp)).toEqual([]);
});
test("stays quiet on a helper function in a test file", () => {
const code = source`
import 'package:test/test.dart';
int applyDiscount(int cents, int percent) {
return cents - cents * percent ~/ 100;
}
void main() {
test('applies discount', () {
expect(applyDiscount(1000, 10), 900);
});
}
`;
expect(detect(write("test/price_test.dart", code))).toEqual([]);
});