36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { detectMutations } from "../src/mutation.ts";
|
|
|
|
test("detectMutations reports mutations whose behaviour changes", async () => {
|
|
const report = await detectMutations({
|
|
baseline: (amount: number) => amount,
|
|
mutations: [
|
|
{ name: "invert sign", value: (amount: number) => -amount },
|
|
{ name: "drop amount", value: () => 0 },
|
|
],
|
|
exercise: (adjust) => adjust(7),
|
|
});
|
|
expect(report.killed).toEqual(["invert sign", "drop amount"]);
|
|
expect(report.survived).toEqual([]);
|
|
});
|
|
|
|
test("detectMutations fails with the names of surviving mutations", async () => {
|
|
await expect(
|
|
detectMutations({
|
|
baseline: (amount: number) => amount,
|
|
mutations: [{ name: "wrong implementation", value: (amount: number) => amount }],
|
|
exercise: (adjust) => adjust(7),
|
|
}),
|
|
).rejects.toThrow(/WRN-MUTATION-SURVIVED: wrong implementation/);
|
|
});
|
|
|
|
test("detectMutations accepts structured observations through an equivalence function", async () => {
|
|
const report = await detectMutations({
|
|
baseline: { status: 200 },
|
|
mutations: [{ name: "deny request", value: { status: 403 } }],
|
|
exercise: async (response) => ({ ...response, volatile: crypto.randomUUID() }),
|
|
equivalent: (left, right) => left.status === right.status,
|
|
});
|
|
expect(report.killed).toEqual(["deny request"]);
|
|
});
|