Skip to content

Commit 02fe5b3

Browse files
authored
Merge pull request #56 from Fission-AI/fix-tests
fix(test): resolve CI test failures with proper build setup
2 parents 5c6ae8e + 57216a7 commit 02fe5b3

10 files changed

+30
-34
lines changed

test/commands/change.interactive-show.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -9,9 +9,6 @@ describe('change show (interactive behavior)', () => {
99
const changesDir = path.join(testDir, 'openspec', 'changes');
1010
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1111

12-
beforeAll(() => {
13-
execSync('pnpm -s build', { stdio: 'pipe' });
14-
});
1512

1613
beforeEach(async () => {
1714
await fs.mkdir(changesDir, { recursive: true });

test/commands/change.interactive-validate.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -12,9 +12,6 @@ describe('change validate (interactive behavior)', () => {
1212
const changesDir = path.join(testDir, 'openspec', 'changes');
1313
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1414

15-
beforeAll(() => {
16-
execSync('pnpm -s build', { stdio: 'pipe' });
17-
});
1815

1916
beforeEach(async () => {
2017
await fs.mkdir(changesDir, { recursive: true });

test/commands/show.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach, beforeAll } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -10,9 +10,6 @@ describe('top-level show command', () => {
1010
const specsDir = path.join(testDir, 'openspec', 'specs');
1111
const openspecBin = path.join(projectRoot, 'bin', 'openspec.js');
1212

13-
beforeAll(() => {
14-
execSync('pnpm -s build', { stdio: 'pipe' });
15-
});
1613

1714
beforeEach(async () => {
1815
await fs.mkdir(changesDir, { recursive: true });

test/commands/spec.interactive-show.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -9,9 +9,6 @@ describe('spec show (interactive behavior)', () => {
99
const specsDir = path.join(testDir, 'openspec', 'specs');
1010
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1111

12-
beforeAll(() => {
13-
execSync('pnpm -s build', { stdio: 'pipe' });
14-
});
1512

1613
beforeEach(async () => {
1714
await fs.mkdir(specsDir, { recursive: true });

test/commands/spec.interactive-validate.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -9,9 +9,6 @@ describe('spec validate (interactive behavior)', () => {
99
const specsDir = path.join(testDir, 'openspec', 'specs');
1010
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1111

12-
beforeAll(() => {
13-
execSync('pnpm -s build', { stdio: 'pipe' });
14-
});
1512

1613
beforeEach(async () => {
1714
await fs.mkdir(specsDir, { recursive: true });

test/commands/spec.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach, beforeAll } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -9,10 +9,6 @@ describe('spec command', () => {
99
const specsDir = path.join(testDir, 'openspec', 'specs');
1010
const openspecBin = path.join(projectRoot, 'bin', 'openspec.js');
1111

12-
beforeAll(() => {
13-
// Ensure CLI is built so bin/openspec.js loads latest logic from dist/
14-
execSync('pnpm -s build', { stdio: 'pipe' });
15-
});
1612

1713
beforeEach(async () => {
1814
await fs.mkdir(specsDir, { recursive: true });

test/commands/validate.enriched-output.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -9,10 +9,6 @@ describe('validate command enriched human output', () => {
99
const changesDir = path.join(testDir, 'openspec', 'changes');
1010
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1111

12-
beforeAll(() => {
13-
// Build once so the bin can resolve dist
14-
try { execSync('pnpm -s build', { stdio: 'pipe' }); } catch {}
15-
});
1612

1713
beforeEach(async () => {
1814
await fs.mkdir(changesDir, { recursive: true });

test/commands/validate.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
44
import { execSync } from 'child_process';
@@ -10,9 +10,6 @@ describe('top-level validate command', () => {
1010
const specsDir = path.join(testDir, 'openspec', 'specs');
1111
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1212

13-
beforeAll(() => {
14-
execSync('pnpm -s build', { stdio: 'pipe' });
15-
});
1613

1714
beforeEach(async () => {
1815
await fs.mkdir(changesDir, { recursive: true });

vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default defineConfig({
44
test: {
55
globals: true,
66
environment: 'node',
7+
globalSetup: './vitest.setup.ts',
78
// Keep default pool settings; some tests rely on process.chdir,
89
// which is not supported in worker threads
910
include: ['test/**/*.test.ts'],

vitest.setup.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { execSync } from 'child_process';
2+
import { existsSync } from 'fs';
3+
import path from 'path';
4+
5+
// Run once before all tests
6+
export async function setup() {
7+
const distPath = path.join(process.cwd(), 'dist', 'cli', 'index.js');
8+
9+
if (!existsSync(distPath)) {
10+
console.log('Building project before tests...');
11+
try {
12+
execSync('pnpm run build', {
13+
stdio: 'inherit',
14+
cwd: process.cwd()
15+
});
16+
} catch (error) {
17+
console.error('Failed to build project:', error);
18+
process.exit(1);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)