Skip to content
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
5 changes: 1 addition & 4 deletions test/commands/change.interactive-show.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
5 changes: 1 addition & 4 deletions test/commands/change.interactive-validate.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
5 changes: 1 addition & 4 deletions test/commands/show.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
5 changes: 1 addition & 4 deletions test/commands/spec.interactive-show.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
5 changes: 1 addition & 4 deletions test/commands/spec.interactive-validate.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
6 changes: 1 addition & 5 deletions test/commands/spec.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
6 changes: 1 addition & 5 deletions test/commands/validate.enriched-output.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
5 changes: 1 addition & 4 deletions test/commands/validate.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
21 changes: 21 additions & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading