Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vitest): use cwd for communication dir #4217

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ src-generated
dist
dist-test
packages/*/testResources/tmp
packages/vitest-runner/.vitest-runner-undefined
packages/report.*.json # Ignore heap dumps
.idea
*.iml
Expand Down
13 changes: 6 additions & 7 deletions packages/vitest-runner/src/file-communicator.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import path from 'path';
import fs from 'fs/promises';
import { fileURLToPath } from 'url';

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

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

export class FileCommunicator {
private readonly communicationDir = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
`.vitest-runner-${process.env.STRYKER_MUTATOR_WORKER}`
);
private readonly communicationDir = path.resolve(`.vitest-runner-${process.env.STRYKER_MUTATOR_WORKER}`);

public readonly files = Object.freeze({
// Replace function is to have a valid windows path
Expand Down Expand Up @@ -79,15 +75,18 @@ export class FileCommunicator {
import { normalizeFileName } from '@stryker-mutator/util';

import { beforeEach, afterAll, beforeAll, afterEach } from 'vitest';
const cwd = process.cwd();

const ns = globalThis.${this.globalNamespace} || (globalThis.${this.globalNamespace} = {});
${body}`;
}

private async cleanCommunicationDirectories() {
await fs.rm(this.communicationDir, { recursive: true, force: true });
await this.dispose();
await fs.mkdir(this.files.coverageDir, { recursive: true });
await fs.mkdir(this.files.hitCountDir, { recursive: true });
}

public async dispose(): Promise<void> {
await fs.rm(this.communicationDir, { recursive: true, force: true });
}
}
1 change: 1 addition & 0 deletions packages/vitest-runner/src/vitest-test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class VitestTestRunner implements TestRunner {
}

public async dispose(): Promise<void> {
await this.fileCommunicator.dispose();
await this.ctx.close();
await this.ctx.closingPromise;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/vitest-runner/test/unit/file-communication.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs/promises';
import { fileURLToPath } from 'url';
import { syncBuiltinESMExports } from 'module';
import path from 'path';

Expand All @@ -24,7 +23,7 @@ describe(FileCommunicator.name, () => {
syncBuiltinESMExports();
});

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

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