Skip to content

Commit a3993b5

Browse files
dcramerclaude
andcommitted
refactor(test): Consolidate test utilities with unified index
Add test-utils/index.ts as single import point for shared test utilities. Move createArchivedTask from cli/test-helpers.ts to test-utils/github-mock.ts since it's used by core tests, not just CLI tests. Fixes #91 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9badb62 commit a3993b5

File tree

4 files changed

+68
-24
lines changed

4 files changed

+68
-24
lines changed

src/cli/test-helpers.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,18 @@ import * as os from "node:os";
88
import { execSync } from "node:child_process";
99
import { FileStorage } from "../core/storage/index.js";
1010

11-
import type { ArchivedTask } from "../types.js";
12-
1311
// Re-export shared test utilities from test-utils
1412
export {
1513
setupGitHubMock,
1614
cleanupGitHubMock,
1715
createIssueFixture,
1816
createTask,
1917
createStore,
18+
createArchivedTask,
2019
type GitHubIssueFixture,
2120
type GitHubMock,
2221
} from "../test-utils/github-mock.js";
2322

24-
/**
25-
* Create an ArchivedTask with sensible defaults for testing.
26-
*/
27-
export function createArchivedTask(
28-
overrides: Partial<ArchivedTask> = {},
29-
): ArchivedTask {
30-
return {
31-
id: "test-id",
32-
parent_id: null,
33-
name: "Test archived task",
34-
description: "",
35-
result: null,
36-
completed_at: null,
37-
archived_at: new Date().toISOString(),
38-
metadata: null,
39-
archived_children: [],
40-
...overrides,
41-
};
42-
}
43-
4423
// ============ CLI-specific utilities ============
4524

4625
// Task IDs are 8 lowercase alphanumeric characters

src/core/storage/archive-storage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "node:fs";
33
import * as path from "node:path";
44
import * as os from "node:os";
55
import { ArchiveStorage } from "./archive-storage.js";
6-
import { createArchivedTask } from "../../cli/test-helpers.js";
6+
import { createArchivedTask } from "../../test-utils/index.js";
77
import type { ArchivedTask } from "../../types.js";
88

99
describe("ArchiveStorage", () => {

src/test-utils/github-mock.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import nock from "nock";
7-
import type { Task, TaskStore } from "../types.js";
7+
import type { ArchivedTask, Task, TaskStore } from "../types.js";
88

99
// ============ GitHub API Mocking ============
1010

@@ -359,3 +359,23 @@ export function createTask(overrides: Partial<Task> = {}): Task {
359359
export function createStore(tasks: Task[] = []): TaskStore {
360360
return { tasks };
361361
}
362+
363+
/**
364+
* Create an ArchivedTask with sensible defaults for testing.
365+
*/
366+
export function createArchivedTask(
367+
overrides: Partial<ArchivedTask> = {},
368+
): ArchivedTask {
369+
return {
370+
id: "test-id",
371+
parent_id: null,
372+
name: "Test archived task",
373+
description: "",
374+
result: null,
375+
completed_at: null,
376+
archived_at: new Date().toISOString(),
377+
metadata: null,
378+
archived_children: [],
379+
...overrides,
380+
};
381+
}

src/test-utils/index.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Unified test utilities for all dex tests.
3+
*
4+
* This module re-exports all shared test utilities from a single location.
5+
* Import from here for general test utilities:
6+
*
7+
* import { createTask, testEnv, setupGitHubMock } from "../test-utils/index.js";
8+
*
9+
* For domain-specific test utilities, use the specialized modules:
10+
* - CLI tests: import from "../cli/test-helpers.js"
11+
* - MCP tests: import from "../mcp/test-helpers.js"
12+
*/
13+
14+
// Test environment setup
15+
export {
16+
testEnv,
17+
initTestEnv,
18+
cleanupTestEnv,
19+
type TestEnv,
20+
} from "./test-env.js";
21+
22+
// Vitest re-exports for convenience
23+
export {
24+
describe,
25+
it,
26+
test,
27+
expect,
28+
beforeEach,
29+
afterEach,
30+
beforeAll,
31+
afterAll,
32+
vi,
33+
} from "./test-env.js";
34+
35+
// GitHub API mocking and task fixtures
36+
export {
37+
setupGitHubMock,
38+
cleanupGitHubMock,
39+
createIssueFixture,
40+
createTask,
41+
createStore,
42+
createArchivedTask,
43+
type GitHubIssueFixture,
44+
type GitHubMock,
45+
} from "./github-mock.js";

0 commit comments

Comments
 (0)