Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
Open
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
15 changes: 10 additions & 5 deletions packages/vitest/src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, resolve } from 'node:path';
import { dirname, extname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import type {
FlakyDetectionContext,
Expand Down Expand Up @@ -157,10 +157,15 @@ export class MergifyReporter implements Reporter {
// Provide quarantine list to workers via ProvidedContext
vitest.provide('mergify:quarantine', [...this.quarantineList]);

// Auto-configure the custom runner if not already set
const dir =
typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url));
const mergifyRunner = resolve(dir, 'runner.js');
// Auto-configure the custom runner if not already set.
// Resolve the runner sibling with the same extension as the current module: the build emits
// dist/index.cjs + dist/runner.cjs and dist/index.mjs + dist/runner.mjs (never runner.js), and
// in dev the sibling is src/runner.ts. A hardcoded 'runner.js' only worked in dev, where
// vite-node remaps the .js specifier onto runner.ts — in the published package the path goes
// through native node resolution and ERR_MODULE_NOT_FOUND aborts every test file (#169).
const moduleFile =
typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url);
const mergifyRunner = resolve(dirname(moduleFile), `runner${extname(moduleFile)}`);
if (!vitest.config.runner) {
vitest.config.runner = mergifyRunner;
} else if (vitest.config.runner !== mergifyRunner) {
Expand Down
33 changes: 33 additions & 0 deletions packages/vitest/tests/dist-runner.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { resolve } from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { startVitest } from 'vitest/node';
// Same scenario as runner.test.ts but consuming the BUILT package, the way a
// real consumer does — this is the path #169 crashed on.
// eslint-disable-next-line import/no-unresolved
import { MergifyReporter } from '../dist/index.mjs';

const fixturesDir = resolve(import.meta.dirname, 'fixtures');

describe('Quarantine runner (dist build)', () => {
beforeEach(() => {
vi.stubEnv('GITHUB_ACTIONS', 'true');
vi.stubEnv('GITHUB_REPOSITORY', 'test-owner/test-repo');
});
afterEach(() => {
vi.unstubAllEnvs();
});

it('quarantined failing test does not fail the run', async () => {
const reporter = new MergifyReporter({
quarantineList: ['failing.test.ts > math > fails intentionally'],
});
const vitest = await startVitest('test', [], {
root: fixturesDir,
include: ['failing.test.ts'],
reporters: [reporter],
watch: false,
});
await vitest?.close();
expect(reporter.getSession()!.status).toBe('passed');
});
});