Skip to content

Commit 57216a7

Browse files
committed
refactor(test): use vitest globalSetup for build instead of per-test builds
1 parent 6e210cf commit 57216a7

11 files changed

+30
-76
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
3-
import { ensureBuild } from '../helpers/ensure-build.js';
43
import path from 'path';
54
import { execSync } from 'child_process';
65

@@ -10,9 +9,6 @@ describe('change show (interactive behavior)', () => {
109
const changesDir = path.join(testDir, 'openspec', 'changes');
1110
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1211

13-
beforeAll(() => {
14-
ensureBuild();
15-
});
1612

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
3-
import { ensureBuild } from '../helpers/ensure-build.js';
43
import path from 'path';
54
import { execSync } from 'child_process';
65

@@ -13,9 +12,6 @@ describe('change validate (interactive behavior)', () => {
1312
const changesDir = path.join(testDir, 'openspec', 'changes');
1413
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1514

16-
beforeAll(() => {
17-
ensureBuild();
18-
});
1915

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

test/commands/show.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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';
5-
import { ensureBuild } from '../helpers/ensure-build.js';
65

76
describe('top-level show command', () => {
87
const projectRoot = process.cwd();
@@ -11,9 +10,6 @@ describe('top-level show command', () => {
1110
const specsDir = path.join(testDir, 'openspec', 'specs');
1211
const openspecBin = path.join(projectRoot, 'bin', 'openspec.js');
1312

14-
beforeAll(() => {
15-
ensureBuild();
16-
});
1713

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
3-
import { ensureBuild } from '../helpers/ensure-build.js';
43
import path from 'path';
54
import { execSync } from 'child_process';
65

@@ -10,9 +9,6 @@ describe('spec show (interactive behavior)', () => {
109
const specsDir = path.join(testDir, 'openspec', 'specs');
1110
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1211

13-
beforeAll(() => {
14-
ensureBuild();
15-
});
1612

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
3-
import { ensureBuild } from '../helpers/ensure-build.js';
43
import path from 'path';
54
import { execSync } from 'child_process';
65

@@ -10,9 +9,6 @@ describe('spec validate (interactive behavior)', () => {
109
const specsDir = path.join(testDir, 'openspec', 'specs');
1110
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1211

13-
beforeAll(() => {
14-
ensureBuild();
15-
});
1612

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

test/commands/spec.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
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';
5-
import { ensureBuild } from '../helpers/ensure-build.js';
65

76
describe('spec command', () => {
87
const projectRoot = process.cwd();
98
const testDir = path.join(projectRoot, 'test-spec-command-tmp');
109
const specsDir = path.join(testDir, 'openspec', 'specs');
1110
const openspecBin = path.join(projectRoot, 'bin', 'openspec.js');
1211

13-
beforeAll(() => {
14-
// Ensure CLI is built so bin/openspec.js loads latest logic from dist/
15-
ensureBuild();
16-
});
1712

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

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
3-
import { ensureBuild } from '../helpers/ensure-build.js';
43
import path from 'path';
54
import { execSync } from 'child_process';
65

@@ -10,10 +9,6 @@ describe('validate command enriched human output', () => {
109
const changesDir = path.join(testDir, 'openspec', 'changes');
1110
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1211

13-
beforeAll(() => {
14-
// Build once so the bin can resolve dist
15-
try { ensureBuild(); } catch {}
16-
});
1712

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

test/commands/validate.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
3-
import { ensureBuild } from '../helpers/ensure-build.js';
43
import path from 'path';
54
import { execSync } from 'child_process';
65

@@ -11,9 +10,6 @@ describe('top-level validate command', () => {
1110
const specsDir = path.join(testDir, 'openspec', 'specs');
1211
const bin = path.join(projectRoot, 'bin', 'openspec.js');
1312

14-
beforeAll(() => {
15-
ensureBuild();
16-
});
1713

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

test/helpers/ensure-build.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

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'],

0 commit comments

Comments
 (0)