@systemfsoftware/stryker-js-vitest-runner 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,51 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, inject } from "vitest";
2
+ //#region src/stryker-setup.ts
3
+ const globalNamespace = inject("globalNamespace");
4
+ const mutantActivation = inject("mutantActivation");
5
+ const mode = inject("mode");
6
+ const ns = globalThis[globalNamespace] ?? (globalThis[globalNamespace] = {});
7
+ ns.hitLimit = inject("hitLimit");
8
+ const isGreaterThanVitest4Point1 = inject("isGreaterThanVitest4Point1");
9
+ if (mode === "mutant") {
10
+ beforeAll(() => {
11
+ ns.hitCount = 0;
12
+ });
13
+ if (mutantActivation === "static") ns.activeMutant = inject("activeMutant");
14
+ else beforeAll(() => {
15
+ ns.activeMutant = inject("activeMutant");
16
+ });
17
+ if (isGreaterThanVitest4Point1) afterAll(({}, suite) => {
18
+ suite.meta.hitCount = ns.hitCount;
19
+ });
20
+ else afterAll(({ meta }) => {
21
+ meta.hitCount = ns.hitCount;
22
+ });
23
+ } else {
24
+ ns.activeMutant = void 0;
25
+ beforeEach(({ task }) => {
26
+ ns.currentTestId = toRawTestId(task);
27
+ });
28
+ afterEach(() => {
29
+ ns.currentTestId = void 0;
30
+ });
31
+ if (isGreaterThanVitest4Point1) afterAll(({}, suite) => {
32
+ suite.meta.mutantCoverage = ns.mutantCoverage;
33
+ });
34
+ else afterAll(({ meta }) => {
35
+ meta.mutantCoverage = ns.mutantCoverage;
36
+ });
37
+ }
38
+ function collectTestName({ name, suite }) {
39
+ const nameParts = [name];
40
+ let currentSuite = suite;
41
+ while (currentSuite) {
42
+ nameParts.unshift(currentSuite.name);
43
+ currentSuite = currentSuite.suite;
44
+ }
45
+ return nameParts.join(" ").trim();
46
+ }
47
+ function toRawTestId(test) {
48
+ return `${test.file?.filepath ?? "unknown.js"}#${collectTestName(test)}`;
49
+ }
50
+ //#endregion
51
+ export {};