@jamesaphoenix/tx-test-utils 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +480 -0
- package/dist/adapters/better-sqlite3-adapter.d.ts +36 -0
- package/dist/adapters/better-sqlite3-adapter.d.ts.map +1 -0
- package/dist/adapters/better-sqlite3-adapter.js +78 -0
- package/dist/adapters/better-sqlite3-adapter.js.map +1 -0
- package/dist/chaos/chaos-utilities.d.ts +465 -0
- package/dist/chaos/chaos-utilities.d.ts.map +1 -0
- package/dist/chaos/chaos-utilities.js +793 -0
- package/dist/chaos/chaos-utilities.js.map +1 -0
- package/dist/chaos/chaos.test.d.ts +9 -0
- package/dist/chaos/chaos.test.d.ts.map +1 -0
- package/dist/chaos/chaos.test.js +498 -0
- package/dist/chaos/chaos.test.js.map +1 -0
- package/dist/chaos/index.d.ts +20 -0
- package/dist/chaos/index.d.ts.map +1 -0
- package/dist/chaos/index.js +39 -0
- package/dist/chaos/index.js.map +1 -0
- package/dist/database/index.d.ts +1 -1
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +1 -1
- package/dist/database/index.js.map +1 -1
- package/dist/database/test-database.d.ts +25 -5
- package/dist/database/test-database.d.ts.map +1 -1
- package/dist/database/test-database.js +142 -11
- package/dist/database/test-database.js.map +1 -1
- package/dist/factories/index.d.ts +0 -3
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/factories/index.js +0 -6
- package/dist/factories/index.js.map +1 -1
- package/dist/factories/learning.factory.js +1 -1
- package/dist/factories/learning.factory.js.map +1 -1
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/shared-test-layer.d.ts +74 -0
- package/dist/helpers/shared-test-layer.d.ts.map +1 -0
- package/dist/helpers/shared-test-layer.js +104 -0
- package/dist/helpers/shared-test-layer.js.map +1 -0
- package/dist/helpers/sqlite-factory.d.ts +49 -0
- package/dist/helpers/sqlite-factory.d.ts.map +1 -0
- package/dist/helpers/sqlite-factory.js +74 -0
- package/dist/helpers/sqlite-factory.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/dist/singleton.d.ts +49 -0
- package/dist/singleton.d.ts.map +1 -0
- package/dist/singleton.js +66 -0
- package/dist/singleton.js.map +1 -0
- package/package.json +11 -10
- package/dist/factories/factories.test.d.ts +0 -8
- package/dist/factories/factories.test.d.ts.map +0 -1
- package/dist/factories/factories.test.js +0 -419
- package/dist/factories/factories.test.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite database factory for tests.
|
|
3
|
+
*
|
|
4
|
+
* Creates SqliteDatabase instances that work with both Vitest (better-sqlite3)
|
|
5
|
+
* and Bun test (bun:sqlite). Tests should use this instead of directly importing
|
|
6
|
+
* from "bun:sqlite".
|
|
7
|
+
*
|
|
8
|
+
* Uses the SqliteDatabase interface from @tx/core, which is what SqliteClient
|
|
9
|
+
* provides via Effect layers. This means databases created here can be used
|
|
10
|
+
* directly with Layer.succeed(SqliteClient, db) — no `as any` needed.
|
|
11
|
+
*
|
|
12
|
+
* @module @tx/test-utils/helpers/sqlite-factory
|
|
13
|
+
*/
|
|
14
|
+
import type { SqliteDatabase } from "@jamesaphoenix/tx-core";
|
|
15
|
+
/**
|
|
16
|
+
* Create a SqliteDatabase instance.
|
|
17
|
+
*
|
|
18
|
+
* - Under Vitest: uses better-sqlite3, wrapped via the adapter
|
|
19
|
+
* - Under Bun test: uses bun:sqlite
|
|
20
|
+
*
|
|
21
|
+
* PRAGMAs (journal_mode, foreign_keys, busy_timeout) are set automatically.
|
|
22
|
+
* Migrations are NOT applied — call applyMigrations(db) yourself if needed.
|
|
23
|
+
*
|
|
24
|
+
* @param path - Database file path, or ":memory:" (default)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { createSqliteDatabase } from "@jamesaphoenix/tx-test-utils"
|
|
29
|
+
* import { applyMigrations, SqliteClient } from "@jamesaphoenix/tx-core"
|
|
30
|
+
* import { Layer } from "effect"
|
|
31
|
+
*
|
|
32
|
+
* // Raw database for migration tests
|
|
33
|
+
* const db = await createSqliteDatabase()
|
|
34
|
+
* applyMigrations(db)
|
|
35
|
+
*
|
|
36
|
+
* // Use with Effect layers
|
|
37
|
+
* const infra = Layer.succeed(SqliteClient, db)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const createSqliteDatabase: (path?: string) => Promise<SqliteDatabase>;
|
|
41
|
+
/**
|
|
42
|
+
* Create a SqliteDatabase with all migrations applied.
|
|
43
|
+
*
|
|
44
|
+
* Convenience wrapper around createSqliteDatabase + applyMigrations.
|
|
45
|
+
*
|
|
46
|
+
* @param path - Database file path, or ":memory:" (default)
|
|
47
|
+
*/
|
|
48
|
+
export declare const createMigratedSqliteDatabase: (path?: string) => Promise<SqliteDatabase>;
|
|
49
|
+
//# sourceMappingURL=sqlite-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-factory.d.ts","sourceRoot":"","sources":["../../src/helpers/sqlite-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAQ5D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAM,MAAmB,KACxB,OAAO,CAAC,cAAc,CAkBxB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GACvC,OAAM,MAAmB,KACxB,OAAO,CAAC,cAAc,CAKxB,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite database factory for tests.
|
|
3
|
+
*
|
|
4
|
+
* Creates SqliteDatabase instances that work with both Vitest (better-sqlite3)
|
|
5
|
+
* and Bun test (bun:sqlite). Tests should use this instead of directly importing
|
|
6
|
+
* from "bun:sqlite".
|
|
7
|
+
*
|
|
8
|
+
* Uses the SqliteDatabase interface from @tx/core, which is what SqliteClient
|
|
9
|
+
* provides via Effect layers. This means databases created here can be used
|
|
10
|
+
* directly with Layer.succeed(SqliteClient, db) — no `as any` needed.
|
|
11
|
+
*
|
|
12
|
+
* @module @tx/test-utils/helpers/sqlite-factory
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Detect whether we're running under Vitest (better-sqlite3) or Bun test (bun:sqlite).
|
|
16
|
+
*/
|
|
17
|
+
const isVitest = () => typeof process !== "undefined" && process.env.VITEST === "true";
|
|
18
|
+
/**
|
|
19
|
+
* Create a SqliteDatabase instance.
|
|
20
|
+
*
|
|
21
|
+
* - Under Vitest: uses better-sqlite3, wrapped via the adapter
|
|
22
|
+
* - Under Bun test: uses bun:sqlite
|
|
23
|
+
*
|
|
24
|
+
* PRAGMAs (journal_mode, foreign_keys, busy_timeout) are set automatically.
|
|
25
|
+
* Migrations are NOT applied — call applyMigrations(db) yourself if needed.
|
|
26
|
+
*
|
|
27
|
+
* @param path - Database file path, or ":memory:" (default)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { createSqliteDatabase } from "@jamesaphoenix/tx-test-utils"
|
|
32
|
+
* import { applyMigrations, SqliteClient } from "@jamesaphoenix/tx-core"
|
|
33
|
+
* import { Layer } from "effect"
|
|
34
|
+
*
|
|
35
|
+
* // Raw database for migration tests
|
|
36
|
+
* const db = await createSqliteDatabase()
|
|
37
|
+
* applyMigrations(db)
|
|
38
|
+
*
|
|
39
|
+
* // Use with Effect layers
|
|
40
|
+
* const infra = Layer.succeed(SqliteClient, db)
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const createSqliteDatabase = async (path = ":memory:") => {
|
|
44
|
+
if (isVitest()) {
|
|
45
|
+
const { wrapBetterSqlite3 } = await import("../adapters/better-sqlite3-adapter.js");
|
|
46
|
+
const Database = (await import("better-sqlite3")).default;
|
|
47
|
+
const raw = new Database(path);
|
|
48
|
+
raw.pragma("journal_mode = WAL");
|
|
49
|
+
raw.pragma("foreign_keys = ON");
|
|
50
|
+
raw.pragma("busy_timeout = " + (process.env.TX_DB_BUSY_TIMEOUT || "5000"));
|
|
51
|
+
return wrapBetterSqlite3(raw);
|
|
52
|
+
}
|
|
53
|
+
// Bun test
|
|
54
|
+
const { Database } = await import("bun:sqlite");
|
|
55
|
+
const raw = new Database(path);
|
|
56
|
+
raw.run("PRAGMA journal_mode = WAL");
|
|
57
|
+
raw.run("PRAGMA foreign_keys = ON");
|
|
58
|
+
raw.run("PRAGMA busy_timeout = " + (process.env.TX_DB_BUSY_TIMEOUT || "5000"));
|
|
59
|
+
return raw;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Create a SqliteDatabase with all migrations applied.
|
|
63
|
+
*
|
|
64
|
+
* Convenience wrapper around createSqliteDatabase + applyMigrations.
|
|
65
|
+
*
|
|
66
|
+
* @param path - Database file path, or ":memory:" (default)
|
|
67
|
+
*/
|
|
68
|
+
export const createMigratedSqliteDatabase = async (path = ":memory:") => {
|
|
69
|
+
const { applyMigrations } = await import("@jamesaphoenix/tx-core");
|
|
70
|
+
const db = await createSqliteDatabase(path);
|
|
71
|
+
applyMigrations(db);
|
|
72
|
+
return db;
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=sqlite-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-factory.js","sourceRoot":"","sources":["../../src/helpers/sqlite-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;GAEG;AACH,MAAM,QAAQ,GAAG,GAAY,EAAE,CAC7B,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO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AM,MAAM,CAAC,wBAAwB,CAAC,CAAA;IAClE,MAAM,EAAE,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAC3C,eAAe,CAAC,EAAE,CAAC,CAAA;IACnB,OAAO,EAAE,CAAA;AACX,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,11 +16,15 @@
|
|
|
16
16
|
* @module @tx/test-utils
|
|
17
17
|
*/
|
|
18
18
|
export { fixtureId, namespacedFixtureId, sequentialFixtureIds, contentFixtureId } from "./fixtures/index.js";
|
|
19
|
-
export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer } from "./database/index.js";
|
|
19
|
+
export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer, wrapDbAsTestDatabase } from "./database/index.js";
|
|
20
20
|
export type { TestDatabase } from "./database/index.js";
|
|
21
|
-
export { TaskFactory, createTestTask, createTestTasks, type CreateTaskOptions, LearningFactory, createTestLearning, createTestLearnings, type CreateLearningOptions,
|
|
21
|
+
export { TaskFactory, createTestTask, createTestTasks, type CreateTaskOptions, LearningFactory, createTestLearning, createTestLearnings, type CreateLearningOptions, } from "./factories/index.js";
|
|
22
22
|
export { hashInput, cachedLLMCall, withLLMCache, configureLLMCache, getCacheConfig, resetCacheConfig, getCacheStats, clearCache, formatCacheStats, getCacheEntry, listCacheEntries } from "./llm-cache/index.js";
|
|
23
23
|
export type { CacheEntry, CachedLLMCallOptions, WithLLMCacheOptions, CacheStats, ClearCacheOptions } from "./llm-cache/index.js";
|
|
24
24
|
export { runEffect, runEffectFail, runEffectEither, expectEffectSuccess, expectEffectFailure, mergeLayers, createTestContext, type RunEffectOptions, type EffectResult } from "./helpers/index.js";
|
|
25
|
+
export { createSharedTestLayer, type SharedTestLayer, type SharedTestLayerResult } from "./helpers/index.js";
|
|
26
|
+
export { createSqliteDatabase, createMigratedSqliteDatabase } from "./helpers/index.js";
|
|
27
|
+
export { getSharedTestLayer, resetTestDb, closeTestDb, isTestDbInitialized } from "./singleton.js";
|
|
25
28
|
export { createMockAnthropic, createMockAnthropicForExtraction, type MockMessage, type MockAnthropicCall, type MockAnthropicResponse, type MockAnthropicConfig, type MockAnthropicResult, createMockOpenAI, createMockOpenAIForExtraction, createMockOpenAIForExtractionRaw, type MockOpenAIMessage, type MockOpenAIChatCall, type MockOpenAIChatResponse, type MockOpenAIConfig, type MockOpenAIResult } from "./mocks/index.js";
|
|
29
|
+
export { chaos, crashAfter, CrashSimulationError, type CrashAfterOptions, type CrashAfterResult, killHeartbeat, WorkerHeartbeatController, type KillHeartbeatOptions, raceWorkers, type RaceWorkersOptions, type RaceWorkersResult, corruptState, type CorruptStateOptions, type CorruptionType, replayJSONL, type ReplayJSONLOptions, type ReplayJSONLResult, type SyncOperation, doubleComplete, type DoubleCompleteOptions, type DoubleCompleteResult, partialWrite, type PartialWriteOptions, type PartialWriteResult, delayedClaim, type DelayedClaimOptions, type DelayedClaimResult, stressLoad, type StressLoadOptions, type StressLoadResult } from "./chaos/index.js";
|
|
26
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gB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ACrB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAA;AASzB,OAAO,EAEL,KAAK,EAEL,UAAU,EACV,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAErB,aAAa,EACb,yBAAyB,EACzB,KAAK,oBAAoB,EAEzB,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEtB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAEnB,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAElB,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAEzB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -18,19 +18,13 @@
|
|
|
18
18
|
// Fixtures - SHA256-based deterministic IDs
|
|
19
19
|
export { fixtureId, namespacedFixtureId, sequentialFixtureIds, contentFixtureId } from "./fixtures/index.js";
|
|
20
20
|
// Database helpers
|
|
21
|
-
export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer } from "./database/index.js";
|
|
21
|
+
export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer, wrapDbAsTestDatabase } from "./database/index.js";
|
|
22
22
|
// Factories
|
|
23
23
|
export {
|
|
24
24
|
// Task
|
|
25
25
|
TaskFactory, createTestTask, createTestTasks,
|
|
26
26
|
// Learning
|
|
27
|
-
LearningFactory, createTestLearning, createTestLearnings,
|
|
28
|
-
// Edge
|
|
29
|
-
EdgeFactory, createTestEdge, createEdgeBetweenLearnings,
|
|
30
|
-
// Anchor
|
|
31
|
-
AnchorFactory, createTestAnchor,
|
|
32
|
-
// Candidate
|
|
33
|
-
CandidateFactory, createTestCandidate } from "./factories/index.js";
|
|
27
|
+
LearningFactory, createTestLearning, createTestLearnings, } from "./factories/index.js";
|
|
34
28
|
// LLM Cache - SHA256-based response caching
|
|
35
29
|
export {
|
|
36
30
|
// Core functions
|
|
@@ -39,6 +33,12 @@ hashInput, cachedLLMCall, withLLMCache, configureLLMCache, getCacheConfig, reset
|
|
|
39
33
|
getCacheStats, clearCache, formatCacheStats, getCacheEntry, listCacheEntries } from "./llm-cache/index.js";
|
|
40
34
|
// Effect Helpers
|
|
41
35
|
export { runEffect, runEffectFail, runEffectEither, expectEffectSuccess, expectEffectFailure, mergeLayers, createTestContext } from "./helpers/index.js";
|
|
36
|
+
// Shared Test Layer - memory-efficient integration testing
|
|
37
|
+
export { createSharedTestLayer } from "./helpers/index.js";
|
|
38
|
+
// SQLite database factory — creates SqliteDatabase for both Vitest and Bun test
|
|
39
|
+
export { createSqliteDatabase, createMigratedSqliteDatabase } from "./helpers/index.js";
|
|
40
|
+
// Singleton Test Database - ONE DB for entire test suite
|
|
41
|
+
export { getSharedTestLayer, resetTestDb, closeTestDb, isTestDbInitialized } from "./singleton.js";
|
|
42
42
|
// Temp Files (to be implemented)
|
|
43
43
|
// export { createTempDir, writeTestTypeScriptFile, createTestSourceFiles } from './helpers/index.js'
|
|
44
44
|
// export type { TempDir } from './helpers/index.js'
|
|
@@ -49,4 +49,26 @@ export { createMockAnthropic, createMockAnthropicForExtraction, createMockOpenAI
|
|
|
49
49
|
// export { MockFileSystem } from './mocks/index.js'
|
|
50
50
|
// Setup (to be implemented)
|
|
51
51
|
// export { default as vitestSetup } from './setup/index.js'
|
|
52
|
+
// Chaos Engineering Utilities
|
|
53
|
+
export {
|
|
54
|
+
// Namespace export
|
|
55
|
+
chaos,
|
|
56
|
+
// Process failure simulation
|
|
57
|
+
crashAfter, CrashSimulationError,
|
|
58
|
+
// Worker heartbeat manipulation
|
|
59
|
+
killHeartbeat, WorkerHeartbeatController,
|
|
60
|
+
// Race condition testing
|
|
61
|
+
raceWorkers,
|
|
62
|
+
// State corruption
|
|
63
|
+
corruptState,
|
|
64
|
+
// JSONL replay
|
|
65
|
+
replayJSONL,
|
|
66
|
+
// Double completion testing
|
|
67
|
+
doubleComplete,
|
|
68
|
+
// Partial write simulation
|
|
69
|
+
partialWrite,
|
|
70
|
+
// Delayed claim testing
|
|
71
|
+
delayedClaim,
|
|
72
|
+
// Stress testing
|
|
73
|
+
stressLoad } from "./chaos/index.js";
|
|
52
74
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAE5B,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAE5B,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,qBAAqB,CAAA;AAG5B,YAAY;AACZ,OAAO;AACL,OAAO;AACP,WAAW,EACX,cAAc,EACd,eAAe;AAEf,WAAW;AACX,eAAe,EACf,kBAAkB,EAClB,mBAAmB,GAEpB,MAAM,sBAAsB,CAAA;AAE7B,4CAA4C;AAC5C,OAAO;AACL,iBAAiB;AACjB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB;AAChB,gBAAgB;AAChB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAS7B,iBAAiB;AACjB,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EAGlB,MAAM,oBAAoB,CAAA;AAE3B,2DAA2D;AAC3D,OAAO,EACL,qBAAqB,EAGtB,MAAM,oBAAoB,CAAA;AAE3B,gFAAgF;AAChF,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,oBAAoB,CAAA;AAE3B,yDAAyD;AACzD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,gBAAgB,CAAA;AAEvB,iCAAiC;AACjC,qGAAqG;AACrG,oDAAoD;AAEpD,QAAQ;AACR,OAAO,EACL,mBAAmB,EACnB,gCAAgC,EAMhC,gBAAgB,EAChB,6BAA6B,EAC7B,gCAAgC,EAMjC,MAAM,kBAAkB,CAAA;AACzB,gDAAgD;AAChD,wDAAwD;AACxD,oDAAoD;AAEpD,4BAA4B;AAC5B,4DAA4D;AAE5D,8BAA8B;AAC9B,OAAO;AACL,mBAAmB;AACnB,KAAK;AACL,6BAA6B;AAC7B,UAAU,EACV,oBAAoB;AAGpB,gCAAgC;AAChC,aAAa,EACb,yBAAyB;AAEzB,yBAAyB;AACzB,WAAW;AAGX,mBAAmB;AACnB,YAAY;AAGZ,eAAe;AACf,WAAW;AAIX,4BAA4B;AAC5B,cAAc;AAGd,2BAA2B;AAC3B,YAAY;AAGZ,wBAAwB;AACxB,YAAY;AAGZ,iBAAiB;AACjB,UAAU,EAGX,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Singleton test database for maximum memory efficiency.
|
|
3
|
+
*
|
|
4
|
+
* Instead of creating a new database per test or per describe block,
|
|
5
|
+
* this module provides a single shared database instance for the entire test suite.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* - Tests call `getSharedTestLayer()` to get the singleton
|
|
9
|
+
* - Global `afterEach` in vitest.setup.ts calls `resetTestDb()` for isolation
|
|
10
|
+
* - Global `afterAll` calls `closeTestDb()` for cleanup
|
|
11
|
+
*
|
|
12
|
+
* @module @tx/test-utils/singleton
|
|
13
|
+
*/
|
|
14
|
+
import { type SharedTestLayerResult } from "./helpers/shared-test-layer.js";
|
|
15
|
+
/**
|
|
16
|
+
* Get the singleton test database layer.
|
|
17
|
+
* Creates it on first call, returns cached instance thereafter.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { getSharedTestLayer } from '@jamesaphoenix/tx-test-utils'
|
|
22
|
+
*
|
|
23
|
+
* it("test", async () => {
|
|
24
|
+
* const { layer } = await getSharedTestLayer()
|
|
25
|
+
* const result = await Effect.runPromise(
|
|
26
|
+
* myEffect.pipe(Effect.provide(layer))
|
|
27
|
+
* )
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const getSharedTestLayer: () => Promise<SharedTestLayerResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Reset all tables in the singleton DB.
|
|
34
|
+
* Call in afterEach to ensure test isolation.
|
|
35
|
+
* Safe to call even if DB hasn't been initialized.
|
|
36
|
+
*/
|
|
37
|
+
export declare const resetTestDb: () => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Close the singleton DB connection.
|
|
40
|
+
* Call in global teardown or afterAll.
|
|
41
|
+
* Resets the singleton so a new one can be created if needed.
|
|
42
|
+
*/
|
|
43
|
+
export declare const closeTestDb: () => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if the singleton has been initialized.
|
|
46
|
+
* Useful for debugging and conditional logic.
|
|
47
|
+
*/
|
|
48
|
+
export declare const isTestDbInitialized: () => boolean;
|
|
49
|
+
//# sourceMappingURL=singleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAyB,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAIlG;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,qBAAqB,CAKxE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CAIhD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CAKhD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAAO,OAEtC,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Singleton test database for maximum memory efficiency.
|
|
3
|
+
*
|
|
4
|
+
* Instead of creating a new database per test or per describe block,
|
|
5
|
+
* this module provides a single shared database instance for the entire test suite.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* - Tests call `getSharedTestLayer()` to get the singleton
|
|
9
|
+
* - Global `afterEach` in vitest.setup.ts calls `resetTestDb()` for isolation
|
|
10
|
+
* - Global `afterAll` calls `closeTestDb()` for cleanup
|
|
11
|
+
*
|
|
12
|
+
* @module @tx/test-utils/singleton
|
|
13
|
+
*/
|
|
14
|
+
import { createSharedTestLayer } from "./helpers/shared-test-layer.js";
|
|
15
|
+
let instance = null;
|
|
16
|
+
/**
|
|
17
|
+
* Get the singleton test database layer.
|
|
18
|
+
* Creates it on first call, returns cached instance thereafter.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { getSharedTestLayer } from '@jamesaphoenix/tx-test-utils'
|
|
23
|
+
*
|
|
24
|
+
* it("test", async () => {
|
|
25
|
+
* const { layer } = await getSharedTestLayer()
|
|
26
|
+
* const result = await Effect.runPromise(
|
|
27
|
+
* myEffect.pipe(Effect.provide(layer))
|
|
28
|
+
* )
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const getSharedTestLayer = async () => {
|
|
33
|
+
if (!instance) {
|
|
34
|
+
instance = await createSharedTestLayer();
|
|
35
|
+
}
|
|
36
|
+
return instance;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Reset all tables in the singleton DB.
|
|
40
|
+
* Call in afterEach to ensure test isolation.
|
|
41
|
+
* Safe to call even if DB hasn't been initialized.
|
|
42
|
+
*/
|
|
43
|
+
export const resetTestDb = async () => {
|
|
44
|
+
if (instance) {
|
|
45
|
+
await instance.reset();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Close the singleton DB connection.
|
|
50
|
+
* Call in global teardown or afterAll.
|
|
51
|
+
* Resets the singleton so a new one can be created if needed.
|
|
52
|
+
*/
|
|
53
|
+
export const closeTestDb = async () => {
|
|
54
|
+
if (instance) {
|
|
55
|
+
await instance.close();
|
|
56
|
+
instance = null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Check if the singleton has been initialized.
|
|
61
|
+
* Useful for debugging and conditional logic.
|
|
62
|
+
*/
|
|
63
|
+
export const isTestDbInitialized = () => {
|
|
64
|
+
return instance !== null;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=singleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,qBAAqB,EAA8B,MAAM,gCAAgC,CAAA;AAElG,IAAI,QAAQ,GAAiC,IAAI,CAAA;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAoC,EAAE;IAC3E,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,MAAM,qBAAqB,EAAE,CAAA;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,IAAmB,EAAE;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,IAAmB,EAAE;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAA;QACtB,QAAQ,GAAG,IAAI,CAAA;IACjB,CAAC;AACH,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAY,EAAE;IAC/C,OAAO,QAAQ,KAAK,IAAI,CAAA;AAC1B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamesaphoenix/tx-test-utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Test utilities, factories, fixtures, and helpers for tx monorepo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,16 +37,21 @@
|
|
|
37
37
|
"./setup": {
|
|
38
38
|
"types": "./dist/setup/index.d.ts",
|
|
39
39
|
"import": "./dist/setup/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./chaos": {
|
|
42
|
+
"types": "./dist/chaos/index.d.ts",
|
|
43
|
+
"import": "./dist/chaos/index.js"
|
|
40
44
|
}
|
|
41
45
|
},
|
|
42
46
|
"files": [
|
|
43
|
-
"dist"
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md"
|
|
44
49
|
],
|
|
45
50
|
"scripts": {
|
|
46
51
|
"build": "tsc -b",
|
|
47
52
|
"typecheck": "tsc --noEmit",
|
|
48
53
|
"lint": "eslint src/",
|
|
49
|
-
"test": "
|
|
54
|
+
"test": "bun test src/ test/"
|
|
50
55
|
},
|
|
51
56
|
"dependencies": {
|
|
52
57
|
"@jamesaphoenix/tx-core": "*",
|
|
@@ -54,21 +59,17 @@
|
|
|
54
59
|
"effect": "^3.19.15"
|
|
55
60
|
},
|
|
56
61
|
"peerDependencies": {
|
|
57
|
-
"
|
|
58
|
-
"vitest": "^3.0.0"
|
|
62
|
+
"vitest": "^4.0.18"
|
|
59
63
|
},
|
|
60
64
|
"peerDependenciesMeta": {
|
|
61
|
-
"better-sqlite3": {
|
|
62
|
-
"optional": false
|
|
63
|
-
},
|
|
64
65
|
"vitest": {
|
|
65
66
|
"optional": false
|
|
66
67
|
}
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@types/
|
|
70
|
+
"@types/bun": "^1.2.0",
|
|
70
71
|
"typescript": "^5.7.0",
|
|
71
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^4.0.18"
|
|
72
73
|
},
|
|
73
74
|
"repository": {
|
|
74
75
|
"type": "git",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factories.test.d.ts","sourceRoot":"","sources":["../../src/factories/factories.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|