@mutineerjs/mutineer 0.2.4 → 0.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.
- package/README.md +48 -42
- package/dist/bin/mutineer.js +0 -0
- package/dist/mutators/__tests__/operator.spec.js +169 -0
- package/dist/mutators/__tests__/registry.spec.js +6 -0
- package/dist/mutators/__tests__/return-value.spec.js +239 -0
- package/dist/mutators/__tests__/utils.spec.js +68 -1
- package/dist/mutators/operator.d.ts +25 -0
- package/dist/mutators/operator.js +50 -0
- package/dist/mutators/registry.d.ts +6 -28
- package/dist/mutators/registry.js +14 -66
- package/dist/mutators/return-value.d.ts +39 -0
- package/dist/mutators/return-value.js +104 -0
- package/dist/mutators/utils.d.ts +21 -0
- package/dist/mutators/utils.js +44 -27
- package/dist/runner/__tests__/pool-executor.spec.js +2 -4
- package/dist/runner/__tests__/variants.spec.js +3 -1
- package/dist/runner/discover.js +2 -1
- package/dist/runner/jest/__tests__/adapter.spec.js +1 -1
- package/dist/runner/jest/__tests__/pool.spec.js +5 -6
- package/dist/runner/jest/__tests__/worker-runtime.spec.js +2 -2
- package/dist/runner/jest/adapter.js +1 -1
- package/dist/runner/jest/pool.d.ts +1 -1
- package/dist/runner/jest/pool.js +6 -6
- package/dist/runner/jest/worker.mjs +1 -1
- package/dist/runner/pool-executor.js +1 -1
- package/dist/runner/shared/__tests__/redirect-state.spec.js +3 -3
- package/dist/runner/shared/index.d.ts +1 -1
- package/dist/runner/shared/index.js +1 -1
- package/dist/runner/shared/redirect-state.d.ts +2 -2
- package/dist/runner/shared/redirect-state.js +4 -4
- package/dist/runner/types.d.ts +1 -1
- package/dist/runner/vitest/__tests__/adapter.spec.js +1 -1
- package/dist/runner/vitest/__tests__/pool.spec.js +1 -1
- package/dist/runner/vitest/__tests__/redirect-loader.spec.js +83 -1
- package/dist/runner/vitest/__tests__/worker-runtime.spec.js +84 -0
- package/dist/runner/vitest/adapter.js +1 -1
- package/dist/runner/vitest/index.d.ts +0 -1
- package/dist/runner/vitest/index.js +0 -1
- package/dist/runner/vitest/pool.d.ts +1 -1
- package/dist/runner/vitest/pool.js +7 -7
- package/dist/runner/vitest/redirect-loader.d.ts +1 -1
- package/dist/runner/vitest/redirect-loader.js +1 -1
- package/dist/runner/vitest/worker-runtime.js +3 -3
- package/dist/runner/vitest/worker.mjs +1 -1
- package/dist/utils/__tests__/coverage.spec.js +167 -0
- package/dist/utils/__tests__/progress.spec.js +96 -0
- package/package.json +71 -22
- package/dist/admin/assets/index-B7nXq-e7.js +0 -32
- package/dist/admin/assets/index-B7nXq-e7.js.map +0 -1
- package/dist/admin/assets/index-BDQLkBUE.js +0 -32
- package/dist/admin/assets/index-BDQLkBUE.js.map +0 -1
- package/dist/admin/assets/index-DVkP-Tc7.css +0 -1
- package/dist/admin/index.html +0 -13
- package/dist/admin/server/admin.d.ts +0 -6
- package/dist/admin/server/admin.js +0 -234
- package/dist/bin/mutate-vitest.d.ts +0 -2
- package/dist/bin/mutate-vitest.js +0 -90
- package/dist/plugin/viteMutate.d.ts +0 -15
- package/dist/plugin/viteMutate.js +0 -52
- package/dist/plugin/vitest.setup.d.ts +0 -47
- package/dist/plugin/vitest.setup.js +0 -118
- package/dist/plugin/withVitest.d.ts +0 -13
- package/dist/plugin/withVitest.js +0 -30
- package/dist/runner/__tests__/orchestrator.spec.js +0 -55
- package/dist/runner/adapters/__tests__/jest.spec.js +0 -88
- package/dist/runner/adapters/__tests__/vitest-worker-runtime.spec.d.ts +0 -1
- package/dist/runner/adapters/__tests__/vitest-worker-runtime.spec.js +0 -59
- package/dist/runner/adapters/__tests__/vitest.spec.d.ts +0 -1
- package/dist/runner/adapters/__tests__/vitest.spec.js +0 -118
- package/dist/runner/adapters/index.d.ts +0 -10
- package/dist/runner/adapters/index.js +0 -9
- package/dist/runner/adapters/jest/__tests__/index.spec.d.ts +0 -1
- package/dist/runner/adapters/jest/__tests__/index.spec.js +0 -88
- package/dist/runner/adapters/jest/index.d.ts +0 -24
- package/dist/runner/adapters/jest/index.js +0 -216
- package/dist/runner/adapters/jest/worker-runtime.d.ts +0 -37
- package/dist/runner/adapters/jest/worker-runtime.js +0 -171
- package/dist/runner/adapters/jest-worker-runtime.d.ts +0 -37
- package/dist/runner/adapters/jest-worker-runtime.js +0 -171
- package/dist/runner/adapters/jest.d.ts +0 -24
- package/dist/runner/adapters/jest.js +0 -216
- package/dist/runner/adapters/types.d.ts +0 -89
- package/dist/runner/adapters/types.js +0 -8
- package/dist/runner/adapters/vitest/__tests__/index.spec.d.ts +0 -1
- package/dist/runner/adapters/vitest/__tests__/index.spec.js +0 -118
- package/dist/runner/adapters/vitest/__tests__/worker-runtime.spec.d.ts +0 -1
- package/dist/runner/adapters/vitest/__tests__/worker-runtime.spec.js +0 -59
- package/dist/runner/adapters/vitest/index.d.ts +0 -33
- package/dist/runner/adapters/vitest/index.js +0 -267
- package/dist/runner/adapters/vitest/worker-runtime.d.ts +0 -25
- package/dist/runner/adapters/vitest/worker-runtime.js +0 -118
- package/dist/runner/adapters/vitest-worker-runtime.d.ts +0 -25
- package/dist/runner/adapters/vitest-worker-runtime.js +0 -118
- package/dist/runner/adapters/vitest.d.ts +0 -33
- package/dist/runner/adapters/vitest.js +0 -267
- package/dist/runner/pool/__tests__/index.spec.d.ts +0 -1
- package/dist/runner/pool/__tests__/index.spec.js +0 -83
- package/dist/runner/pool/__tests__/pool-plugin.spec.d.ts +0 -1
- package/dist/runner/pool/__tests__/pool-plugin.spec.js +0 -59
- package/dist/runner/pool/__tests__/pool-redirect-loader.spec.d.ts +0 -1
- package/dist/runner/pool/__tests__/pool-redirect-loader.spec.js +0 -78
- package/dist/runner/pool/index.d.ts +0 -8
- package/dist/runner/pool/index.js +0 -9
- package/dist/runner/pool/jest/pool.d.ts +0 -52
- package/dist/runner/pool/jest/pool.js +0 -309
- package/dist/runner/pool/jest/worker.d.mts +0 -1
- package/dist/runner/pool/jest/worker.mjs +0 -60
- package/dist/runner/pool/jest-pool.d.ts +0 -52
- package/dist/runner/pool/jest-pool.js +0 -309
- package/dist/runner/pool/jest-worker.d.mts +0 -1
- package/dist/runner/pool/jest-worker.mjs +0 -60
- package/dist/runner/pool/plugin.d.ts +0 -18
- package/dist/runner/pool/plugin.js +0 -60
- package/dist/runner/pool/pool-plugin.d.ts +0 -18
- package/dist/runner/pool/pool-plugin.js +0 -60
- package/dist/runner/pool/pool-redirect-loader.d.ts +0 -19
- package/dist/runner/pool/pool-redirect-loader.js +0 -116
- package/dist/runner/pool/pool-redirect-loader.mjs +0 -146
- package/dist/runner/pool/redirect-loader.d.ts +0 -19
- package/dist/runner/pool/redirect-loader.js +0 -116
- package/dist/runner/pool/vitest/pool.d.ts +0 -70
- package/dist/runner/pool/vitest/pool.js +0 -376
- package/dist/runner/pool/vitest/worker.d.mts +0 -15
- package/dist/runner/pool/vitest/worker.mjs +0 -96
- package/dist/runner/pool/vitest-worker.d.mts +0 -15
- package/dist/runner/pool/vitest-worker.mjs +0 -96
- package/dist/runner/shared-module-redirect.d.ts +0 -56
- package/dist/runner/shared-module-redirect.js +0 -84
- package/dist/types/api.d.ts +0 -20
- package/dist/types/api.js +0 -1
- /package/dist/{runner/__tests__/orchestrator.spec.d.ts → mutators/__tests__/operator.spec.d.ts} +0 -0
- /package/dist/{runner/adapters/__tests__/jest.spec.d.ts → mutators/__tests__/return-value.spec.d.ts} +0 -0
|
@@ -42,7 +42,7 @@ export async function executePool(opts) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
//
|
|
45
|
+
// Initialise worker pool
|
|
46
46
|
const workerLogSuffix = workerCount < concurrency ? ` (requested ${concurrency})` : '';
|
|
47
47
|
log.info(`Initializing ${adapter.name} worker pool with ${workerCount} workers...${workerLogSuffix}`);
|
|
48
48
|
const poolStart = Date.now();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { initialiseRedirectState, setRedirect, getRedirect, clearRedirect, } from '../redirect-state.js';
|
|
3
3
|
describe('redirect-state', () => {
|
|
4
4
|
beforeEach(() => {
|
|
5
|
-
|
|
5
|
+
initialiseRedirectState();
|
|
6
6
|
});
|
|
7
|
-
describe('
|
|
7
|
+
describe('initialiseRedirectState', () => {
|
|
8
8
|
it('sets global redirect to null/null', () => {
|
|
9
9
|
expect(globalThis.__mutineer_redirect__).toEqual({
|
|
10
10
|
from: null,
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* including mutant file path generation and redirect state management.
|
|
6
6
|
*/
|
|
7
7
|
export { getMutantFilePath } from './mutant-paths.js';
|
|
8
|
-
export { setRedirect, getRedirect, clearRedirect,
|
|
8
|
+
export { setRedirect, getRedirect, clearRedirect, initialiseRedirectState, } from './redirect-state.js';
|
|
9
9
|
export type { RedirectConfig } from './redirect-state.js';
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* including mutant file path generation and redirect state management.
|
|
6
6
|
*/
|
|
7
7
|
export { getMutantFilePath } from './mutant-paths.js';
|
|
8
|
-
export { setRedirect, getRedirect, clearRedirect,
|
|
8
|
+
export { setRedirect, getRedirect, clearRedirect, initialiseRedirectState, } from './redirect-state.js';
|
|
@@ -23,10 +23,10 @@ export interface RedirectConfig {
|
|
|
23
23
|
readonly to: string;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Initialise the global redirect state.
|
|
27
27
|
* Must be called once at module load time.
|
|
28
28
|
*/
|
|
29
|
-
export declare function
|
|
29
|
+
export declare function initialiseRedirectState(): void;
|
|
30
30
|
/**
|
|
31
31
|
* Set the active redirect configuration.
|
|
32
32
|
*
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* test execution.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Initialise the global redirect state.
|
|
12
12
|
* Must be called once at module load time.
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
14
|
+
export function initialiseRedirectState() {
|
|
15
15
|
globalThis.__mutineer_redirect__ = { from: null, to: null };
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -46,5 +46,5 @@ export function getRedirect() {
|
|
|
46
46
|
export function clearRedirect() {
|
|
47
47
|
globalThis.__mutineer_redirect__ = { from: null, to: null };
|
|
48
48
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
49
|
+
// Initialise on module load
|
|
50
|
+
initialiseRedirectState();
|
package/dist/runner/types.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface TestRunnerAdapter {
|
|
|
41
41
|
*/
|
|
42
42
|
readonly name: string;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Initialise the adapter (start worker pools, etc.).
|
|
45
45
|
* Must be called before running tests.
|
|
46
46
|
*/
|
|
47
47
|
init(concurrencyOverride?: number): Promise<void>;
|
|
@@ -41,7 +41,7 @@ describe('Vitest adapter', () => {
|
|
|
41
41
|
afterEach(() => {
|
|
42
42
|
vi.useRealTimers();
|
|
43
43
|
});
|
|
44
|
-
it('
|
|
44
|
+
it('initialises pool with override concurrency', async () => {
|
|
45
45
|
const adapter = makeAdapter();
|
|
46
46
|
await adapter.init(5);
|
|
47
47
|
expect(poolInstance?.init).toHaveBeenCalledTimes(1);
|
|
@@ -40,7 +40,7 @@ describe('VitestPool', () => {
|
|
|
40
40
|
cwd: process.cwd(),
|
|
41
41
|
concurrency: 1,
|
|
42
42
|
timeoutMs: 5000,
|
|
43
|
-
createWorker: (id
|
|
43
|
+
createWorker: (id) => {
|
|
44
44
|
const worker = new EventEmitter();
|
|
45
45
|
worker.id = id;
|
|
46
46
|
worker.start = vi.fn().mockResolvedValue(undefined);
|
|
@@ -7,11 +7,12 @@ vi.mock('node:module', async (importOriginal) => {
|
|
|
7
7
|
const actual = await importOriginal();
|
|
8
8
|
return { ...actual, register: vi.fn() };
|
|
9
9
|
});
|
|
10
|
-
import { resolve as poolResolve } from '../redirect-loader.js';
|
|
10
|
+
import { resolve as poolResolve, initialise } from '../redirect-loader.js';
|
|
11
11
|
describe('pool-redirect-loader resolve', () => {
|
|
12
12
|
afterEach(() => {
|
|
13
13
|
;
|
|
14
14
|
globalThis.__mutineer_redirect__ = undefined;
|
|
15
|
+
delete process.env.MUTINEER_DEBUG;
|
|
15
16
|
vi.restoreAllMocks();
|
|
16
17
|
});
|
|
17
18
|
it('resolves .js to .ts in the same directory', async () => {
|
|
@@ -88,4 +89,85 @@ describe('pool-redirect-loader resolve', () => {
|
|
|
88
89
|
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
89
90
|
}
|
|
90
91
|
});
|
|
92
|
+
it('passes through non-.js specifiers to nextResolve', async () => {
|
|
93
|
+
const nextResolve = vi.fn().mockResolvedValue({
|
|
94
|
+
url: 'file:///some/module.ts',
|
|
95
|
+
shortCircuit: false,
|
|
96
|
+
});
|
|
97
|
+
const result = await poolResolve('./module', { parentURL: 'file:///src/index.ts' }, nextResolve);
|
|
98
|
+
expect(nextResolve).toHaveBeenCalled();
|
|
99
|
+
expect(result.url).toBe('file:///some/module.ts');
|
|
100
|
+
});
|
|
101
|
+
it('passes through builtin modules to nextResolve', async () => {
|
|
102
|
+
const nextResolve = vi.fn().mockResolvedValue({
|
|
103
|
+
url: 'node:fs',
|
|
104
|
+
shortCircuit: true,
|
|
105
|
+
});
|
|
106
|
+
const result = await poolResolve('node:fs', { parentURL: 'file:///src/index.ts' }, nextResolve);
|
|
107
|
+
expect(nextResolve).toHaveBeenCalled();
|
|
108
|
+
expect(result.url).toBe('node:fs');
|
|
109
|
+
});
|
|
110
|
+
it('skips .js->ts resolution for non-relative specifiers', async () => {
|
|
111
|
+
const nextResolve = vi.fn().mockResolvedValue({
|
|
112
|
+
url: 'file:///node_modules/pkg/index.js',
|
|
113
|
+
shortCircuit: false,
|
|
114
|
+
});
|
|
115
|
+
const result = await poolResolve('some-package/foo.js', { parentURL: 'file:///src/index.ts' }, nextResolve);
|
|
116
|
+
expect(nextResolve).toHaveBeenCalled();
|
|
117
|
+
expect(result.url).toBe('file:///node_modules/pkg/index.js');
|
|
118
|
+
});
|
|
119
|
+
it('resolves .js to .tsx when .ts does not exist', async () => {
|
|
120
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-pool-loader-'));
|
|
121
|
+
const parentFile = path.join(tmpDir, 'src', 'index.ts');
|
|
122
|
+
const tsxFile = path.join(tmpDir, 'src', 'comp.tsx');
|
|
123
|
+
await fs.mkdir(path.dirname(parentFile), { recursive: true });
|
|
124
|
+
await fs.writeFile(parentFile, 'export {}', 'utf8');
|
|
125
|
+
await fs.writeFile(tsxFile, 'export const Comp = () => null', 'utf8');
|
|
126
|
+
try {
|
|
127
|
+
const nextResolve = vi.fn();
|
|
128
|
+
const result = await poolResolve('./comp.js', { parentURL: pathToFileURL(parentFile).href }, nextResolve);
|
|
129
|
+
expect(nextResolve).not.toHaveBeenCalled();
|
|
130
|
+
expect(result.shortCircuit).toBe(true);
|
|
131
|
+
expect(result.url).toBe(pathToFileURL(tsxFile).href);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
it('tries parent of __mutineer__ directory for ts resolution', async () => {
|
|
138
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-pool-loader-'));
|
|
139
|
+
const srcDir = path.join(tmpDir, 'src');
|
|
140
|
+
const mutineerDir = path.join(srcDir, '__mutineer__');
|
|
141
|
+
await fs.mkdir(mutineerDir, { recursive: true });
|
|
142
|
+
const parentFile = path.join(mutineerDir, 'mutant.ts');
|
|
143
|
+
const tsFile = path.join(srcDir, 'sibling.ts');
|
|
144
|
+
await fs.writeFile(parentFile, 'export {}', 'utf8');
|
|
145
|
+
await fs.writeFile(tsFile, 'export const x = 1', 'utf8');
|
|
146
|
+
try {
|
|
147
|
+
const nextResolve = vi.fn();
|
|
148
|
+
const result = await poolResolve('./sibling.js', { parentURL: pathToFileURL(parentFile).href }, nextResolve);
|
|
149
|
+
expect(nextResolve).not.toHaveBeenCalled();
|
|
150
|
+
expect(result.shortCircuit).toBe(true);
|
|
151
|
+
expect(result.url).toBe(pathToFileURL(tsFile).href);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
it('initialise sets debug mode', () => {
|
|
158
|
+
// Should not throw
|
|
159
|
+
initialise({ debug: true });
|
|
160
|
+
initialise({ debug: false });
|
|
161
|
+
initialise(undefined);
|
|
162
|
+
});
|
|
163
|
+
it('returns null from tryResolveTsExtension when parentURL is invalid', async () => {
|
|
164
|
+
const nextResolve = vi.fn().mockResolvedValue({
|
|
165
|
+
url: 'file:///fallback.js',
|
|
166
|
+
shortCircuit: false,
|
|
167
|
+
});
|
|
168
|
+
// parentURL is not a valid file URL, so tryResolveTsExtension should return null
|
|
169
|
+
await poolResolve('./foo.js', { parentURL: 'not-a-valid-url' }, nextResolve);
|
|
170
|
+
// Falls through to nextResolve
|
|
171
|
+
expect(nextResolve).toHaveBeenCalled();
|
|
172
|
+
});
|
|
91
173
|
});
|
|
@@ -55,6 +55,90 @@ describe('VitestWorkerRuntime', () => {
|
|
|
55
55
|
expect(fs.existsSync(path.join(tmp, 'src', '__mutineer__'))).toBe(false);
|
|
56
56
|
await runtime.shutdown();
|
|
57
57
|
});
|
|
58
|
+
it('throws when run is called before init', async () => {
|
|
59
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
|
|
60
|
+
tmpFiles.push(tmp);
|
|
61
|
+
const runtime = createVitestWorkerRuntime({
|
|
62
|
+
workerId: 'w-noinit',
|
|
63
|
+
cwd: tmp,
|
|
64
|
+
});
|
|
65
|
+
await expect(runtime.run({
|
|
66
|
+
id: 'mut#err',
|
|
67
|
+
name: 'm',
|
|
68
|
+
file: path.join(tmp, 'src.ts'),
|
|
69
|
+
code: 'export const x=1',
|
|
70
|
+
line: 1,
|
|
71
|
+
col: 1,
|
|
72
|
+
}, [path.join(tmp, 'test.ts')])).rejects.toThrow('Vitest runtime not initialised');
|
|
73
|
+
});
|
|
74
|
+
it('shutdown is a no-op when not initialised', async () => {
|
|
75
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
|
|
76
|
+
tmpFiles.push(tmp);
|
|
77
|
+
const runtime = createVitestWorkerRuntime({
|
|
78
|
+
workerId: 'w-noinit2',
|
|
79
|
+
cwd: tmp,
|
|
80
|
+
});
|
|
81
|
+
// Should not throw
|
|
82
|
+
await runtime.shutdown();
|
|
83
|
+
expect(closeFn).not.toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
it('passes vitestConfigPath option to createVitest', async () => {
|
|
86
|
+
const { createVitest } = await import('vitest/node');
|
|
87
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
|
|
88
|
+
tmpFiles.push(tmp);
|
|
89
|
+
const runtime = createVitestWorkerRuntime({
|
|
90
|
+
workerId: 'w-config',
|
|
91
|
+
cwd: tmp,
|
|
92
|
+
vitestConfigPath: '/custom/vitest.config.ts',
|
|
93
|
+
});
|
|
94
|
+
await runtime.init();
|
|
95
|
+
expect(createVitest).toHaveBeenCalledWith('test', expect.objectContaining({ config: '/custom/vitest.config.ts' }), expect.any(Object));
|
|
96
|
+
await runtime.shutdown();
|
|
97
|
+
});
|
|
98
|
+
it('handles non-Error thrown during run', async () => {
|
|
99
|
+
runSpecsFn.mockRejectedValue('string error');
|
|
100
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
|
|
101
|
+
tmpFiles.push(tmp);
|
|
102
|
+
const runtime = createVitestWorkerRuntime({
|
|
103
|
+
workerId: 'w-strerr',
|
|
104
|
+
cwd: tmp,
|
|
105
|
+
});
|
|
106
|
+
await runtime.init();
|
|
107
|
+
const result = await runtime.run({
|
|
108
|
+
id: 'mut#3',
|
|
109
|
+
name: 'm',
|
|
110
|
+
file: path.join(tmp, 'src.ts'),
|
|
111
|
+
code: 'export const x=1',
|
|
112
|
+
line: 1,
|
|
113
|
+
col: 1,
|
|
114
|
+
}, [path.join(tmp, 'test.ts')]);
|
|
115
|
+
expect(result.killed).toBe(true);
|
|
116
|
+
expect(result.error).toBe('string error');
|
|
117
|
+
await runtime.shutdown();
|
|
118
|
+
});
|
|
119
|
+
it('falls back to all testModules when no relevant modules match', async () => {
|
|
120
|
+
runSpecsFn.mockResolvedValue({
|
|
121
|
+
testModules: [{ moduleId: 'unknown-module', ok: () => true }],
|
|
122
|
+
});
|
|
123
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
|
|
124
|
+
tmpFiles.push(tmp);
|
|
125
|
+
const runtime = createVitestWorkerRuntime({
|
|
126
|
+
workerId: 'w-fallback',
|
|
127
|
+
cwd: tmp,
|
|
128
|
+
});
|
|
129
|
+
await runtime.init();
|
|
130
|
+
const result = await runtime.run({
|
|
131
|
+
id: 'mut#4',
|
|
132
|
+
name: 'm',
|
|
133
|
+
file: path.join(tmp, 'src.ts'),
|
|
134
|
+
code: 'export const x=1',
|
|
135
|
+
line: 1,
|
|
136
|
+
col: 1,
|
|
137
|
+
}, [path.join(tmp, 'test.ts')]);
|
|
138
|
+
// Falls back to all testModules; 'unknown-module' reports ok() = true
|
|
139
|
+
expect(result.killed).toBe(false);
|
|
140
|
+
await runtime.shutdown();
|
|
141
|
+
});
|
|
58
142
|
it('returns escaped when no specs produced', async () => {
|
|
59
143
|
getProjectByNameFn.mockReturnValue({ createSpecification: () => null });
|
|
60
144
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mutineer-worker-'));
|
|
@@ -154,7 +154,7 @@ export class VitestAdapter {
|
|
|
154
154
|
}
|
|
155
155
|
async runMutant(mutant, tests) {
|
|
156
156
|
if (!this.pool) {
|
|
157
|
-
throw new Error('VitestAdapter not
|
|
157
|
+
throw new Error('VitestAdapter not initialised. Call init() first.');
|
|
158
158
|
}
|
|
159
159
|
try {
|
|
160
160
|
const result = await this.pool.run(mutant, [...tests]);
|
|
@@ -7,5 +7,4 @@
|
|
|
7
7
|
export { VitestAdapter, createVitestAdapter, isCoverageRequestedInArgs, } from './adapter.js';
|
|
8
8
|
export { VitestPool, runWithPool, type VitestPoolOptions } from './pool.js';
|
|
9
9
|
export { poolMutineerPlugin } from './plugin.js';
|
|
10
|
-
export { resolve as poolRedirectResolve } from './redirect-loader.js';
|
|
11
10
|
export type { MutantPayload, MutantRunResult, MutantRunSummary, } from '../../types/mutant.js';
|
|
@@ -7,4 +7,3 @@
|
|
|
7
7
|
export { VitestAdapter, createVitestAdapter, isCoverageRequestedInArgs, } from './adapter.js';
|
|
8
8
|
export { VitestPool, runWithPool } from './pool.js';
|
|
9
9
|
export { poolMutineerPlugin } from './plugin.js';
|
|
10
|
-
export { resolve as poolRedirectResolve } from './redirect-loader.js';
|
|
@@ -221,7 +221,7 @@ export class VitestPool {
|
|
|
221
221
|
this.workers = [];
|
|
222
222
|
this.availableWorkers = [];
|
|
223
223
|
this.waitingTasks = [];
|
|
224
|
-
this.
|
|
224
|
+
this.initialised = false;
|
|
225
225
|
this.shuttingDown = false;
|
|
226
226
|
this.options = {
|
|
227
227
|
cwd: options.cwd,
|
|
@@ -232,7 +232,7 @@ export class VitestPool {
|
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
234
|
async init() {
|
|
235
|
-
if (this.
|
|
235
|
+
if (this.initialised)
|
|
236
236
|
return;
|
|
237
237
|
poolLog.debug(`Initializing pool with ${this.options.concurrency} workers`);
|
|
238
238
|
const startPromises = [];
|
|
@@ -254,8 +254,8 @@ export class VitestPool {
|
|
|
254
254
|
}));
|
|
255
255
|
}
|
|
256
256
|
await Promise.all(startPromises);
|
|
257
|
-
this.
|
|
258
|
-
poolLog.debug('Pool
|
|
257
|
+
this.initialised = true;
|
|
258
|
+
poolLog.debug('Pool initialised');
|
|
259
259
|
}
|
|
260
260
|
handleWorkerExit(worker) {
|
|
261
261
|
// Remove from available list
|
|
@@ -313,8 +313,8 @@ export class VitestPool {
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
async run(mutant, tests) {
|
|
316
|
-
if (!this.
|
|
317
|
-
throw new Error('Pool not
|
|
316
|
+
if (!this.initialised) {
|
|
317
|
+
throw new Error('Pool not initialised. Call init() first.');
|
|
318
318
|
}
|
|
319
319
|
if (this.shuttingDown) {
|
|
320
320
|
throw new Error('Pool is shutting down');
|
|
@@ -336,7 +336,7 @@ export class VitestPool {
|
|
|
336
336
|
await Promise.all(this.workers.map((w) => w.shutdown()));
|
|
337
337
|
this.workers = [];
|
|
338
338
|
this.availableWorkers = [];
|
|
339
|
-
this.
|
|
339
|
+
this.initialised = false;
|
|
340
340
|
poolLog.debug('Pool shut down');
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -13,7 +13,7 @@ declare global {
|
|
|
13
13
|
to: string | null;
|
|
14
14
|
} | undefined;
|
|
15
15
|
}
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function initialise(data: {
|
|
17
17
|
debug?: boolean;
|
|
18
18
|
} | undefined): void;
|
|
19
19
|
export declare function resolve(specifier: string, context: {
|
|
@@ -17,7 +17,7 @@ register(import.meta.url, {
|
|
|
17
17
|
data: { debug: process.env.MUTINEER_DEBUG === '1' },
|
|
18
18
|
});
|
|
19
19
|
let DEBUG = process.env.MUTINEER_DEBUG === '1';
|
|
20
|
-
export function
|
|
20
|
+
export function initialise(data) {
|
|
21
21
|
if (data?.debug !== undefined) {
|
|
22
22
|
DEBUG = data.debug;
|
|
23
23
|
}
|
|
@@ -25,10 +25,10 @@ export class VitestWorkerRuntime {
|
|
|
25
25
|
plugins: [poolMutineerPlugin()],
|
|
26
26
|
});
|
|
27
27
|
await this.vitest.init();
|
|
28
|
-
log.debug(`Vitest
|
|
28
|
+
log.debug(`Vitest initialised for worker ${this.options.workerId}`);
|
|
29
29
|
}
|
|
30
30
|
catch (err) {
|
|
31
|
-
log.error(`Failed to
|
|
31
|
+
log.error(`Failed to initialise Vitest: ${err}`);
|
|
32
32
|
throw err;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -40,7 +40,7 @@ export class VitestWorkerRuntime {
|
|
|
40
40
|
}
|
|
41
41
|
async run(mutant, tests) {
|
|
42
42
|
if (!this.vitest) {
|
|
43
|
-
throw new Error('Vitest runtime not
|
|
43
|
+
throw new Error('Vitest runtime not initialised');
|
|
44
44
|
}
|
|
45
45
|
const start = Date.now();
|
|
46
46
|
try {
|
|
@@ -38,6 +38,173 @@ describe('coverage utilities', () => {
|
|
|
38
38
|
const coverage = { coveredLines: new Map() };
|
|
39
39
|
expect(getFileCoverageStats(coverage, '/nope.ts')).toBeNull();
|
|
40
40
|
});
|
|
41
|
+
it('loads coverage from a relative path', async () => {
|
|
42
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
43
|
+
const filePath = '/src/file.ts';
|
|
44
|
+
const data = {
|
|
45
|
+
[filePath]: {
|
|
46
|
+
path: filePath,
|
|
47
|
+
statementMap: {
|
|
48
|
+
'0': { start: { line: 1, column: 0 }, end: { line: 1, column: 10 } },
|
|
49
|
+
},
|
|
50
|
+
s: { '0': 1 },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
await fs.writeFile(path.join(tmpDir, 'cov.json'), JSON.stringify(data), 'utf8');
|
|
54
|
+
try {
|
|
55
|
+
const coverage = await loadCoverageData('cov.json', tmpDir);
|
|
56
|
+
expect(coverage.coveredLines.size).toBeGreaterThan(0);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
it('throws on missing coverage file', async () => {
|
|
63
|
+
await expect(loadCoverageData('/nonexistent/path.json', '/tmp')).rejects.toThrow('Failed to read coverage file');
|
|
64
|
+
});
|
|
65
|
+
it('throws on invalid JSON in coverage file', async () => {
|
|
66
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
67
|
+
await fs.writeFile(path.join(tmpDir, 'bad.json'), 'not json', 'utf8');
|
|
68
|
+
try {
|
|
69
|
+
await expect(loadCoverageData(path.join(tmpDir, 'bad.json'), tmpDir)).rejects.toThrow('Failed to parse coverage file');
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
it('skips files with missing statementMap or s', async () => {
|
|
76
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
77
|
+
const data = {
|
|
78
|
+
'/src/nomap.ts': { path: '/src/nomap.ts' },
|
|
79
|
+
'/src/nos.ts': {
|
|
80
|
+
path: '/src/nos.ts',
|
|
81
|
+
statementMap: {
|
|
82
|
+
'0': { start: { line: 1, column: 0 }, end: { line: 1, column: 10 } },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
await fs.writeFile(path.join(tmpDir, 'cov.json'), JSON.stringify(data), 'utf8');
|
|
87
|
+
try {
|
|
88
|
+
const coverage = await loadCoverageData(path.join(tmpDir, 'cov.json'), tmpDir);
|
|
89
|
+
expect(coverage.coveredLines.size).toBe(0);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
it('normalizes relative file paths in coverage data', async () => {
|
|
96
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
97
|
+
const data = {
|
|
98
|
+
'src/relative.ts': {
|
|
99
|
+
path: 'src/relative.ts',
|
|
100
|
+
statementMap: {
|
|
101
|
+
'0': { start: { line: 1, column: 0 }, end: { line: 1, column: 10 } },
|
|
102
|
+
},
|
|
103
|
+
s: { '0': 1 },
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
await fs.writeFile(path.join(tmpDir, 'cov.json'), JSON.stringify(data), 'utf8');
|
|
107
|
+
try {
|
|
108
|
+
const coverage = await loadCoverageData(path.join(tmpDir, 'cov.json'), tmpDir);
|
|
109
|
+
// Should have resolved relative path
|
|
110
|
+
const absPath = path.join(tmpDir, 'src/relative.ts');
|
|
111
|
+
expect(coverage.coveredLines.has(absPath)).toBe(true);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
it('skips files where all statements have zero hits', async () => {
|
|
118
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
119
|
+
const data = {
|
|
120
|
+
'/src/uncovered.ts': {
|
|
121
|
+
path: '/src/uncovered.ts',
|
|
122
|
+
statementMap: {
|
|
123
|
+
'0': { start: { line: 1, column: 0 }, end: { line: 1, column: 10 } },
|
|
124
|
+
},
|
|
125
|
+
s: { '0': 0 },
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
await fs.writeFile(path.join(tmpDir, 'cov.json'), JSON.stringify(data), 'utf8');
|
|
129
|
+
try {
|
|
130
|
+
const coverage = await loadCoverageData(path.join(tmpDir, 'cov.json'), tmpDir);
|
|
131
|
+
expect(coverage.coveredLines.size).toBe(0);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
it('isLineCovered returns false for uncovered file', () => {
|
|
138
|
+
const coverage = { coveredLines: new Map() };
|
|
139
|
+
expect(isLineCovered(coverage, '/nonexistent.ts', 1)).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
it('returns null for per-test coverage when no files found', async () => {
|
|
142
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
143
|
+
await fs.mkdir(path.join(tmpDir, 'empty-reports'), { recursive: true });
|
|
144
|
+
try {
|
|
145
|
+
const map = await loadPerTestCoverageData(path.join(tmpDir, 'empty-reports'), tmpDir);
|
|
146
|
+
expect(map).toBeNull();
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
it('loads per-test coverage in format B (direct arrays)', async () => {
|
|
153
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
154
|
+
const reportsDir = path.join(tmpDir, 'coverage');
|
|
155
|
+
await fs.mkdir(reportsDir, { recursive: true });
|
|
156
|
+
const formatB = {
|
|
157
|
+
'/test/a.spec.ts': {
|
|
158
|
+
'/src/a.ts': [1, 2, 3],
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
await fs.writeFile(path.join(reportsDir, 'per-test-coverage.json'), JSON.stringify(formatB), 'utf8');
|
|
162
|
+
try {
|
|
163
|
+
const map = await loadPerTestCoverageData(reportsDir, tmpDir);
|
|
164
|
+
expect(map).not.toBeNull();
|
|
165
|
+
const lines = map.get('/test/a.spec.ts').get('/src/a.ts');
|
|
166
|
+
expect(lines.has(1)).toBe(true);
|
|
167
|
+
expect(lines.has(3)).toBe(true);
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
it('handles per-test coverage with non-object/null values gracefully', async () => {
|
|
174
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
175
|
+
const reportsDir = path.join(tmpDir, 'coverage');
|
|
176
|
+
await fs.mkdir(reportsDir, { recursive: true });
|
|
177
|
+
const data = {
|
|
178
|
+
'/test/a.spec.ts': null,
|
|
179
|
+
'/test/b.spec.ts': 'not-an-object',
|
|
180
|
+
};
|
|
181
|
+
await fs.writeFile(path.join(reportsDir, 'per-test-coverage.json'), JSON.stringify(data), 'utf8');
|
|
182
|
+
try {
|
|
183
|
+
const map = await loadPerTestCoverageData(reportsDir, tmpDir);
|
|
184
|
+
// No valid entries, should return null
|
|
185
|
+
expect(map).toBeNull();
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
it('uses relative reportsDir when not absolute', async () => {
|
|
192
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
193
|
+
const reportsDir = path.join(tmpDir, 'reports');
|
|
194
|
+
await fs.mkdir(reportsDir, { recursive: true });
|
|
195
|
+
const data = {
|
|
196
|
+
'/test/a.spec.ts': { '/src/a.ts': [1] },
|
|
197
|
+
};
|
|
198
|
+
await fs.writeFile(path.join(reportsDir, 'per-test-coverage.json'), JSON.stringify(data), 'utf8');
|
|
199
|
+
try {
|
|
200
|
+
// Pass relative path
|
|
201
|
+
const map = await loadPerTestCoverageData('reports', tmpDir);
|
|
202
|
+
expect(map).not.toBeNull();
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
41
208
|
it('loads per-test coverage data from various shapes', async () => {
|
|
42
209
|
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mutineer-coverage-'));
|
|
43
210
|
const reportsDir = path.join(tmpDir, 'coverage');
|