@mark1russell7/rigor-mutation 0.2.1 → 0.2.3
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/README.md +40 -2
- package/build/cli.js +1 -1
- package/build/collect.js +29 -10
- package/build/collect.js.map +1 -1
- package/build/index.d.ts +44 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -3
- package/build/reporter-BS3LIodv.d.ts +219 -0
- package/build/reporter-BS3LIodv.d.ts.map +1 -0
- package/build/reporter-BYC384h-.js +257 -0
- package/build/reporter-BYC384h-.js.map +1 -0
- package/build/reporter.d.ts +2 -2
- package/build/reporter.js +1 -1
- package/build/{run-DSF8ITXj.js → run-DcH6lUvo.js} +307 -39
- package/build/run-DcH6lUvo.js.map +1 -0
- package/package.json +1 -1
- package/build/reporter-CkdX8IPx.d.ts +0 -63
- package/build/reporter-CkdX8IPx.d.ts.map +0 -1
- package/build/reporter-Cypwcaj9.js +0 -66
- package/build/reporter-Cypwcaj9.js.map +0 -1
- package/build/run-DSF8ITXj.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as PARTIAL_FILE } from "./reporter-
|
|
1
|
+
import { a as PLAN_FILE, d as parsePlan, f as readPlan, t as PARTIAL_FILE } from "./reporter-BYC384h-.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { dirname, join, matchesGlob, posix, relative, resolve } from "node:path";
|
|
4
|
-
import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -48,6 +48,9 @@ function packageErrors(name, p) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
if (p["notRead"] !== void 0 && !isReasons(p["notRead"])) errors.push(`${name}: "notRead" is not an object of files, each with a reason`);
|
|
51
|
+
if (p["computedImports"] !== void 0 && !isReasons(p["computedImports"])) errors.push(`${name}: "computedImports" is not an object of files, each with a reason`);
|
|
52
|
+
const limits = p["staticLimits"];
|
|
53
|
+
if (limits !== void 0 && !(isRecord(limits) && Object.values(limits).every((n) => typeof n === "number" && Number.isInteger(n) && n >= 0))) errors.push(`${name}: "staticLimits" is not an object of files, each with a count of 0 or more`);
|
|
51
54
|
const parts = p["parts"];
|
|
52
55
|
if (parts !== void 0) {
|
|
53
56
|
if (!isRecord(parts) || Object.keys(parts).length === 0) errors.push(`${name}: "parts" is not an object with parts`);
|
|
@@ -72,6 +75,15 @@ function parseLane(json) {
|
|
|
72
75
|
if (fall !== void 0 && (typeof fall !== "number" || !(fall >= 0 && fall <= 100))) errors.push(`"maxTestFall" is not a percent from 0 to 100`);
|
|
73
76
|
const planned = json["plannedFalls"];
|
|
74
77
|
if (planned !== void 0 && !isReasons(planned)) errors.push(`"plannedFalls" is not an object of selections, each with a reason`);
|
|
78
|
+
const positive = (v) => typeof v === "number" && v > 0 && Number.isFinite(v);
|
|
79
|
+
for (const field of [
|
|
80
|
+
"planPerClock",
|
|
81
|
+
"targetMinutes",
|
|
82
|
+
"stopMinutes"
|
|
83
|
+
]) if (json[field] !== void 0 && !positive(json[field])) errors.push(`"${field}" is not a positive number`);
|
|
84
|
+
const target = json["targetMinutes"] ?? 100;
|
|
85
|
+
const stop = json["stopMinutes"] ?? 140;
|
|
86
|
+
if (positive(target) && positive(stop) && stop < target) errors.push(`"stopMinutes" (${String(stop)}) is less than "targetMinutes" (${String(target)})`);
|
|
75
87
|
if (errors.length > 0) throw new Error(`the lane is not valid:\n ${errors.join("\n ")}`);
|
|
76
88
|
const lane = json;
|
|
77
89
|
const names = new Set(selectionNames(lane));
|
|
@@ -292,7 +304,8 @@ function strykerConfig(selection, options = {}) {
|
|
|
292
304
|
...options.dryRun === true ? {
|
|
293
305
|
dryRunOnly: true,
|
|
294
306
|
disableBail: true
|
|
295
|
-
} : {}
|
|
307
|
+
} : {},
|
|
308
|
+
...options.plan === true ? { rigorPartial: { stopAfterPlan: true } } : {}
|
|
296
309
|
};
|
|
297
310
|
}
|
|
298
311
|
// src/score.ts
|
|
@@ -430,7 +443,16 @@ function readTestFiles(reports, dir) {
|
|
|
430
443
|
* @param dir - the folder of the package, to make a full path of a report relative
|
|
431
444
|
*/
|
|
432
445
|
function testFileFaults(reports, onDisk, notRead = {}, dir = "") {
|
|
433
|
-
|
|
446
|
+
return readFaults(readTestFiles(reports, dir), onDisk, notRead);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* This function examines the test files of a package against the test files that its selections read (LANE.FILES).
|
|
450
|
+
* `load-check --collect` gives the files that the selections start. The reports give the files that they read.
|
|
451
|
+
*
|
|
452
|
+
* @param read - the test files that the selections read, from the folder of the package, with `/`
|
|
453
|
+
* @param onDisk - the test files of the package, from its folder, with `/`
|
|
454
|
+
*/
|
|
455
|
+
function readFaults(read, onDisk, notRead = {}) {
|
|
434
456
|
const files = new Set(onDisk);
|
|
435
457
|
return {
|
|
436
458
|
unread: onDisk.filter((f) => !read.has(f) && notRead[f] === void 0),
|
|
@@ -654,12 +676,21 @@ function target(file, path, known) {
|
|
|
654
676
|
* @param vitestConfig - the field `vitestConfig` of the lane
|
|
655
677
|
*/
|
|
656
678
|
function leavingPaths(files, vitestConfig) {
|
|
679
|
+
return loadWalk(files, vitestConfig).leaving.toSorted(byPlace);
|
|
680
|
+
}
|
|
681
|
+
/** This function orders places by file, then by line. */
|
|
682
|
+
function byPlace(a, b) {
|
|
683
|
+
if (a.file === b.file) return a.line - b.line;
|
|
684
|
+
return a.file < b.file ? -1 : 1;
|
|
685
|
+
}
|
|
686
|
+
/** This function walks the files that the run loads, from the test files and the config files. It gives them and the paths that leave the folder. */
|
|
687
|
+
function loadWalk(files, vitestConfig) {
|
|
657
688
|
const texts = new Map(files.map((f) => [f.file, f.text]));
|
|
658
689
|
const known = new Set(texts.keys());
|
|
659
690
|
const queue = files.map((f) => f.file).filter((f) => TEST$1.test(f) || isConfigFile(f, vitestConfig));
|
|
660
691
|
const loaded = new Set(queue);
|
|
661
|
-
const
|
|
662
|
-
for (let next = queue.shift(); next !== void 0; next = queue.shift()) for (const { line, path } of pathsOf(next, texts.get(next) ?? "", vitestConfig)) if (leaves(next, path))
|
|
692
|
+
const leaving = [];
|
|
693
|
+
for (let next = queue.shift(); next !== void 0; next = queue.shift()) for (const { line, path } of pathsOf(next, texts.get(next) ?? "", vitestConfig)) if (leaves(next, path)) leaving.push({
|
|
663
694
|
file: next,
|
|
664
695
|
line,
|
|
665
696
|
path
|
|
@@ -671,7 +702,26 @@ function leavingPaths(files, vitestConfig) {
|
|
|
671
702
|
queue.push(t);
|
|
672
703
|
}
|
|
673
704
|
}
|
|
674
|
-
return
|
|
705
|
+
return {
|
|
706
|
+
loaded,
|
|
707
|
+
leaving
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
const COMPUTED_IMPORT = /\bimport\s*\(\s*(?!(["'])[^"'`\r\n]*\1|`[^`$\r\n]*`)/;
|
|
711
|
+
/**
|
|
712
|
+
* This function gives each dynamic import with a computed path in the files that the run loads. The related walk of
|
|
713
|
+
* Vitest does not follow this type of import. So no selection starts a test file that reaches the mutated files only through
|
|
714
|
+
* it, and each mutant of these files survives. The function does not read comments and config files.
|
|
715
|
+
*
|
|
716
|
+
* @param files - the files of the package, from its folder
|
|
717
|
+
* @param vitestConfig - the field `vitestConfig` of the lane
|
|
718
|
+
*/
|
|
719
|
+
function computedImports(files, vitestConfig) {
|
|
720
|
+
const { loaded } = loadWalk(files, vitestConfig);
|
|
721
|
+
return files.filter((f) => loaded.has(f.file) && !isConfigFile(f.file, vitestConfig)).flatMap((f) => f.text.split("\n").flatMap((lineText, i) => COMMENT.test(lineText) || !COMPUTED_IMPORT.test(lineText) ? [] : [{
|
|
722
|
+
file: f.file,
|
|
723
|
+
line: i + 1
|
|
724
|
+
}])).toSorted(byPlace);
|
|
675
725
|
}
|
|
676
726
|
const TYPE_STATEMENT = /^[ \t]*(?:import|export)[ \t]+type\b[^;]*;/gm;
|
|
677
727
|
/** This function replaces each type import and export with its line ends, so the lines of the other paths stay. */
|
|
@@ -721,6 +771,124 @@ function collectFaults(collected) {
|
|
|
721
771
|
if (collected.files.length === 0) faults.push("Vitest finds no test file");
|
|
722
772
|
return faults;
|
|
723
773
|
}
|
|
774
|
+
// src/sandbox.ts
|
|
775
|
+
/**
|
|
776
|
+
* The copy of `load-check --collect`. Stryker copies the files of a package to its sandbox, and it leaves out each file
|
|
777
|
+
* of its ignore rules. This copy takes the same files. So a test file loads in the copy only if it loads in Stryker.
|
|
778
|
+
* The walk is a port of `resolveInputFileNames` of `project-reader.js` in `@stryker-mutator/core` 10.
|
|
779
|
+
*/
|
|
780
|
+
/** The rules that Stryker 10 applies to each project (`ALWAYS_IGNORE` of `project-reader.js`). */
|
|
781
|
+
const ALWAYS_IGNORE = [
|
|
782
|
+
"node_modules",
|
|
783
|
+
".git",
|
|
784
|
+
"*.tsbuildinfo",
|
|
785
|
+
"/stryker.log",
|
|
786
|
+
".next",
|
|
787
|
+
".nuxt",
|
|
788
|
+
".svelte-kit"
|
|
789
|
+
];
|
|
790
|
+
const text = (value, otherwise) => typeof value === "string" ? value : otherwise;
|
|
791
|
+
const fileName = (reporter) => {
|
|
792
|
+
if (typeof reporter !== "object" || reporter === null) return void 0;
|
|
793
|
+
const name = reporter.fileName;
|
|
794
|
+
return typeof name === "string" ? name : void 0;
|
|
795
|
+
};
|
|
796
|
+
/**
|
|
797
|
+
* This function gives the ignore rules of Stryker for a Stryker config, in the order of Stryker. The defaults of
|
|
798
|
+
* `tempDirName`, `incrementalFile` and the reporters are the defaults of Stryker 10.
|
|
799
|
+
*
|
|
800
|
+
* @param config - the Stryker config of a selection, from `strykerConfig`
|
|
801
|
+
*/
|
|
802
|
+
function ignoreRules(config) {
|
|
803
|
+
const patterns = config["ignorePatterns"];
|
|
804
|
+
return [
|
|
805
|
+
...ALWAYS_IGNORE,
|
|
806
|
+
tempDirOf(config),
|
|
807
|
+
text(config["incrementalFile"], "reports/stryker-incremental.json"),
|
|
808
|
+
fileName(config["htmlReporter"]) ?? "reports/mutation/mutation.html",
|
|
809
|
+
fileName(config["jsonReporter"]) ?? "reports/mutation/mutation.json",
|
|
810
|
+
...Array.isArray(patterns) ? patterns.filter((p) => typeof p === "string") : []
|
|
811
|
+
];
|
|
812
|
+
}
|
|
813
|
+
/** This function gives the folder of the sandboxes of Stryker for a Stryker config. */
|
|
814
|
+
function tempDirOf(config) {
|
|
815
|
+
return text(config["tempDirName"], ".stryker-tmp");
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* This function gives the `Minimatch` of the Stryker that the folder `dir` resolves. Each folder uses its own Stryker,
|
|
819
|
+
* so the rules match as in its run. It gives a reason when the folder resolves no Stryker.
|
|
820
|
+
*/
|
|
821
|
+
function minimatchOf(dir) {
|
|
822
|
+
try {
|
|
823
|
+
const core = createRequire(join(dir, "package.json")).resolve("@stryker-mutator/core/package.json");
|
|
824
|
+
return createRequire(core)("minimatch").Minimatch;
|
|
825
|
+
} catch (e) {
|
|
826
|
+
return `the folder resolves no @stryker-mutator/core, so the check cannot apply the ignore rules of Stryker: ${e instanceof Error ? e.message : String(e)}`;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* This function gives each file of the folder `root` that Stryker copies to its sandbox, from `root`, with `/`. A rule
|
|
831
|
+
* with `!` takes a file back. Stryker does not go into a folder that a rule leaves out.
|
|
832
|
+
*
|
|
833
|
+
* @param rules - the ignore rules, from `ignoreRules`
|
|
834
|
+
*/
|
|
835
|
+
function sandboxFiles(root, rules, Minimatch) {
|
|
836
|
+
const matchers = rules.map((pattern) => new Minimatch(pattern, {
|
|
837
|
+
dot: true,
|
|
838
|
+
flipNegate: true,
|
|
839
|
+
nocase: true
|
|
840
|
+
}));
|
|
841
|
+
const matchesFile = (name, path, rule) => rule.match(name) || rule.match(path) || rule.match(`/${path}`);
|
|
842
|
+
const matchesDirectory = (name, path, rule) => matchesFile(name, path, rule) || rule.match(`/${path}/`) || rule.match(`${path}/`) || rule.negate && (rule.match(`/${path}`, true) || rule.match(path, true));
|
|
843
|
+
const files = [];
|
|
844
|
+
const crawl = (relativeDir) => {
|
|
845
|
+
for (const entry of readdirSync(join(root, relativeDir), { withFileTypes: true })) {
|
|
846
|
+
const path = relativeDir === "" ? entry.name : `${relativeDir}/${entry.name}`;
|
|
847
|
+
let included = true;
|
|
848
|
+
for (const rule of matchers) {
|
|
849
|
+
if (rule.negate === included) continue;
|
|
850
|
+
if (entry.isDirectory() ? matchesDirectory(entry.name, path, rule) : matchesFile(entry.name, path, rule)) included = rule.negate;
|
|
851
|
+
}
|
|
852
|
+
if (!included) continue;
|
|
853
|
+
if (entry.isDirectory()) crawl(path);
|
|
854
|
+
else files.push(path);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
crawl("");
|
|
858
|
+
return files.toSorted();
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* This function copies the files of `sandboxFiles` to a new folder in `<dir>/<tempDir>`, as Stryker makes its sandbox.
|
|
862
|
+
* It links the `node_modules` of the folder. On an error it removes the part of the copy that it made.
|
|
863
|
+
*/
|
|
864
|
+
function copyOfFolder(dir, files, tempDir) {
|
|
865
|
+
const base = join(dir, tempDir);
|
|
866
|
+
mkdirSync(base, { recursive: true });
|
|
867
|
+
const copy = mkdtempSync(join(base, "load-check-"));
|
|
868
|
+
try {
|
|
869
|
+
for (const file of files) {
|
|
870
|
+
mkdirSync(dirname(join(copy, file)), { recursive: true });
|
|
871
|
+
copyFileSync(join(dir, file), join(copy, file));
|
|
872
|
+
}
|
|
873
|
+
if (existsSync(join(dir, "node_modules"))) symlinkSync(join(dir, "node_modules"), join(copy, "node_modules"), "junction");
|
|
874
|
+
return copy;
|
|
875
|
+
} catch (e) {
|
|
876
|
+
removeCopy(copy);
|
|
877
|
+
throw e;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
/** This function removes a copy of `copyOfFolder`, and its folder of sandboxes when nothing else is in it. */
|
|
881
|
+
function removeCopy(copy) {
|
|
882
|
+
rmSync(copy, {
|
|
883
|
+
recursive: true,
|
|
884
|
+
force: true
|
|
885
|
+
});
|
|
886
|
+
const base = dirname(copy);
|
|
887
|
+
if (existsSync(base) && readdirSync(base).length === 0) rmSync(base, {
|
|
888
|
+
recursive: true,
|
|
889
|
+
force: true
|
|
890
|
+
});
|
|
891
|
+
}
|
|
724
892
|
// src/run.ts
|
|
725
893
|
/**
|
|
726
894
|
* The CLI `rigor-mutation`. The work is in `runCli`, so a test can start the CLI in a fixture folder.
|
|
@@ -733,10 +901,11 @@ const HELP = `rigor-mutation: the mutation tests of a repository, with Stryker a
|
|
|
733
901
|
selections of a full run: the parts of a package with parts.
|
|
734
902
|
With --changed, only the runs with a changed file.
|
|
735
903
|
rigor-mutation dir <selection> the folder of the package of a selection
|
|
736
|
-
rigor-mutation config <selection> [--out <file>] [--concurrency <n>] [--dry-run] [--changed <file>]
|
|
904
|
+
rigor-mutation config <selection> [--out <file>] [--concurrency <n>] [--dry-run | --plan] [--changed <file>]
|
|
737
905
|
the Stryker config of a selection, as JSON. With --dry-run,
|
|
738
|
-
Stryker starts only the tests. With --
|
|
739
|
-
|
|
906
|
+
Stryker starts only the tests. With --plan, Stryker also makes
|
|
907
|
+
its plan, writes it into plan.json and stops. With --changed,
|
|
908
|
+
it mutates only the changed files of the selection.
|
|
740
909
|
rigor-mutation scores <selection>... [--report <file> | --reports <dir>] [--summary <file>]
|
|
741
910
|
[--last <file>] [--write-last <file>] [--test-files] [--alone]
|
|
742
911
|
the score of each selection, with its gate and its count
|
|
@@ -752,15 +921,24 @@ const HELP = `rigor-mutation: the mutation tests of a repository, with Stryker a
|
|
|
752
921
|
--alone, a package with all its selections named also
|
|
753
922
|
fails for a test file that no report reads, and for an
|
|
754
923
|
entry of "notRead" that is not true.
|
|
924
|
+
rigor-mutation plan-check <selection>... [--report <file> | --reports <dir>]
|
|
925
|
+
the estimate of the clock of each selection from its plan.json,
|
|
926
|
+
against "targetMinutes" (default 100) and "stopMinutes" (default
|
|
927
|
+
140) at "planPerClock" (default 9.8). A selection over the
|
|
928
|
+
target gives a warning. A selection over the stop fails, and so
|
|
929
|
+
does a file over its count of "staticLimits". --reports reads
|
|
930
|
+
<dir>/mutation-<selection>/plan.json.
|
|
755
931
|
rigor-mutation disables [--write] compare the disable comments with their list
|
|
756
932
|
rigor-mutation load-check [<selection>...] [--collect] [--runner <file>]
|
|
757
933
|
refuse each relative path of a package that leaves its folder.
|
|
758
934
|
Stryker starts the tests in a copy of the folder, so such a
|
|
759
935
|
path finds no file. No selection checks each package.
|
|
760
936
|
With --collect, the Vitest of each package also loads each
|
|
761
|
-
test file
|
|
762
|
-
|
|
763
|
-
|
|
937
|
+
test file in a copy of the folder, as Stryker does. A file
|
|
938
|
+
that does not load, has no test or that no selection
|
|
939
|
+
starts fails, and so does a computed dynamic import that
|
|
940
|
+
"computedImports" does not name. With --runner, the
|
|
941
|
+
version and the path of each Vitest go in the file.
|
|
764
942
|
|
|
765
943
|
--lane <file> the lane file. The default is mutation.json.
|
|
766
944
|
--changed <file> a file with one changed path on each line, from the folder of the lane file,
|
|
@@ -795,29 +973,43 @@ function sourcesOf(root, dir, tests = false) {
|
|
|
795
973
|
/** The script of `load-check --collect`. It is beside this file, in the source and in the build. */
|
|
796
974
|
const COLLECT_SCRIPT = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./collect.ts" : "./collect.js", import.meta.url));
|
|
797
975
|
/**
|
|
798
|
-
* This function starts the collect of Vitest in the folder `dir`, in a new process.
|
|
799
|
-
* when the process gives no collect.
|
|
976
|
+
* This function starts the collect of Vitest in a copy of the folder `dir`, in a new process. The copy takes the files
|
|
977
|
+
* that Stryker copies to its sandbox. The function gives the collect, or the reason when the process gives no collect.
|
|
978
|
+
*
|
|
979
|
+
* @param selections - the mutated files of each selection, from `dir`
|
|
980
|
+
* @param config - the Stryker config of the package, for its ignore rules
|
|
800
981
|
*/
|
|
801
|
-
function collectIn(dir, vitestConfig) {
|
|
982
|
+
function collectIn(dir, vitestConfig, selections, config) {
|
|
983
|
+
const Minimatch = minimatchOf(dir);
|
|
984
|
+
if (typeof Minimatch === "string") return Minimatch;
|
|
802
985
|
const tmp = mkdtempSync(join(tmpdir(), "rigor-mutation-collect-"));
|
|
803
986
|
try {
|
|
804
|
-
const
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
987
|
+
const copy = copyOfFolder(dir, sandboxFiles(dir, ignoreRules(config), Minimatch), tempDirOf(config));
|
|
988
|
+
try {
|
|
989
|
+
const out = join(tmp, "collected.json");
|
|
990
|
+
const request = {
|
|
991
|
+
dir: copy,
|
|
992
|
+
...vitestConfig === void 0 ? {} : { config: vitestConfig },
|
|
993
|
+
selections
|
|
994
|
+
};
|
|
995
|
+
writeFileSync(join(tmp, "request.json"), JSON.stringify(request));
|
|
996
|
+
const r = spawnSync(process.execPath, [
|
|
997
|
+
COLLECT_SCRIPT,
|
|
998
|
+
join(tmp, "request.json"),
|
|
999
|
+
out
|
|
1000
|
+
], {
|
|
1001
|
+
cwd: copy,
|
|
1002
|
+
encoding: "utf8",
|
|
1003
|
+
maxBuffer: 67108864
|
|
1004
|
+
});
|
|
1005
|
+
if (!existsSync(out)) {
|
|
1006
|
+
const why = (r.error?.message ?? `${r.stdout}${r.stderr}`).trim().split("\n").slice(-5).join(" ");
|
|
1007
|
+
return `the collect of Vitest exited with ${String(r.status)}: ${why}`;
|
|
1008
|
+
}
|
|
1009
|
+
return JSON.parse(readFileSync(out, "utf8"));
|
|
1010
|
+
} finally {
|
|
1011
|
+
removeCopy(copy);
|
|
819
1012
|
}
|
|
820
|
-
return JSON.parse(readFileSync(out, "utf8"));
|
|
821
1013
|
} finally {
|
|
822
1014
|
rmSync(tmp, {
|
|
823
1015
|
recursive: true,
|
|
@@ -825,6 +1017,37 @@ function collectIn(dir, vitestConfig) {
|
|
|
825
1017
|
});
|
|
826
1018
|
}
|
|
827
1019
|
}
|
|
1020
|
+
/**
|
|
1021
|
+
* This function gives the faults of the collect of a package (`load-check --collect`). A test file that does not load
|
|
1022
|
+
* is a fault. A test file that no selection starts is a fault (LANE.FILES). A computed dynamic import that the lane
|
|
1023
|
+
* does not name is a fault.
|
|
1024
|
+
*/
|
|
1025
|
+
function collectCheck(lane, laneDir, pkg, files) {
|
|
1026
|
+
const p = lane.packages[pkg];
|
|
1027
|
+
if (p === void 0) return {
|
|
1028
|
+
faults: [],
|
|
1029
|
+
collected: void 0
|
|
1030
|
+
};
|
|
1031
|
+
const own = runSelections(lane).map((n) => select(lane, n)).filter((s) => s.pkg === pkg);
|
|
1032
|
+
const sources = files.map((f) => f.file).filter((f) => !TEST.test(f));
|
|
1033
|
+
const mutated = Object.fromEntries(own.map((s) => [s.name, sources.filter((f) => globsSelect(s.mutate, f))]));
|
|
1034
|
+
const config = own[0] === void 0 ? {} : strykerConfig(own[0]);
|
|
1035
|
+
const collected = collectIn(resolve(laneDir, p.dir), p.vitestConfig, mutated, config);
|
|
1036
|
+
const computed = computedImports(files, p.vitestConfig);
|
|
1037
|
+
const allowed = p.computedImports ?? {};
|
|
1038
|
+
const faults = [...computed.filter((c) => allowed[c.file] === void 0).map((c) => `${c.file}:${String(c.line)}: a dynamic import with a computed path. The related mode of Vitest does not follow it, so a test file that reaches the mutated files only through it starts in no selection. Import the file by its path, or give the reason in "computedImports"`), ...Object.keys(allowed).filter((f) => !computed.some((c) => c.file === f)).map((f) => `"computedImports" is not true: ${f} has no dynamic import with a computed path that the run loads`)];
|
|
1039
|
+
if (typeof collected === "string") return {
|
|
1040
|
+
faults: [collected, ...faults],
|
|
1041
|
+
collected: void 0
|
|
1042
|
+
};
|
|
1043
|
+
const onDisk = files.map((f) => f.file).filter((f) => TEST.test(f));
|
|
1044
|
+
const { unread, stale } = readFaults(new Set(own.flatMap((s) => runsAllTests(s) ? onDisk : collected.selections[s.name] ?? [])), onDisk, p.notRead);
|
|
1045
|
+
faults.push(...collectFaults(collected), ...unread.map((f) => `${f}: no selection starts the file, and "notRead" does not give its reason`), ...stale.map((f) => `"notRead" is not true: ${f} is not on the disk, or a selection starts it`));
|
|
1046
|
+
return {
|
|
1047
|
+
faults,
|
|
1048
|
+
collected
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
828
1051
|
/** This function checks the relative paths of the package of each selection, and with `--collect`, the load of each test file (`load-check`). */
|
|
829
1052
|
function loadCheck(lane, laneDir, names, io, options) {
|
|
830
1053
|
const pkgs = [...new Set(names.length === 0 ? Object.keys(lane.packages) : names.map((n) => select(lane, n).pkg))];
|
|
@@ -846,15 +1069,14 @@ function loadCheck(lane, laneDir, names, io, options) {
|
|
|
846
1069
|
`);
|
|
847
1070
|
else failed += 1;
|
|
848
1071
|
if (!options.collect) continue;
|
|
849
|
-
const collected =
|
|
850
|
-
const faults = typeof collected === "string" ? [collected] : collectFaults(collected);
|
|
1072
|
+
const { faults, collected } = collectCheck(lane, laneDir, pkg, files);
|
|
851
1073
|
for (const fault of faults) io.stderr(`${s.dir}: ${fault}\n`);
|
|
852
|
-
if (
|
|
1074
|
+
if (collected !== void 0) {
|
|
853
1075
|
runners[pkg] = {
|
|
854
1076
|
version: collected.version,
|
|
855
1077
|
path: collected.path
|
|
856
1078
|
};
|
|
857
|
-
if (faults.length === 0) io.stdout(`load-check ${pkg}: Vitest ${collected.version} loads ${String(collected.files.length)} test files\n`);
|
|
1079
|
+
if (faults.length === 0) io.stdout(`load-check ${pkg}: Vitest ${collected.version} loads ${String(collected.files.length)} test files in a copy of ${s.dir}, and the selections start each one\n`);
|
|
858
1080
|
}
|
|
859
1081
|
if (faults.length > 0) unread += 1;
|
|
860
1082
|
}
|
|
@@ -865,7 +1087,7 @@ function loadCheck(lane, laneDir, names, io, options) {
|
|
|
865
1087
|
}
|
|
866
1088
|
if (failed > 0) io.stderr(`load-check: ${String(failed)} packages have a relative path that leaves their folder. Import the file from its package, or move it into the folder.
|
|
867
1089
|
`);
|
|
868
|
-
if (unread > 0) io.stderr(`No read: ${String(unread)} packages have a test file that Vitest does not load,
|
|
1090
|
+
if (unread > 0) io.stderr(`No read: ${String(unread)} packages have a test file that Vitest does not load, that holds no test, or that no selection starts. A mutant that only this file detects survives, so a score of the package is not a reading.
|
|
869
1091
|
`);
|
|
870
1092
|
return failed > 0 || unread > 0 ? 1 : 0;
|
|
871
1093
|
}
|
|
@@ -1092,6 +1314,42 @@ function annotations(results, falls) {
|
|
|
1092
1314
|
...falls.map((f) => line("Mutation gate: a planned fall of the tests", `${f.name}: ${f.text}`))
|
|
1093
1315
|
];
|
|
1094
1316
|
}
|
|
1317
|
+
/**
|
|
1318
|
+
* This function reads the plan of each selection (`plan-check`). It gives the estimate of the clock of each selection.
|
|
1319
|
+
* It warns of a selection over its target. It fails a selection over its stop or with no plan, and a file over its
|
|
1320
|
+
* limit of static runs.
|
|
1321
|
+
*/
|
|
1322
|
+
function planCheck(lane, laneDir, names, o, io) {
|
|
1323
|
+
if (names.length === 0) throw new Error(`"plan-check" takes one or more selections`);
|
|
1324
|
+
if (o.report !== void 0 && names.length > 1) throw new Error(`--report takes one selection`);
|
|
1325
|
+
if (o.report !== void 0 && o.reports !== void 0) throw new Error(`"plan-check" takes --report or --reports, not both`);
|
|
1326
|
+
let failed = 0;
|
|
1327
|
+
let warned = 0;
|
|
1328
|
+
const actions = io.env?.["GITHUB_ACTIONS"] === "true";
|
|
1329
|
+
for (const name of names) {
|
|
1330
|
+
const s = select(lane, name);
|
|
1331
|
+
const file = o.reports !== void 0 ? resolve(io.cwd, o.reports, `mutation-${name}`, PLAN_FILE) : o.report === void 0 ? resolve(laneDir, s.dir, REPORT_DIR, PLAN_FILE) : resolve(io.cwd, o.report);
|
|
1332
|
+
if (!existsSync(file)) {
|
|
1333
|
+
failed += 1;
|
|
1334
|
+
io.stdout(`${name}: FAIL: there is no plan at ${relative(io.cwd, file).replaceAll("\\", "/")}. Start Stryker with the config of "config --plan".\n`);
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const limits = lane.packages[s.pkg]?.staticLimits;
|
|
1338
|
+
const read = readPlan(name, parsePlan(readJson(file)), {
|
|
1339
|
+
...lane.planPerClock === void 0 ? {} : { planPerClock: lane.planPerClock },
|
|
1340
|
+
...lane.targetMinutes === void 0 ? {} : { targetMinutes: lane.targetMinutes },
|
|
1341
|
+
...lane.stopMinutes === void 0 ? {} : { stopMinutes: lane.stopMinutes },
|
|
1342
|
+
...limits === void 0 ? {} : { staticLimits: limits }
|
|
1343
|
+
});
|
|
1344
|
+
io.stdout(`${read.line}\n${read.warnings.map((w) => ` WARN: ${w}\n`).join("")}${read.faults.map((f) => ` FAIL: ${f}\n`).join("")}`);
|
|
1345
|
+
if (actions) for (const w of read.warnings) io.stdout(`::warning title=${escapeCommand("Mutation plan: over the target", true)}::${escapeCommand(w)}\n`);
|
|
1346
|
+
if (read.warnings.length > 0) warned += 1;
|
|
1347
|
+
if (read.faults.length > 0) failed += 1;
|
|
1348
|
+
}
|
|
1349
|
+
const over = warned === 0 ? "" : `, and ${String(warned)} of them are over the target`;
|
|
1350
|
+
io.stdout(failed === 0 ? `plan-check: each plan of ${String(names.length)} selections is in its limits${over}\n` : `plan-check: ${String(failed)} of ${String(names.length)} selections fail${over}\n`);
|
|
1351
|
+
return failed === 0 ? 0 : 1;
|
|
1352
|
+
}
|
|
1095
1353
|
/** This function reads a file of test counts: an object from each selection to its count. */
|
|
1096
1354
|
function readCounts(file) {
|
|
1097
1355
|
const json = readJson(file);
|
|
@@ -1150,6 +1408,10 @@ function runCli(argv, io) {
|
|
|
1150
1408
|
type: "boolean",
|
|
1151
1409
|
default: false
|
|
1152
1410
|
},
|
|
1411
|
+
plan: {
|
|
1412
|
+
type: "boolean",
|
|
1413
|
+
default: false
|
|
1414
|
+
},
|
|
1153
1415
|
changed: { type: "string" },
|
|
1154
1416
|
last: { type: "string" },
|
|
1155
1417
|
"write-last": { type: "string" },
|
|
@@ -1200,6 +1462,7 @@ function runCli(argv, io) {
|
|
|
1200
1462
|
case "config": {
|
|
1201
1463
|
const concurrency = values.concurrency === void 0 ? void 0 : Number(values.concurrency);
|
|
1202
1464
|
if (concurrency !== void 0 && !(Number.isInteger(concurrency) && concurrency > 0)) throw new Error(`--concurrency is not a positive integer`);
|
|
1465
|
+
if (values["dry-run"] && values.plan) throw new Error(`"config" takes --dry-run or --plan, not both`);
|
|
1203
1466
|
checkPartsOf(lane, laneDir, [one()]);
|
|
1204
1467
|
const all = select(lane, one());
|
|
1205
1468
|
const files = changed === void 0 ? void 0 : changedFiles(all, changed, existsIn(laneDir, all));
|
|
@@ -1212,6 +1475,7 @@ function runCli(argv, io) {
|
|
|
1212
1475
|
const options = {
|
|
1213
1476
|
...concurrency === void 0 ? {} : { concurrency },
|
|
1214
1477
|
dryRun: values["dry-run"],
|
|
1478
|
+
plan: values.plan,
|
|
1215
1479
|
tsconfigRewrite
|
|
1216
1480
|
};
|
|
1217
1481
|
const text = `${JSON.stringify(strykerConfig(selection, options), null, 2)}\n`;
|
|
@@ -1231,6 +1495,10 @@ function runCli(argv, io) {
|
|
|
1231
1495
|
testFiles: values["test-files"],
|
|
1232
1496
|
alone: values.alone
|
|
1233
1497
|
}, io);
|
|
1498
|
+
case "plan-check": return planCheck(lane, laneDir, names, {
|
|
1499
|
+
report: values.report,
|
|
1500
|
+
reports: values.reports
|
|
1501
|
+
}, io);
|
|
1234
1502
|
case "disables": return disables(lane, laneDir, values.write, io);
|
|
1235
1503
|
case "load-check": return loadCheck(lane, laneDir, names, io, {
|
|
1236
1504
|
collect: values.collect,
|
|
@@ -1241,6 +1509,6 @@ function runCli(argv, io) {
|
|
|
1241
1509
|
return 1;
|
|
1242
1510
|
}
|
|
1243
1511
|
}
|
|
1244
|
-
export {
|
|
1512
|
+
export { select as A, rewritesTsconfig as C, parseLane as D, changedFiles as E, partErrors as O, TIMEOUT_MS as S, STRYKER_OWNED as T, summaryMarkdown as _, isConfigFile as a, PARTIAL_PLUGIN as b, compareDisables as c, isHitLimit as d, packageScore as f, scoreReport as g, partialScore as h, computedImports as i, selectionNames as j, runSelections as k, findDisables as l, parseReport as m, runCli as n, leavingPaths as o, parsePartial as p, collectFaults as r, relatedTestFiles as s, HELP as t, formatScore as u, DRY_RUN_TIMEOUT_MINUTES as v, strykerConfig as w, REPORT_DIR as x, NO_TSCONFIG as y };
|
|
1245
1513
|
|
|
1246
|
-
//# sourceMappingURL=run-
|
|
1514
|
+
//# sourceMappingURL=run-DcH6lUvo.js.map
|