@godzillaba/mutest 1.2.1 → 1.3.2

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.
Files changed (2) hide show
  1. package/index.ts +20 -17
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env -S npx tsx
2
2
  import { execFile as execFileCb } from "child_process";
3
- import { readFile, cp, rm } from "fs/promises";
3
+ import { readFile, writeFile, cp, rm } from "fs/promises";
4
4
  import { promisify } from "util";
5
5
 
6
6
  const execFile = promisify(execFileCb);
@@ -21,7 +21,7 @@ async function setupWorkers(workerCount: number): Promise<string> {
21
21
  const dir = `${root}/worker-${i}`;
22
22
  return execFile("bash", [
23
23
  "-c",
24
- `mkdir -p "${dir}" && git ls-files -z | tar -c --null -T - | tar -x -C "${dir}" && ln -s ${cwd}/node_modules ${dir}/node_modules && ln -s ${cwd}/lib ${dir}/lib`,
24
+ `mkdir -p "${dir}" && git ls-files -z --cached --others --exclude-standard | tar -c --null -T - | tar -x -C "${dir}" && ln -s ${cwd}/node_modules ${dir}/node_modules && ln -s ${cwd}/lib ${dir}/lib`,
25
25
  ]);
26
26
  });
27
27
  await Promise.all(workers);
@@ -65,8 +65,8 @@ async function processMutants(
65
65
  for (let i = 0; i < mutants.length; i++)
66
66
  queues[i % workerCount].push(mutants[i]);
67
67
 
68
- let killed = 0;
69
- let survived = 0;
68
+ let done = 0;
69
+ const survivors: Mutant[] = [];
70
70
 
71
71
  const workers = queues.map(async (queue, workerIdx) => {
72
72
  const workerDir = `${tempDir}/worker-${workerIdx}`;
@@ -74,26 +74,29 @@ async function processMutants(
74
74
  await cp(`gambit_out/${mutant.name}`, `${workerDir}/${mutant.original}`);
75
75
  try {
76
76
  await execFile("forge", ["test", "--optimize", "false", "--root", workerDir]);
77
- survived++;
78
- console.log(
79
- `[SURVIVED] #${mutant.id} ${mutant.description} ${mutant.original}`,
80
- );
81
- } catch {
82
- killed++;
83
- console.log(
84
- `[KILLED] #${mutant.id} ${mutant.description} ${mutant.original}`,
85
- );
86
- }
77
+ survivors.push(mutant);
78
+ } catch {}
79
+ done++;
80
+ process.stdout.write(`\r${done}/${mutants.length} tested`);
87
81
  }
88
82
  });
89
83
 
90
84
  await Promise.all(workers);
91
- console.log(
92
- `\n${killed + survived} mutants tested: ${killed} killed, ${survived} survived`,
93
- );
85
+ const killed = mutants.length - survivors.length;
86
+ console.log(`\n\n${killed} killed, ${survivors.length} survived`);
87
+ await writeFile("gambit_out/survivors.json", JSON.stringify(survivors, null, 2) + "\n");
88
+ console.log(`Wrote survivors.json`);
94
89
  }
95
90
 
96
91
  async function loadExistingMutants(): Promise<Mutant[]> {
92
+ try {
93
+ const raw = await readFile("gambit_out/survivors.json", "utf-8");
94
+ const survivors: Mutant[] = JSON.parse(raw);
95
+ if (survivors.length > 0) {
96
+ console.log(`Found survivors.json, re-testing ${survivors.length} survivors...`);
97
+ return survivors;
98
+ }
99
+ } catch {}
97
100
  const raw = await readFile("gambit_out/gambit_results.json", "utf-8");
98
101
  return JSON.parse(raw);
99
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godzillaba/mutest",
3
- "version": "1.2.1",
3
+ "version": "1.3.2",
4
4
  "bin": {
5
5
  "mutest": "./index.ts"
6
6
  },