Skip to content

Commit 736d97c

Browse files
authored
fix(vitest): use cwd for communication dir (#4217)
Base the communication directory of the vitest runner on the current working directory (cwd) rather than the `node_modules/@stryker-mutator/vitest-runner` directory.
1 parent e775193 commit 736d97c

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ src-generated
1616
dist
1717
dist-test
1818
packages/*/testResources/tmp
19+
packages/vitest-runner/.vitest-runner-undefined
1920
packages/report.*.json # Ignore heap dumps
2021
.idea
2122
*.iml

packages/vitest-runner/src/file-communicator.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import path from 'path';
22
import fs from 'fs/promises';
3-
import { fileURLToPath } from 'url';
43

54
import { MutantRunOptions } from '@stryker-mutator/api/test-runner';
65
import { normalizeFileName } from '@stryker-mutator/util';
76

87
import { collectTestName, toTestId } from './vitest-helpers.js';
98

109
export class FileCommunicator {
11-
private readonly communicationDir = path.resolve(
12-
path.dirname(fileURLToPath(import.meta.url)),
13-
`.vitest-runner-${process.env.STRYKER_MUTATOR_WORKER}`
14-
);
10+
private readonly communicationDir = path.resolve(`.vitest-runner-${process.env.STRYKER_MUTATOR_WORKER}`);
1511

1612
public readonly files = Object.freeze({
1713
// Replace function is to have a valid windows path
@@ -79,15 +75,18 @@ export class FileCommunicator {
7975
import { normalizeFileName } from '@stryker-mutator/util';
8076
8177
import { beforeEach, afterAll, beforeAll, afterEach } from 'vitest';
82-
const cwd = process.cwd();
8378
8479
const ns = globalThis.${this.globalNamespace} || (globalThis.${this.globalNamespace} = {});
8580
${body}`;
8681
}
8782

8883
private async cleanCommunicationDirectories() {
89-
await fs.rm(this.communicationDir, { recursive: true, force: true });
84+
await this.dispose();
9085
await fs.mkdir(this.files.coverageDir, { recursive: true });
9186
await fs.mkdir(this.files.hitCountDir, { recursive: true });
9287
}
88+
89+
public async dispose(): Promise<void> {
90+
await fs.rm(this.communicationDir, { recursive: true, force: true });
91+
}
9392
}

packages/vitest-runner/src/vitest-test-runner.ts

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export class VitestTestRunner implements TestRunner {
178178
}
179179

180180
public async dispose(): Promise<void> {
181+
await this.fileCommunicator.dispose();
181182
await this.ctx.close();
182183
await this.ctx.closingPromise;
183184
}

packages/vitest-runner/test/unit/file-communication.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fs from 'fs/promises';
2-
import { fileURLToPath } from 'url';
32
import { syncBuiltinESMExports } from 'module';
43
import path from 'path';
54

@@ -24,7 +23,7 @@ describe(FileCommunicator.name, () => {
2423
syncBuiltinESMExports();
2524
});
2625

27-
const communicationDir = fileURLToPath(new URL(`../../src/.vitest-runner-${process.env.STRYKER_MUTATOR_WORKER}`, import.meta.url));
26+
const communicationDir = path.resolve(`.vitest-runner-${process.env.STRYKER_MUTATOR_WORKER}`);
2827

2928
function assertVitestSetupContains(containsText: string) {
3029
sinon.assert.calledOnceWithExactly(writeFileStub, sut.files.vitestSetup, sinon.match(containsText));

0 commit comments

Comments
 (0)