test: prebuild dist before vitest

This commit is contained in:
Peter Steinberger 2026-05-09 12:30:11 +01:00
parent 9aab8df289
commit 3648a92b2b
No known key found for this signature in database
7 changed files with 23 additions and 64 deletions

View File

@ -28,6 +28,10 @@
splitting them as inline command strings, so app bundle helpers like Hopper's
MCP server can be configured directly.
### Tooling
- Build `dist/` once before the Vitest suite instead of letting parallel integration tests rebuild it mid-run.
## [0.10.1] - 2026-05-04
### CLI

View File

@ -52,7 +52,7 @@
"typecheck": "tsgo --project tsconfig.json --noEmit",
"test": "cross-env MCPORTER_TEST_REPORTER=quiet pnpm test:verbose",
"test:quiet": "cross-env MCPORTER_TEST_REPORTER=quiet pnpm test:verbose",
"test:verbose": "node scripts/test-runner.js",
"test:verbose": "pnpm build && node scripts/test-runner.js",
"test:live": "MCP_LIVE_TESTS=1 vitest run tests/live",
"clean": "rimraf dist",
"dev": "tsgo -w -p tsconfig.build.json",

View File

@ -8,30 +8,16 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
const CLI_ENTRY = fileURLToPath(new URL('../dist/cli.js', import.meta.url));
const PNPM_COMMAND = process.platform === 'win32' ? 'cmd.exe' : 'pnpm';
const PNPM_ARGS_PREFIX = process.platform === 'win32' ? ['/d', '/s', '/c', 'pnpm'] : [];
const testRequire = createRequire(import.meta.url);
const MCP_SERVER_MODULE = pathToFileURL(testRequire.resolve('@modelcontextprotocol/sdk/server/mcp.js')).href;
const STDIO_SERVER_MODULE = pathToFileURL(testRequire.resolve('@modelcontextprotocol/sdk/server/stdio.js')).href;
const ZOD_MODULE = pathToFileURL(path.join(process.cwd(), 'node_modules', 'zod', 'index.js')).href;
function pnpmArgs(args: string[]): string[] {
return [...PNPM_ARGS_PREFIX, ...args];
}
async function ensureDistBuilt(): Promise<void> {
try {
await fs.access(CLI_ENTRY);
} catch {
await new Promise<void>((resolve, reject) => {
execFile(PNPM_COMMAND, pnpmArgs(['build']), { cwd: process.cwd(), env: process.env }, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
throw new Error('dist/cli.js is missing; run `pnpm build` before invoking this integration test directly.');
}
}

View File

@ -25,15 +25,11 @@ function pnpmArgs(args: string[]): string[] {
}
async function ensureDistBuilt(): Promise<void> {
await new Promise<void>((resolve, reject) => {
execFile(PNPM_COMMAND, pnpmArgs(['build']), { cwd: process.cwd(), env: process.env }, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
try {
await fs.access(CLI_ENTRY);
} catch {
throw new Error('dist/cli.js is missing; run `pnpm build` before invoking this integration test directly.');
}
}
async function hasBun(): Promise<boolean> {

View File

@ -12,12 +12,6 @@ const MCP_SERVER_MODULE = pathToFileURL(testRequire.resolve('@modelcontextprotoc
const STDIO_SERVER_MODULE = pathToFileURL(testRequire.resolve('@modelcontextprotocol/sdk/server/stdio.js')).href;
const ZOD_MODULE = pathToFileURL(testRequire.resolve('zod')).href;
const describeDaemon = process.platform === 'win32' ? describe.skip : describe;
const PNPM_COMMAND = process.platform === 'win32' ? 'cmd.exe' : 'pnpm';
const PNPM_ARGS_PREFIX = process.platform === 'win32' ? ['/d', '/s', '/c', 'pnpm'] : [];
function pnpmArgs(args: string[]): string[] {
return [...PNPM_ARGS_PREFIX, ...args];
}
async function readFileWithRetries(filePath: string, retries = 20, delayMs = 100): Promise<string> {
let lastError: unknown;
@ -39,15 +33,7 @@ async function ensureDistBuilt(): Promise<void> {
try {
await fs.access(CLI_ENTRY);
} catch {
await new Promise<void>((resolve, reject) => {
execFile(PNPM_COMMAND, pnpmArgs(['build']), { cwd: process.cwd(), env: process.env }, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
throw new Error('dist/cli.js is missing; run `pnpm build` before invoking this integration test directly.');
}
}

View File

@ -14,6 +14,15 @@ const describeGenerateCli = process.platform === 'win32' ? describe.skip : descr
let baseUrl: URL;
const tmpDir = path.join(process.cwd(), 'tmp', 'mcporter-cli-tests');
const CLI_ENTRY = path.join(process.cwd(), 'dist', 'cli.js');
async function ensureDistBuilt(): Promise<void> {
try {
await fs.access(CLI_ENTRY);
} catch {
throw new Error('dist/cli.js is missing; run `pnpm build` before invoking this integration test directly.');
}
}
if (process.platform !== 'win32') {
beforeAll(async () => {
@ -199,15 +208,7 @@ describeGenerateCli('generateCli', () => {
console.warn('bun is not available on this runner; skipping compilation checks.');
return;
}
await new Promise<void>((resolve, reject) => {
exec.exec('pnpm build', execOptions(), (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
await ensureDistBuilt();
const expectedBinaryPath = path.join(tmpDir, 'integration');
const {

View File

@ -7,26 +7,12 @@ import { fileURLToPath } from 'node:url';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
const CLI_ENTRY = fileURLToPath(new URL('../dist/cli.js', import.meta.url));
const PNPM_COMMAND = process.platform === 'win32' ? 'cmd.exe' : 'pnpm';
const PNPM_ARGS_PREFIX = process.platform === 'win32' ? ['/d', '/s', '/c', 'pnpm'] : [];
function pnpmArgs(args: string[]): string[] {
return [...PNPM_ARGS_PREFIX, ...args];
}
async function ensureDistBuilt(): Promise<void> {
try {
await fs.access(CLI_ENTRY);
} catch {
await new Promise<void>((resolve, reject) => {
execFile(PNPM_COMMAND, pnpmArgs(['build']), { cwd: process.cwd(), env: process.env }, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
throw new Error('dist/cli.js is missing; run `pnpm build` before invoking this integration test directly.');
}
}