@cosyte/vitest-config 0.1.6 → 0.1.8
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.
- package/CHANGELOG.md +37 -0
- package/README.md +13 -3
- package/mutate.d.ts +51 -0
- package/mutate.js +214 -20
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7bfe66e: `cosyte-mutate changed` mutates only the changed lines of each changed file, not the whole file. It
|
|
8
|
+
hands Stryker one mutation range per run of lines the change added or edited (`src/a.ts:3-5`), read
|
|
9
|
+
from the same zero-context diff `cosyte-ratchet` reads, so Stryker mutates only what lies wholly on
|
|
10
|
+
those lines. A mutant that reaches past them, such as the body of a function around an edited
|
|
11
|
+
statement, is not mutated, and the run counts those for each file. Lines only deleted add no
|
|
12
|
+
mutant. On a wide change to a large library, a run over whole files tested thousands of mutants on
|
|
13
|
+
lines the change never touched.
|
|
14
|
+
- 7bfe66e: `cosyte-mutate changed` exits 0 when the changed source files hold no mutant, for example a change to
|
|
15
|
+
types or comments only. It finds the files' mutants with Stryker's own instrumenter before Stryker
|
|
16
|
+
starts, and with none it says so, names the files, and writes the empty `changed.json` the ratchet
|
|
17
|
+
reads. It used to start Stryker, which refused the run because no test was related to the files,
|
|
18
|
+
and exited 2 as though its input could not be read. A changed file it cannot read or parse still
|
|
19
|
+
exits 2.
|
|
20
|
+
- Updated dependencies [7bfe66e]
|
|
21
|
+
- Updated dependencies [7bfe66e]
|
|
22
|
+
- Updated dependencies [2c29a9e]
|
|
23
|
+
- Updated dependencies [7bfe66e]
|
|
24
|
+
- @cosyte/script-utils@0.1.16
|
|
25
|
+
|
|
26
|
+
## 0.1.7
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 1858905: The package is now published with npm provenance: its `publishConfig` sets `"provenance": true`, so npm shows a provenance statement that ties each release's tarball to the source commit and the workflow run that built it.
|
|
31
|
+
- Updated dependencies [dbc3106]
|
|
32
|
+
- Updated dependencies [c8c11db]
|
|
33
|
+
- Updated dependencies [593195a]
|
|
34
|
+
- Updated dependencies [0c54a26]
|
|
35
|
+
- Updated dependencies [1858905]
|
|
36
|
+
- Updated dependencies [1ba9fe6]
|
|
37
|
+
- Updated dependencies [e447209]
|
|
38
|
+
- @cosyte/script-utils@0.1.15
|
|
39
|
+
|
|
3
40
|
## 0.1.6
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -143,9 +143,19 @@ pnpm exec cosyte-ratchet check --skip coverage --base origin/main
|
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
`full` writes `reports/mutation/mutation.json`, the report the floor file's mutation score is read
|
|
146
|
-
from. `changed`
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
from. `changed` mutates only the changed lines of each changed file: it hands Stryker one mutation
|
|
147
|
+
range per run of lines the change added or edited (`src/a.ts:3-5`), read from the same zero-context
|
|
148
|
+
diff the ratchet reads, and Stryker mutates only the mutants that lie wholly inside a range. A
|
|
149
|
+
mutant that spans a changed line and an unchanged one, such as the body of a function around an
|
|
150
|
+
edited statement or a two-line expression with one line edited, is not mutated in a changed run,
|
|
151
|
+
so the ratchet does not judge it on the pull request; the run prints how many there are for each
|
|
152
|
+
file. The full run still mutates every mutant, so those are tested on its schedule. Lines only
|
|
153
|
+
deleted add no mutant. `changed` writes `reports/mutation/changed.json` beside the full report, so
|
|
154
|
+
a run over a few files is never read as the whole package's score. A change with no changed source file starts no run: it writes an
|
|
155
|
+
empty report, so the ratchet can tell "ran, nothing to mutate" from "never ran", and exits 0. So
|
|
156
|
+
does a change with no mutant wholly on its changed lines (types, comments or deleted lines only):
|
|
157
|
+
before Stryker starts, `changed` finds the files' mutants with Stryker's own instrumenter, and with
|
|
158
|
+
none there it says so, writes the empty report, and exits 0. A changed file it cannot read or parse exits 2.
|
|
149
159
|
`cosyte-mutate` exits 0 when the run finished and 2 when it could not run; it does not judge the
|
|
150
160
|
score.
|
|
151
161
|
|
package/mutate.d.ts
CHANGED
|
@@ -89,6 +89,52 @@ export declare function loadChangeReader(
|
|
|
89
89
|
load?: (specifier: string) => Promise<unknown>,
|
|
90
90
|
): Promise<ChangeReader>;
|
|
91
91
|
|
|
92
|
+
/** A mutant as Stryker's instrumenter finds it; only the fields a run reads are declared. */
|
|
93
|
+
export interface FoundMutant {
|
|
94
|
+
fileName: string;
|
|
95
|
+
location: MutantSpan;
|
|
96
|
+
mutatorName?: string;
|
|
97
|
+
status?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Finds the mutants in files, each named by its absolute path, under a config's `mutator` options. */
|
|
101
|
+
export type MutantFinder = (
|
|
102
|
+
files: { name: string; content: string }[],
|
|
103
|
+
mutator?: Record<string, unknown>,
|
|
104
|
+
) => Promise<FoundMutant[]>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Load Stryker's instrumenter from beside the installed `@stryker-mutator/core`; rejects with
|
|
108
|
+
* `MutateUnreadable` when it cannot be loaded.
|
|
109
|
+
*/
|
|
110
|
+
export declare function loadMutantFinder(
|
|
111
|
+
resolveCore?: (specifier: string) => string,
|
|
112
|
+
): Promise<MutantFinder>;
|
|
113
|
+
|
|
114
|
+
/** A mutant's location as Stryker's instrumenter gives it: lines and columns from 0. */
|
|
115
|
+
export interface MutantSpan {
|
|
116
|
+
start: { line: number; column: number };
|
|
117
|
+
end: { line: number; column: number };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The changed lines (from 1) as runs of consecutive lines, in order: `[3, 5]` for 3, 4 and 5. */
|
|
121
|
+
export declare function lineRuns(lines: ReadonlySet<number>): [number, number][];
|
|
122
|
+
|
|
123
|
+
/** Changed lines as runs, `3-5, 9`; empty for no line. */
|
|
124
|
+
export declare function describeLines(lines: ReadonlySet<number>): string;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Plan a changed run over the changed lines of each file: one mutation range per run of changed
|
|
128
|
+
* lines (`file:3-5`), how many mutants lie wholly inside them of how many in the files, and a note
|
|
129
|
+
* per file that also counts the mutants reaching past its changed lines.
|
|
130
|
+
*/
|
|
131
|
+
export declare function planChangedLines(input: {
|
|
132
|
+
cwd: string;
|
|
133
|
+
files: readonly string[];
|
|
134
|
+
linesOf: (file: string) => ReadonlySet<number>;
|
|
135
|
+
mutants: readonly { fileName: string; location: MutantSpan }[];
|
|
136
|
+
}): { mutate: string[]; generated: number; total: number; notes: string[] };
|
|
137
|
+
|
|
92
138
|
/** Start StrykerJS with these options and wait for it to finish. */
|
|
93
139
|
export declare function runStryker(options: Record<string, unknown>): Promise<void>;
|
|
94
140
|
|
|
@@ -114,5 +160,10 @@ export declare function runMutate(opts: {
|
|
|
114
160
|
out: (text: string) => void;
|
|
115
161
|
err: (text: string) => void;
|
|
116
162
|
changes?: ChangeReader;
|
|
163
|
+
/**
|
|
164
|
+
* Finds the mutants in the changed files; a changed run with none wholly on changed lines starts
|
|
165
|
+
* no Stryker run.
|
|
166
|
+
*/
|
|
167
|
+
findMutants?: MutantFinder;
|
|
117
168
|
stryker?: (options: Record<string, unknown>) => Promise<void>;
|
|
118
169
|
}): Promise<number>;
|
package/mutate.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @cosyte/vitest-config/mutate
|
|
2
2
|
//
|
|
3
3
|
// THE TWO RUNS: `full` mutates everything the config names and writes the report the floor file's
|
|
4
|
-
// mutation score is read from; `changed` mutates only the source files a change
|
|
5
|
-
// base ref, and writes its report to a separate file, `changed.json` beside the
|
|
6
|
-
// over a few files can never be read as the package's score.
|
|
4
|
+
// mutation score is read from; `changed` mutates only the changed lines of the source files a change
|
|
5
|
+
// touched against a base ref, and writes its report to a separate file, `changed.json` beside the
|
|
6
|
+
// full one, so a run over a few files can never be read as the package's score.
|
|
7
7
|
//
|
|
8
8
|
// What a change touched is read from git by @cosyte/script-utils/changes, the same reading the
|
|
9
9
|
// ratchet judges changed lines with, so the two cannot disagree about which files a pull request
|
|
@@ -11,19 +11,24 @@
|
|
|
11
11
|
// that uses only the Vitest config installs nothing for it. A changed run with no changed source file starts no mutation run: it writes an empty
|
|
12
12
|
// report, so the ratchet can tell "ran, nothing to mutate" from "never ran", and exits 0.
|
|
13
13
|
//
|
|
14
|
-
// A
|
|
15
|
-
//
|
|
16
|
-
// the
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// Stryker keeps its incremental results, so a later run retests only what changed. A changed run
|
|
21
|
-
// reads neither variable, and a full run with neither set runs exactly as it always has.
|
|
14
|
+
// A changed run also starts nothing when its changed files hold no mutant at all, for example when
|
|
15
|
+
// a change touched only types or comments. Stryker refuses such a run (with no mutant, no test is
|
|
16
|
+
// related to the files, so its initial test run finds none), and that refusal is not an unreadable
|
|
17
|
+
// input. So before Stryker starts, the run reads each changed file and finds its mutants with
|
|
18
|
+
// Stryker's own instrumenter, the copy beside the installed @stryker-mutator/core; with none, it
|
|
19
|
+
// writes the same empty report and exits 0. A file it cannot read or parse still exits 2.
|
|
22
20
|
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
21
|
+
// ONLY THE CHANGED LINES. A run over whole files tests every mutant in them, which on a wide change
|
|
22
|
+
// to a large library took longer than the job's timeout, though a change is held to the mutants on
|
|
23
|
+
// its changed lines. So a changed run hands Stryker one mutation range per run of
|
|
24
|
+
// changed lines (`file:3-5`), read from the same zero-context diff the ratchet reads. Stryker mutates
|
|
25
|
+
// what lies wholly inside a range, so a mutant that reaches past the changed lines (the body of a
|
|
26
|
+
// function around an edited statement) is not mutated; the run counts those for each file. A file
|
|
27
|
+
// whose path holds a character a glob reads specially is mutated whole, since Stryker refuses a range
|
|
28
|
+
// on a glob. Lines only deleted, and a file only moved, leave no changed line, so they add no mutant.
|
|
25
29
|
|
|
26
|
-
import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
30
|
+
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
31
|
+
import { createRequire } from "node:module";
|
|
27
32
|
import { dirname, join, matchesGlob, relative, resolve, sep } from "node:path";
|
|
28
33
|
import { pathToFileURL } from "node:url";
|
|
29
34
|
|
|
@@ -56,9 +61,11 @@ const HELP = `cosyte-mutate: run StrykerJS with the shared config, over everythi
|
|
|
56
61
|
|
|
57
62
|
full mutates every file the config names and writes its JSON report where the config says
|
|
58
63
|
(reports/mutation/mutation.json with @cosyte/vitest-config/stryker).
|
|
59
|
-
changed mutates only the source files changed against the merge base of
|
|
60
|
-
edits not yet committed and untracked files)
|
|
61
|
-
|
|
64
|
+
changed mutates only the changed lines of the source files changed against the merge base of
|
|
65
|
+
<ref> and HEAD (with edits not yet committed and untracked files): each mutant that lies
|
|
66
|
+
wholly on changed lines. It writes changed.json beside the full
|
|
67
|
+
report. With no changed source file, or no mutant on a changed line (a change to types,
|
|
68
|
+
comments or deleted lines only), it writes an empty report and exits 0.
|
|
62
69
|
--config the Stryker config file, default ${DEFAULT_CONFIG}, relative to the working directory.
|
|
63
70
|
|
|
64
71
|
A full run reads two variables; with neither set it runs as above:
|
|
@@ -300,6 +307,164 @@ export async function loadChangeReader(load = (specifier) => import(specifier))
|
|
|
300
307
|
}
|
|
301
308
|
}
|
|
302
309
|
|
|
310
|
+
/**
|
|
311
|
+
* A logger that drops everything, for the instrumenter, whose own lines would only repeat ours.
|
|
312
|
+
* `isDebugEnabled` returns undefined, which the instrumenter reads as false.
|
|
313
|
+
*/
|
|
314
|
+
const SILENT = Object.freeze({
|
|
315
|
+
debug() {},
|
|
316
|
+
info() {},
|
|
317
|
+
warn() {},
|
|
318
|
+
isDebugEnabled() {},
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Load Stryker's instrumenter, the module Stryker itself finds mutants with, from beside the
|
|
323
|
+
* installed @stryker-mutator/core, so the two are always the same version. It is a dependency of
|
|
324
|
+
* that package, not of this one, so it is resolved from there.
|
|
325
|
+
*
|
|
326
|
+
* @param {(specifier: string) => string} [resolveCore] Resolves @stryker-mutator/core to a module
|
|
327
|
+
* URL; replaced in tests.
|
|
328
|
+
* @returns {Promise<(files: { name: string, content: string }[], mutator?: Record<string, unknown>) => Promise<{ fileName: string }[]>>}
|
|
329
|
+
* Finds the mutants in the files, each named by its absolute path, under the config's `mutator`
|
|
330
|
+
* options. An excluded mutator's mutants are still found, as Stryker finds them: ignored.
|
|
331
|
+
*/
|
|
332
|
+
export async function loadMutantFinder(
|
|
333
|
+
resolveCore = (specifier) => import.meta.resolve(specifier),
|
|
334
|
+
) {
|
|
335
|
+
let Instrumenter;
|
|
336
|
+
try {
|
|
337
|
+
const path = createRequire(resolveCore("@stryker-mutator/core")).resolve(
|
|
338
|
+
"@stryker-mutator/instrumenter",
|
|
339
|
+
);
|
|
340
|
+
({ Instrumenter } = await import(pathToFileURL(path).href));
|
|
341
|
+
} catch (cause) {
|
|
342
|
+
throw new MutateUnreadable(
|
|
343
|
+
"a changed run finds mutants with the instrumenter of @stryker-mutator/core, which could " +
|
|
344
|
+
`not be loaded (${cause.message})`,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
return async (files, mutator) => {
|
|
348
|
+
// Stryker's own defaults, under the config's `mutator` options, as Stryker passes them.
|
|
349
|
+
const options = {
|
|
350
|
+
ignorers: [],
|
|
351
|
+
plugins: null,
|
|
352
|
+
// Stryker disable next-line ArrayDeclaration: no mutator is named "Stryker was here", so excluding it changes nothing
|
|
353
|
+
excludedMutations: [],
|
|
354
|
+
...mutator,
|
|
355
|
+
};
|
|
356
|
+
const input = files.map(({ name, content }) => ({ name, content, mutate: true }));
|
|
357
|
+
const { mutants } = await new Instrumenter(SILENT).instrument(input, options);
|
|
358
|
+
return mutants;
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Read the changed files a run would mutate and find their mutants.
|
|
364
|
+
*
|
|
365
|
+
* @param {object} input The inputs.
|
|
366
|
+
* @param {string} input.cwd The directory Stryker runs in.
|
|
367
|
+
* @param {readonly string[]} input.files The files, relative to `cwd`.
|
|
368
|
+
* @param {Record<string, unknown>} [input.mutator] The config's `mutator` options.
|
|
369
|
+
* @param {Awaited<ReturnType<typeof loadMutantFinder>>} input.find Finds the mutants.
|
|
370
|
+
* @returns {Promise<{ fileName: string }[]>} The mutants.
|
|
371
|
+
*/
|
|
372
|
+
async function findChangedMutants({ cwd, files, mutator, find }) {
|
|
373
|
+
const read = files.map((file) => {
|
|
374
|
+
const name = resolve(cwd, file);
|
|
375
|
+
try {
|
|
376
|
+
return { name, content: readFileSync(name, "utf8") };
|
|
377
|
+
} catch (cause) {
|
|
378
|
+
throw new MutateUnreadable(`the changed file ${file} could not be read: ${cause.message}`);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
return await find(read, mutator);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @typedef {{ start: { line: number, column: number }, end: { line: number, column: number } }} MutantSpan
|
|
386
|
+
* A mutant's location as Stryker's instrumenter gives it: lines and columns from 0.
|
|
387
|
+
*/
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* The changed lines as runs of consecutive lines, in order: `[3, 5]` for lines 3, 4 and 5.
|
|
391
|
+
*
|
|
392
|
+
* @param {ReadonlySet<number>} lines Line numbers, from 1.
|
|
393
|
+
* @returns {[number, number][]} The first and last line of each run.
|
|
394
|
+
*/
|
|
395
|
+
export function lineRuns(lines) {
|
|
396
|
+
const runs = [];
|
|
397
|
+
for (const n of [...lines].sort((a, b) => a - b)) {
|
|
398
|
+
const last = runs[runs.length - 1];
|
|
399
|
+
if (last !== undefined && n === last[1] + 1) last[1] = n;
|
|
400
|
+
else runs.push([n, n]);
|
|
401
|
+
}
|
|
402
|
+
return runs;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Changed lines as a reader takes them in: runs of lines joined, `3-5, 9`.
|
|
407
|
+
*
|
|
408
|
+
* @param {ReadonlySet<number>} lines Line numbers, from 1.
|
|
409
|
+
* @returns {string} The runs, empty for no line.
|
|
410
|
+
*/
|
|
411
|
+
export function describeLines(lines) {
|
|
412
|
+
return lineRuns(lines)
|
|
413
|
+
.map(([a, b]) => (a === b ? `${a}` : `${a}-${b}`))
|
|
414
|
+
.join(", ");
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Plan a changed run over the changed lines of each file: one Stryker mutation range per run of
|
|
419
|
+
* changed lines (`file:3-5`), and a line for each file saying what it holds. Stryker mutates what
|
|
420
|
+
* lies wholly inside a range, so a mutant that spans a changed line and an unchanged one (a
|
|
421
|
+
* function's body around an edited statement) is not mutated; each file's line counts them.
|
|
422
|
+
*
|
|
423
|
+
* @param {object} input The inputs.
|
|
424
|
+
* @param {string} input.cwd The directory Stryker runs in.
|
|
425
|
+
* @param {readonly string[]} input.files The changed files to mutate, relative to `cwd`.
|
|
426
|
+
* @param {(file: string) => ReadonlySet<number>} input.linesOf A file's changed lines.
|
|
427
|
+
* @param {readonly { fileName: string, location: MutantSpan }[]} input.mutants The mutants found in
|
|
428
|
+
* the files, each with its absolute file name.
|
|
429
|
+
* @returns {{ mutate: string[], generated: number, total: number, notes: string[] }} The `mutate`
|
|
430
|
+
* patterns, how many mutants they hold of how many in the files, and one note per file.
|
|
431
|
+
*/
|
|
432
|
+
export function planChangedLines({ cwd, files, linesOf, mutants }) {
|
|
433
|
+
const plan = { mutate: [], generated: 0, total: 0, notes: [] };
|
|
434
|
+
for (const file of files) {
|
|
435
|
+
const name = resolve(cwd, file);
|
|
436
|
+
const spans = mutants.filter((m) => m.fileName === name).map((m) => m.location);
|
|
437
|
+
const lines = linesOf(file);
|
|
438
|
+
const where =
|
|
439
|
+
lines.size === 0
|
|
440
|
+
? `${file}, no added or changed line`
|
|
441
|
+
: `${file}, changed ${lines.size === 1 ? "line" : "lines"} ${describeLines(lines)}`;
|
|
442
|
+
plan.total += spans.length;
|
|
443
|
+
if (!/^[\w./-]+$/.test(file)) {
|
|
444
|
+
plan.mutate.push(file);
|
|
445
|
+
plan.generated += spans.length;
|
|
446
|
+
plan.notes.push(
|
|
447
|
+
`${where}: all ${spans.length} mutant(s), the whole file, as its path holds a character a glob reads`,
|
|
448
|
+
);
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
const runs = lineRuns(lines);
|
|
452
|
+
// Spans count lines from 0; runs from 1.
|
|
453
|
+
const inside = ({ start, end }) =>
|
|
454
|
+
runs.some(([a, b]) => start.line + 1 >= a && end.line + 1 <= b);
|
|
455
|
+
const touches = ({ start, end }) => [...lines].some((n) => n > start.line && n <= end.line + 1);
|
|
456
|
+
const held = spans.filter(inside).length;
|
|
457
|
+
const across = spans.filter((s) => touches(s) && !inside(s)).length;
|
|
458
|
+
plan.mutate.push(...runs.map(([a, b]) => `${file}:${a}-${b}`));
|
|
459
|
+
plan.generated += held;
|
|
460
|
+
plan.notes.push(
|
|
461
|
+
`${where}: ${held} of ${spans.length} mutant(s)` +
|
|
462
|
+
(across === 0 ? "" : `, and ${across} more that reach past the changed lines, not mutated`),
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
return plan;
|
|
466
|
+
}
|
|
467
|
+
|
|
303
468
|
/**
|
|
304
469
|
* Start StrykerJS with these options and wait for it to finish.
|
|
305
470
|
*
|
|
@@ -385,6 +550,8 @@ async function runFull({ cwd, env, out, stryker, configFile, config, name }) {
|
|
|
385
550
|
* @param {(opts: { base: string, cwd: string }) => { root: string, files: Map<string, Set<number>> }} [opts.changes]
|
|
386
551
|
* Reads what a change touched; replaced in tests. Left out, a changed run loads it from
|
|
387
552
|
* @cosyte/script-utils.
|
|
553
|
+
* @param {Awaited<ReturnType<typeof loadMutantFinder>>} [opts.findMutants] Finds the mutants in
|
|
554
|
+
* the changed files; replaced in tests. Left out, a changed run loads Stryker's instrumenter.
|
|
388
555
|
* @param {typeof runStryker} [opts.stryker] Starts Stryker; replaced in tests.
|
|
389
556
|
* @returns {Promise<number>} The exit code.
|
|
390
557
|
*/
|
|
@@ -395,6 +562,7 @@ export async function runMutate({
|
|
|
395
562
|
out,
|
|
396
563
|
err,
|
|
397
564
|
changes,
|
|
565
|
+
findMutants,
|
|
398
566
|
stryker = runStryker,
|
|
399
567
|
}) {
|
|
400
568
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
@@ -426,11 +594,37 @@ export async function runMutate({
|
|
|
426
594
|
);
|
|
427
595
|
return 0;
|
|
428
596
|
}
|
|
429
|
-
|
|
430
|
-
|
|
597
|
+
const mutants = await findChangedMutants({
|
|
598
|
+
cwd,
|
|
599
|
+
files,
|
|
600
|
+
mutator: config.mutator,
|
|
601
|
+
find: findMutants ?? (await loadMutantFinder()),
|
|
602
|
+
});
|
|
603
|
+
// The change names files from the repository root; the run names them from its directory.
|
|
604
|
+
const lines = new Map(
|
|
605
|
+
[...change.files].map(([file, set]) => [
|
|
606
|
+
relative(cwd, resolve(change.root, file)).split(sep).join("/"),
|
|
607
|
+
set,
|
|
608
|
+
]),
|
|
609
|
+
);
|
|
610
|
+
const plan = planChangedLines({ cwd, files, linesOf: (file) => lines.get(file), mutants });
|
|
611
|
+
if (plan.generated === 0) {
|
|
612
|
+
mkdirSync(dirname(resolve(cwd, report)), { recursive: true });
|
|
613
|
+
writeFileSync(resolve(cwd, report), emptyReport(cwd));
|
|
614
|
+
out(
|
|
615
|
+
`cosyte-mutate: no mutants were generated: no mutant in the ${files.length} changed source file(s) against ${options.base} lies wholly on changed lines (a change to types, comments or deleted lines only, for example):\n`,
|
|
616
|
+
);
|
|
617
|
+
for (const note of plan.notes) out(` ${note}\n`);
|
|
618
|
+
out(`cosyte-mutate: nothing to mutate. Wrote an empty ${report}.\n`);
|
|
619
|
+
return 0;
|
|
620
|
+
}
|
|
621
|
+
out(
|
|
622
|
+
`cosyte-mutate: mutating the changed lines of ${files.length} changed file(s) against ${options.base}: ${plan.generated} of the ${plan.total} mutant(s) in them, those wholly on changed lines:\n`,
|
|
623
|
+
);
|
|
624
|
+
for (const note of plan.notes) out(` ${note}\n`);
|
|
431
625
|
await stryker({
|
|
432
626
|
configFile,
|
|
433
|
-
mutate:
|
|
627
|
+
mutate: plan.mutate,
|
|
434
628
|
jsonReporter: { fileName: report },
|
|
435
629
|
htmlReporter: { fileName: htmlReportFor(report) },
|
|
436
630
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosyte/vitest-config",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Shared Vitest config (v8 coverage, per-directory >=90 gates) and StrykerJS mutation testing config for @cosyte/* packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitest",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"CHANGELOG.md"
|
|
59
59
|
],
|
|
60
60
|
"publishConfig": {
|
|
61
|
-
"access": "public"
|
|
61
|
+
"access": "public",
|
|
62
|
+
"provenance": true
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
65
|
"@stryker-mutator/core": "^10.0.0",
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
68
69
|
"vitest": "^4.0.0 || ^5.0.0",
|
|
69
70
|
"typescript": ">=5.0.0",
|
|
70
|
-
"@cosyte/script-utils": "^0.1.
|
|
71
|
+
"@cosyte/script-utils": "^0.1.16"
|
|
71
72
|
},
|
|
72
73
|
"peerDependenciesMeta": {
|
|
73
74
|
"@cosyte/script-utils": {
|
|
@@ -87,10 +88,10 @@
|
|
|
87
88
|
"@stryker-mutator/core": "10.1.1",
|
|
88
89
|
"@stryker-mutator/vitest-runner": "10.1.1",
|
|
89
90
|
"@vitest/coverage-v8": "5.1.0",
|
|
90
|
-
"vite": "8.
|
|
91
|
+
"vite": "8.4.0",
|
|
91
92
|
"vitest": "5.1.0",
|
|
92
93
|
"typescript": "5.9.3",
|
|
93
|
-
"@cosyte/script-utils": "^0.1.
|
|
94
|
+
"@cosyte/script-utils": "^0.1.16"
|
|
94
95
|
},
|
|
95
96
|
"scripts": {
|
|
96
97
|
"test": "vitest run --coverage"
|