@geekmidas/testkit 0.1.0 → 0.2.0
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 +162 -13
- package/dist/{Factory-BZ8uMoXl.d.cts → Factory-D7oHtI2D.d.cts} +2 -2
- package/dist/Factory.d.cts +2 -2
- package/dist/{KyselyFactory-BFygzOlO.d.cts → KyselyFactory-dYdviox2.d.cts} +3 -3
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/{ObjectionFactory-CeSIN3kZ.d.cts → ObjectionFactory-0gUdx8bB.d.cts} +3 -3
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/{VitestKyselyTransactionIsolator-XDL3ngs_.mjs → VitestKyselyTransactionIsolator-CNURW8y6.mjs} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-XDL3ngs_.mjs.map → VitestKyselyTransactionIsolator-CNURW8y6.mjs.map} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-DnyZMaA-.d.mts → VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-4HOeLQ0d.d.cts → VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-DX_VPKS-.cjs → VitestKyselyTransactionIsolator-EvDLk5zg.cjs} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-DX_VPKS-.cjs.map → VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
- package/dist/{VitestObjectionTransactionIsolator-COVDlpEo.d.cts → VitestObjectionTransactionIsolator-1TpsPqfG.d.cts} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-D_tlOtq8.cjs → VitestObjectionTransactionIsolator-CM5KTAFA.cjs} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-D_tlOtq8.cjs.map → VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map} +1 -1
- package/dist/{VitestObjectionTransactionIsolator-lZUSz1w0.d.mts → VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-_EhJKu_O.mjs → VitestObjectionTransactionIsolator-jQFaCz0u.mjs} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-_EhJKu_O.mjs.map → VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map} +1 -1
- package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
- package/dist/{VitestTransactionIsolator-DWDbnITQ.d.mts → VitestTransactionIsolator-BvR19bYn.d.mts} +44 -18
- package/dist/{VitestTransactionIsolator-BKIrj3Uy.cjs → VitestTransactionIsolator-CMfJXZP8.cjs} +52 -36
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-CyG_i_Nj.d.cts → VitestTransactionIsolator-CwQaxZLP.d.cts} +44 -18
- package/dist/{VitestTransactionIsolator-BIaMs4c2.mjs → VitestTransactionIsolator-DQ7tLqgV.mjs} +52 -36
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -0
- package/dist/VitestTransactionIsolator.cjs +1 -1
- package/dist/VitestTransactionIsolator.d.cts +2 -2
- package/dist/VitestTransactionIsolator.d.mts +2 -2
- package/dist/VitestTransactionIsolator.mjs +1 -1
- package/dist/better-auth.d.cts +2 -2
- package/dist/{directory-DlkPEzL4.d.cts → directory-BUcnztHI.d.cts} +3 -3
- package/dist/{faker-Cg76aFNO.d.cts → faker-Dg3trU4a.d.cts} +3 -3
- package/dist/faker.d.cts +1 -1
- package/dist/kysely.cjs +23 -29
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +40 -38
- package/dist/kysely.d.mts +37 -35
- package/dist/kysely.mjs +23 -29
- package/dist/kysely.mjs.map +1 -1
- package/dist/objection.cjs +23 -47
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +40 -56
- package/dist/objection.d.mts +37 -53
- package/dist/objection.mjs +23 -47
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/package.json +1 -1
- package/src/VitestTransactionIsolator.ts +98 -31
- package/src/__tests__/KyselyFactory.spec.ts +4 -5
- package/src/__tests__/ObjectionFactory.spec.ts +4 -5
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +6 -3
- package/src/__tests__/integration.spec.ts +8 -10
- package/src/kysely.ts +49 -34
- package/src/objection.ts +47 -52
- package/dist/VitestTransactionIsolator-BIaMs4c2.mjs.map +0 -1
- package/dist/VitestTransactionIsolator-BKIrj3Uy.cjs.map +0 -1
package/dist/kysely.d.cts
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import { FakerFactory, faker } from "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import { FakerFactory, faker } from "./faker-Dg3trU4a.cjs";
|
|
2
|
+
import "./Factory-D7oHtI2D.cjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-dYdviox2.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
|
|
6
|
-
import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-CwQaxZLP.cjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-D3EZZhjZ.cjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
11
11
|
//#region src/kysely.d.ts
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Kysely-specific options for transaction wrapping.
|
|
15
|
+
*/
|
|
16
|
+
interface KyselyTransactionOptions<Database, Extended extends Record<string, unknown> = {}> {
|
|
17
|
+
/** Function that creates or returns a Kysely database instance */
|
|
18
|
+
connection: DatabaseConnection<Kysely<Database>>;
|
|
19
|
+
/** Optional setup function to run within the transaction before each test */
|
|
20
|
+
setup?: (trx: Transaction<Database>) => Promise<void>;
|
|
21
|
+
/** Transaction isolation level (defaults to REPEATABLE_READ) */
|
|
22
|
+
isolationLevel?: IsolationLevel;
|
|
23
|
+
/** Additional fixtures that depend on the transaction */
|
|
24
|
+
fixtures?: FixtureCreators<Transaction<Database>, Extended>;
|
|
25
|
+
}
|
|
13
26
|
/**
|
|
14
27
|
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
15
28
|
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
16
29
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
17
30
|
*
|
|
18
31
|
* @template Database - The database schema type
|
|
32
|
+
* @template Extended - Additional fixtures to provide
|
|
19
33
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
20
|
-
* @param
|
|
21
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
22
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
34
|
+
* @param options - Configuration options for transaction wrapping
|
|
23
35
|
* @returns A wrapped test API that provides transaction isolation
|
|
24
36
|
*
|
|
25
37
|
* @example
|
|
@@ -29,7 +41,9 @@ import { TestAPI } from "vitest";
|
|
|
29
41
|
* import { db } from './database';
|
|
30
42
|
*
|
|
31
43
|
* // Create isolated test with automatic rollback
|
|
32
|
-
* const isolatedTest = wrapVitestKyselyTransaction(test,
|
|
44
|
+
* const isolatedTest = wrapVitestKyselyTransaction(test, {
|
|
45
|
+
* connection: db,
|
|
46
|
+
* });
|
|
33
47
|
*
|
|
34
48
|
* // Use in tests - each test gets its own transaction
|
|
35
49
|
* isolatedTest('should create user', async ({ trx }) => {
|
|
@@ -40,35 +54,23 @@ import { TestAPI } from "vitest";
|
|
|
40
54
|
* .executeTakeFirst();
|
|
41
55
|
*
|
|
42
56
|
* expect(user).toBeDefined();
|
|
43
|
-
* // User is automatically rolled back after test
|
|
44
57
|
* });
|
|
45
58
|
*
|
|
46
|
-
* // With
|
|
47
|
-
* const
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* .values({ key: 'test_mode', value: 'true' })
|
|
54
|
-
* .execute();
|
|
55
|
-
* }
|
|
56
|
-
* );
|
|
57
|
-
*
|
|
58
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
59
|
-
* const setting = await trx
|
|
60
|
-
* .selectFrom('settings')
|
|
61
|
-
* .where('key', '=', 'test_mode')
|
|
62
|
-
* .selectAll()
|
|
63
|
-
* .executeTakeFirst();
|
|
59
|
+
* // With fixtures for factories
|
|
60
|
+
* const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {
|
|
61
|
+
* connection: db,
|
|
62
|
+
* fixtures: {
|
|
63
|
+
* factory: (trx) => new Factory(trx),
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
64
66
|
*
|
|
65
|
-
*
|
|
67
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
68
|
+
* const user = await factory.insert('user', { name: 'Test' });
|
|
69
|
+
* expect(user.id).toBeDefined();
|
|
66
70
|
* });
|
|
67
71
|
* ```
|
|
68
72
|
*/
|
|
69
|
-
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI,
|
|
70
|
-
trx: Transaction<Database>;
|
|
71
|
-
}>;
|
|
73
|
+
declare function wrapVitestKyselyTransaction<Database, Extended extends Record<string, unknown> = {}>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>): TestAPI<DatabaseFixtures<Transaction<Database>, object> & Extended>;
|
|
72
74
|
/**
|
|
73
75
|
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
74
76
|
* Each fixture receives the transaction and can create dependencies like factories or repositories.
|
|
@@ -93,7 +95,10 @@ declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection:
|
|
|
93
95
|
* };
|
|
94
96
|
*
|
|
95
97
|
* // Create base wrapped test
|
|
96
|
-
* const baseTest = wrapVitestKyselyTransaction<DB>(test,
|
|
98
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, {
|
|
99
|
+
* connection: db,
|
|
100
|
+
* setup: createTestTables,
|
|
101
|
+
* });
|
|
97
102
|
*
|
|
98
103
|
* // Extend with fixtures - each fixture receives the transaction
|
|
99
104
|
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
|
@@ -118,10 +123,7 @@ declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection:
|
|
|
118
123
|
* });
|
|
119
124
|
* ```
|
|
120
125
|
*/
|
|
121
|
-
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>):
|
|
122
|
-
<C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
123
|
-
<C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
124
|
-
};
|
|
126
|
+
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
|
|
125
127
|
//#endregion
|
|
126
|
-
export { FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
128
|
+
export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
127
129
|
//# sourceMappingURL=kysely.d.cts.map
|
package/dist/kysely.d.mts
CHANGED
|
@@ -3,23 +3,35 @@ import "./Factory-Cmr3s3-s.mjs";
|
|
|
3
3
|
import { KyselyFactory } from "./KyselyFactory-BTdygZ-i.mjs";
|
|
4
4
|
import "./PostgresMigrator-DQaRxoaY.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
|
|
6
|
-
import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-BvR19bYn.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-Dxlp1u0f.mjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
11
11
|
//#region src/kysely.d.ts
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Kysely-specific options for transaction wrapping.
|
|
15
|
+
*/
|
|
16
|
+
interface KyselyTransactionOptions<Database, Extended extends Record<string, unknown> = {}> {
|
|
17
|
+
/** Function that creates or returns a Kysely database instance */
|
|
18
|
+
connection: DatabaseConnection<Kysely<Database>>;
|
|
19
|
+
/** Optional setup function to run within the transaction before each test */
|
|
20
|
+
setup?: (trx: Transaction<Database>) => Promise<void>;
|
|
21
|
+
/** Transaction isolation level (defaults to REPEATABLE_READ) */
|
|
22
|
+
isolationLevel?: IsolationLevel;
|
|
23
|
+
/** Additional fixtures that depend on the transaction */
|
|
24
|
+
fixtures?: FixtureCreators<Transaction<Database>, Extended>;
|
|
25
|
+
}
|
|
13
26
|
/**
|
|
14
27
|
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
15
28
|
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
16
29
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
17
30
|
*
|
|
18
31
|
* @template Database - The database schema type
|
|
32
|
+
* @template Extended - Additional fixtures to provide
|
|
19
33
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
20
|
-
* @param
|
|
21
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
22
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
34
|
+
* @param options - Configuration options for transaction wrapping
|
|
23
35
|
* @returns A wrapped test API that provides transaction isolation
|
|
24
36
|
*
|
|
25
37
|
* @example
|
|
@@ -29,7 +41,9 @@ import { TestAPI } from "vitest";
|
|
|
29
41
|
* import { db } from './database';
|
|
30
42
|
*
|
|
31
43
|
* // Create isolated test with automatic rollback
|
|
32
|
-
* const isolatedTest = wrapVitestKyselyTransaction(test,
|
|
44
|
+
* const isolatedTest = wrapVitestKyselyTransaction(test, {
|
|
45
|
+
* connection: db,
|
|
46
|
+
* });
|
|
33
47
|
*
|
|
34
48
|
* // Use in tests - each test gets its own transaction
|
|
35
49
|
* isolatedTest('should create user', async ({ trx }) => {
|
|
@@ -40,35 +54,23 @@ import { TestAPI } from "vitest";
|
|
|
40
54
|
* .executeTakeFirst();
|
|
41
55
|
*
|
|
42
56
|
* expect(user).toBeDefined();
|
|
43
|
-
* // User is automatically rolled back after test
|
|
44
57
|
* });
|
|
45
58
|
*
|
|
46
|
-
* // With
|
|
47
|
-
* const
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* .values({ key: 'test_mode', value: 'true' })
|
|
54
|
-
* .execute();
|
|
55
|
-
* }
|
|
56
|
-
* );
|
|
57
|
-
*
|
|
58
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
59
|
-
* const setting = await trx
|
|
60
|
-
* .selectFrom('settings')
|
|
61
|
-
* .where('key', '=', 'test_mode')
|
|
62
|
-
* .selectAll()
|
|
63
|
-
* .executeTakeFirst();
|
|
59
|
+
* // With fixtures for factories
|
|
60
|
+
* const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {
|
|
61
|
+
* connection: db,
|
|
62
|
+
* fixtures: {
|
|
63
|
+
* factory: (trx) => new Factory(trx),
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
64
66
|
*
|
|
65
|
-
*
|
|
67
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
68
|
+
* const user = await factory.insert('user', { name: 'Test' });
|
|
69
|
+
* expect(user.id).toBeDefined();
|
|
66
70
|
* });
|
|
67
71
|
* ```
|
|
68
72
|
*/
|
|
69
|
-
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI,
|
|
70
|
-
trx: Transaction<Database>;
|
|
71
|
-
}>;
|
|
73
|
+
declare function wrapVitestKyselyTransaction<Database, Extended extends Record<string, unknown> = {}>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>): TestAPI<DatabaseFixtures<Transaction<Database>, object> & Extended>;
|
|
72
74
|
/**
|
|
73
75
|
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
74
76
|
* Each fixture receives the transaction and can create dependencies like factories or repositories.
|
|
@@ -93,7 +95,10 @@ declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection:
|
|
|
93
95
|
* };
|
|
94
96
|
*
|
|
95
97
|
* // Create base wrapped test
|
|
96
|
-
* const baseTest = wrapVitestKyselyTransaction<DB>(test,
|
|
98
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, {
|
|
99
|
+
* connection: db,
|
|
100
|
+
* setup: createTestTables,
|
|
101
|
+
* });
|
|
97
102
|
*
|
|
98
103
|
* // Extend with fixtures - each fixture receives the transaction
|
|
99
104
|
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
|
@@ -118,10 +123,7 @@ declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection:
|
|
|
118
123
|
* });
|
|
119
124
|
* ```
|
|
120
125
|
*/
|
|
121
|
-
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>):
|
|
122
|
-
<C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
123
|
-
<C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
124
|
-
};
|
|
126
|
+
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
|
|
125
127
|
//#endregion
|
|
126
|
-
export { FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
128
|
+
export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
127
129
|
//# sourceMappingURL=kysely.d.mts.map
|
package/dist/kysely.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { faker } from "./faker-BGKYFoCT.mjs";
|
|
|
3
3
|
import { KyselyFactory } from "./KyselyFactory-CXY5gJk2.mjs";
|
|
4
4
|
import "./PostgresMigrator-DbuJGAVy.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
|
|
6
|
-
import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-CNURW8y6.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/kysely.ts
|
|
10
10
|
/**
|
|
@@ -13,10 +13,9 @@ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolat
|
|
|
13
13
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
14
14
|
*
|
|
15
15
|
* @template Database - The database schema type
|
|
16
|
+
* @template Extended - Additional fixtures to provide
|
|
16
17
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
17
|
-
* @param
|
|
18
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
19
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
18
|
+
* @param options - Configuration options for transaction wrapping
|
|
20
19
|
* @returns A wrapped test API that provides transaction isolation
|
|
21
20
|
*
|
|
22
21
|
* @example
|
|
@@ -26,7 +25,9 @@ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolat
|
|
|
26
25
|
* import { db } from './database';
|
|
27
26
|
*
|
|
28
27
|
* // Create isolated test with automatic rollback
|
|
29
|
-
* const isolatedTest = wrapVitestKyselyTransaction(test,
|
|
28
|
+
* const isolatedTest = wrapVitestKyselyTransaction(test, {
|
|
29
|
+
* connection: db,
|
|
30
|
+
* });
|
|
30
31
|
*
|
|
31
32
|
* // Use in tests - each test gets its own transaction
|
|
32
33
|
* isolatedTest('should create user', async ({ trx }) => {
|
|
@@ -37,35 +38,25 @@ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolat
|
|
|
37
38
|
* .executeTakeFirst();
|
|
38
39
|
*
|
|
39
40
|
* expect(user).toBeDefined();
|
|
40
|
-
* // User is automatically rolled back after test
|
|
41
41
|
* });
|
|
42
42
|
*
|
|
43
|
-
* // With
|
|
44
|
-
* const
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* .values({ key: 'test_mode', value: 'true' })
|
|
51
|
-
* .execute();
|
|
52
|
-
* }
|
|
53
|
-
* );
|
|
54
|
-
*
|
|
55
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
56
|
-
* const setting = await trx
|
|
57
|
-
* .selectFrom('settings')
|
|
58
|
-
* .where('key', '=', 'test_mode')
|
|
59
|
-
* .selectAll()
|
|
60
|
-
* .executeTakeFirst();
|
|
43
|
+
* // With fixtures for factories
|
|
44
|
+
* const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {
|
|
45
|
+
* connection: db,
|
|
46
|
+
* fixtures: {
|
|
47
|
+
* factory: (trx) => new Factory(trx),
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
61
50
|
*
|
|
62
|
-
*
|
|
51
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
52
|
+
* const user = await factory.insert('user', { name: 'Test' });
|
|
53
|
+
* expect(user.id).toBeDefined();
|
|
63
54
|
* });
|
|
64
55
|
* ```
|
|
65
56
|
*/
|
|
66
|
-
function wrapVitestKyselyTransaction(api,
|
|
57
|
+
function wrapVitestKyselyTransaction(api, options) {
|
|
67
58
|
const wrapper = new VitestKyselyTransactionIsolator(api);
|
|
68
|
-
return wrapper.wrapVitestWithTransaction(
|
|
59
|
+
return wrapper.wrapVitestWithTransaction(options);
|
|
69
60
|
}
|
|
70
61
|
/**
|
|
71
62
|
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
@@ -91,7 +82,10 @@ function wrapVitestKyselyTransaction(api, connection, setup, level = IsolationLe
|
|
|
91
82
|
* };
|
|
92
83
|
*
|
|
93
84
|
* // Create base wrapped test
|
|
94
|
-
* const baseTest = wrapVitestKyselyTransaction<DB>(test,
|
|
85
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, {
|
|
86
|
+
* connection: db,
|
|
87
|
+
* setup: createTestTables,
|
|
88
|
+
* });
|
|
95
89
|
*
|
|
96
90
|
* // Extend with fixtures - each fixture receives the transaction
|
|
97
91
|
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
package/dist/kysely.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely.mjs","names":["api: TestAPI","
|
|
1
|
+
{"version":3,"file":"kysely.mjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACrE,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,mBACL,aACA,SACD;AACF"}
|
package/dist/objection.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const require_faker = require('./faker-B14IEMIN.cjs');
|
|
|
3
3
|
const require_ObjectionFactory = require('./ObjectionFactory-Eb04AOnv.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
6
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
7
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-
|
|
6
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
|
7
|
+
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-CM5KTAFA.cjs');
|
|
8
8
|
|
|
9
9
|
//#region src/objection.ts
|
|
10
10
|
/**
|
|
@@ -12,10 +12,9 @@ const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTra
|
|
|
12
12
|
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
13
13
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
14
14
|
*
|
|
15
|
+
* @template Extended - Additional fixtures to provide
|
|
15
16
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
16
|
-
* @param
|
|
17
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
18
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
17
|
+
* @param options - Configuration options for transaction wrapping
|
|
19
18
|
* @returns A wrapped test API that provides transaction isolation
|
|
20
19
|
*
|
|
21
20
|
* @example
|
|
@@ -23,10 +22,12 @@ const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTra
|
|
|
23
22
|
* import { test } from 'vitest';
|
|
24
23
|
* import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
|
|
25
24
|
* import { knex } from './database';
|
|
26
|
-
* import { User
|
|
25
|
+
* import { User } from './models';
|
|
27
26
|
*
|
|
28
27
|
* // Create isolated test with automatic rollback
|
|
29
|
-
* const isolatedTest = wrapVitestObjectionTransaction(test,
|
|
28
|
+
* const isolatedTest = wrapVitestObjectionTransaction(test, {
|
|
29
|
+
* connection: knex,
|
|
30
|
+
* });
|
|
30
31
|
*
|
|
31
32
|
* // Use in tests - each test gets its own transaction
|
|
32
33
|
* isolatedTest('should create user', async ({ trx }) => {
|
|
@@ -34,53 +35,25 @@ const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTra
|
|
|
34
35
|
* .insert({ name: 'Test User', email: 'test@example.com' });
|
|
35
36
|
*
|
|
36
37
|
* expect(user).toBeDefined();
|
|
37
|
-
* // User is automatically rolled back after test
|
|
38
38
|
* });
|
|
39
39
|
*
|
|
40
|
-
* // With
|
|
41
|
-
* const
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* await knex('settings')
|
|
47
|
-
* .transacting(trx)
|
|
48
|
-
* .insert({ key: 'test_mode', value: 'true' });
|
|
49
|
-
* }
|
|
50
|
-
* );
|
|
51
|
-
*
|
|
52
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
53
|
-
* const setting = await knex('settings')
|
|
54
|
-
* .transacting(trx)
|
|
55
|
-
* .where('key', 'test_mode')
|
|
56
|
-
* .first();
|
|
57
|
-
*
|
|
58
|
-
* expect(setting?.value).toBe('true');
|
|
40
|
+
* // With fixtures for factories
|
|
41
|
+
* const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {
|
|
42
|
+
* connection: knex,
|
|
43
|
+
* fixtures: {
|
|
44
|
+
* factory: (trx) => new Factory(trx),
|
|
45
|
+
* },
|
|
59
46
|
* });
|
|
60
47
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* isolatedTest('creates related data', async ({ trx }) => {
|
|
66
|
-
* // Factory can use the transaction
|
|
67
|
-
* const user = await User.query(trx).insert({ name: 'Author' });
|
|
68
|
-
* const posts = await Post.query(trx).insert([
|
|
69
|
-
* { title: 'Post 1', userId: user.id },
|
|
70
|
-
* { title: 'Post 2', userId: user.id }
|
|
71
|
-
* ]);
|
|
72
|
-
*
|
|
73
|
-
* const userWithPosts = await User.query(trx)
|
|
74
|
-
* .findById(user.id)
|
|
75
|
-
* .withGraphFetched('posts');
|
|
76
|
-
*
|
|
77
|
-
* expect(userWithPosts.posts).toHaveLength(2);
|
|
48
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
49
|
+
* const user = await factory.insert('user', { name: 'Test' });
|
|
50
|
+
* expect(user.id).toBeDefined();
|
|
78
51
|
* });
|
|
79
52
|
* ```
|
|
80
53
|
*/
|
|
81
|
-
function wrapVitestObjectionTransaction(api,
|
|
54
|
+
function wrapVitestObjectionTransaction(api, options) {
|
|
82
55
|
const wrapper = new require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator(api);
|
|
83
|
-
return wrapper.wrapVitestWithTransaction(
|
|
56
|
+
return wrapper.wrapVitestWithTransaction(options);
|
|
84
57
|
}
|
|
85
58
|
/**
|
|
86
59
|
* Extends an Objection.js transaction-wrapped test with additional fixtures.
|
|
@@ -106,7 +79,10 @@ function wrapVitestObjectionTransaction(api, conn, setup, level = require_Vitest
|
|
|
106
79
|
* };
|
|
107
80
|
*
|
|
108
81
|
* // Create base wrapped test
|
|
109
|
-
* const baseTest = wrapVitestObjectionTransaction(test,
|
|
82
|
+
* const baseTest = wrapVitestObjectionTransaction(test, {
|
|
83
|
+
* connection: knex,
|
|
84
|
+
* setup: createTestTables,
|
|
85
|
+
* });
|
|
110
86
|
*
|
|
111
87
|
* // Extend with fixtures - each fixture receives the transaction
|
|
112
88
|
* const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(
|
package/dist/objection.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objection.cjs","names":["api: TestAPI","
|
|
1
|
+
{"version":3,"file":"objection.cjs","names":["api: TestAPI","options: ObjectionTransactionOptions<Extended>","VitestObjectionTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Knex.Transaction, Extended>"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific options for transaction wrapping.\n */\nexport interface ObjectionTransactionOptions<\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Knex database connection */\n connection: DatabaseConnection<Knex>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Knex.Transaction) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Knex.Transaction, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestObjectionTransaction<{ factory: Factory }>(test, {\n * connection: knex,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction<\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends an Objection.js transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestObjectionTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction, extendWithFixtures, ObjectionFactory } from '@geekmidas/testkit/objection';\n * import { User } from './models';\n *\n * // Define your builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestObjectionTransaction(test, {\n * connection: knex,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<{ factory: ObjectionFactory<typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new ObjectionFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await User.query(trx).findById(user.id);\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {\n return baseExtendWithFixtures<Knex.Transaction, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,SAAgB,+BAEdA,KAAcC,SAAgD;CAC9D,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgBC,qBAGdC,aAAgBC,UAAuD;AACvE,QAAO,qDACL,aACA,SACD;AACF"}
|