File size: 2,055 Bytes
3201ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// @vitest-environment node
import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";

const repoRoot = path.resolve(
  path.dirname(fileURLToPath(import.meta.url)),
  "../..",
);

describe("Stryker mutation testing setup", () => {
  it("uses the Vitest runner for first-party TypeScript source", async () => {
    const config = (
      (await import("../../stryker.config.mjs")) as {
        default: {
          mutate: string[];
          testRunner: string;
          vitest: { configFile: string; related: boolean };
        };
      }
    ).default;

    expect(config).toMatchObject({
      testRunner: "vitest",
      vitest: {
        configFile: "vite.config.ts",
        related: true,
      },
    });
    expect(config.mutate).toContain("src/**/*.{ts,tsx}");
    expect(config.mutate).toContain("!src/**/*.{test,spec}.{ts,tsx}");
    expect(config.mutate).toContain("!src/**/*.d.ts");
    expect(config.mutate).toContain("!src/{fixtures,mocks,dev}/**");
  });

  it("provides full, incremental, and branch-diff commands", () => {
    const packageJson = JSON.parse(
      readFileSync(path.join(repoRoot, "package.json"), "utf8"),
    ) as {
      devDependencies: Record<string, string>;
      scripts: Record<string, string>;
    };

    expect(packageJson.scripts).toMatchObject({
      "test:mutation": "npm run make-i18n && stryker run",
      "test:mutation:diff":
        "npm run make-i18n && node scripts/stryker-diff.mjs",
      "test:mutation:incremental":
        "npm run make-i18n && stryker run --incremental",
    });
    expect(packageJson.devDependencies).toMatchObject({
      "@stryker-mutator/core": "9.6.1",
      "@stryker-mutator/vitest-runner": "9.6.1",
    });
  });

  it("ignores local mutation sandboxes and reports", () => {
    const gitignore = readFileSync(path.join(repoRoot, ".gitignore"), "utf8");

    expect(gitignore).toContain(".stryker-tmp/");
    expect(gitignore).toContain("reports/");
  });
});