diff --git a/test/commands/change.interactive-show.test.ts b/test/commands/change.interactive-show.test.ts index 34c6f259..b4dee52d 100644 --- a/test/commands/change.interactive-show.test.ts +++ b/test/commands/change.interactive-show.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -9,9 +9,6 @@ describe('change show (interactive behavior)', () => { const changesDir = path.join(testDir, 'openspec', 'changes'); const bin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(changesDir, { recursive: true }); diff --git a/test/commands/change.interactive-validate.test.ts b/test/commands/change.interactive-validate.test.ts index bd43367c..33484ab2 100644 --- a/test/commands/change.interactive-validate.test.ts +++ b/test/commands/change.interactive-validate.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -12,9 +12,6 @@ describe('change validate (interactive behavior)', () => { const changesDir = path.join(testDir, 'openspec', 'changes'); const bin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(changesDir, { recursive: true }); diff --git a/test/commands/show.test.ts b/test/commands/show.test.ts index c9a9b569..67de310c 100644 --- a/test/commands/show.test.ts +++ b/test/commands/show.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach, afterEach, beforeAll } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -10,9 +10,6 @@ describe('top-level show command', () => { const specsDir = path.join(testDir, 'openspec', 'specs'); const openspecBin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(changesDir, { recursive: true }); diff --git a/test/commands/spec.interactive-show.test.ts b/test/commands/spec.interactive-show.test.ts index fd0be69d..f41fdb63 100644 --- a/test/commands/spec.interactive-show.test.ts +++ b/test/commands/spec.interactive-show.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -9,9 +9,6 @@ describe('spec show (interactive behavior)', () => { const specsDir = path.join(testDir, 'openspec', 'specs'); const bin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(specsDir, { recursive: true }); diff --git a/test/commands/spec.interactive-validate.test.ts b/test/commands/spec.interactive-validate.test.ts index 70d3dc60..14949d6c 100644 --- a/test/commands/spec.interactive-validate.test.ts +++ b/test/commands/spec.interactive-validate.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -9,9 +9,6 @@ describe('spec validate (interactive behavior)', () => { const specsDir = path.join(testDir, 'openspec', 'specs'); const bin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(specsDir, { recursive: true }); diff --git a/test/commands/spec.test.ts b/test/commands/spec.test.ts index 60802cf4..2a93d18f 100644 --- a/test/commands/spec.test.ts +++ b/test/commands/spec.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach, afterEach, beforeAll } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -9,10 +9,6 @@ describe('spec command', () => { const specsDir = path.join(testDir, 'openspec', 'specs'); const openspecBin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - // Ensure CLI is built so bin/openspec.js loads latest logic from dist/ - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(specsDir, { recursive: true }); diff --git a/test/commands/validate.enriched-output.test.ts b/test/commands/validate.enriched-output.test.ts index 6e88ce80..90b4d1b4 100644 --- a/test/commands/validate.enriched-output.test.ts +++ b/test/commands/validate.enriched-output.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -9,10 +9,6 @@ describe('validate command enriched human output', () => { const changesDir = path.join(testDir, 'openspec', 'changes'); const bin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - // Build once so the bin can resolve dist - try { execSync('pnpm -s build', { stdio: 'pipe' }); } catch {} - }); beforeEach(async () => { await fs.mkdir(changesDir, { recursive: true }); diff --git a/test/commands/validate.test.ts b/test/commands/validate.test.ts index 2f536844..5e4254c3 100644 --- a/test/commands/validate.test.ts +++ b/test/commands/validate.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest'; +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { promises as fs } from 'fs'; import path from 'path'; import { execSync } from 'child_process'; @@ -10,9 +10,6 @@ describe('top-level validate command', () => { const specsDir = path.join(testDir, 'openspec', 'specs'); const bin = path.join(projectRoot, 'bin', 'openspec.js'); - beforeAll(() => { - execSync('pnpm -s build', { stdio: 'pipe' }); - }); beforeEach(async () => { await fs.mkdir(changesDir, { recursive: true }); diff --git a/vitest.config.ts b/vitest.config.ts index 5e92c39b..2d6f6588 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,6 +4,7 @@ export default defineConfig({ test: { globals: true, environment: 'node', + globalSetup: './vitest.setup.ts', // Keep default pool settings; some tests rely on process.chdir, // which is not supported in worker threads include: ['test/**/*.test.ts'], diff --git a/vitest.setup.ts b/vitest.setup.ts new file mode 100644 index 00000000..03bc27e7 --- /dev/null +++ b/vitest.setup.ts @@ -0,0 +1,21 @@ +import { execSync } from 'child_process'; +import { existsSync } from 'fs'; +import path from 'path'; + +// Run once before all tests +export async function setup() { + const distPath = path.join(process.cwd(), 'dist', 'cli', 'index.js'); + + if (!existsSync(distPath)) { + console.log('Building project before tests...'); + try { + execSync('pnpm run build', { + stdio: 'inherit', + cwd: process.cwd() + }); + } catch (error) { + console.error('Failed to build project:', error); + process.exit(1); + } + } +} \ No newline at end of file