@geekmidas/testkit 10.0.0-alpha.3 → 10.0.0-alpha.31
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 +74 -0
- package/dist/Factory.cjs +51 -2
- package/dist/Factory.cjs.map +1 -0
- package/dist/Factory.d.cts +143 -3
- package/dist/Factory.d.cts.map +1 -0
- package/dist/Factory.d.mts +143 -3
- package/dist/Factory.d.mts.map +1 -0
- package/dist/Factory.mjs +50 -2
- package/dist/Factory.mjs.map +1 -0
- package/dist/KyselyFactory.cjs +237 -4
- package/dist/KyselyFactory.cjs.map +1 -0
- package/dist/KyselyFactory.d.cts +224 -4
- package/dist/KyselyFactory.d.cts.map +1 -0
- package/dist/KyselyFactory.d.mts +224 -4
- package/dist/KyselyFactory.d.mts.map +1 -0
- package/dist/KyselyFactory.mjs +236 -4
- package/dist/KyselyFactory.mjs.map +1 -0
- package/dist/ObjectionFactory.cjs +265 -4
- package/dist/ObjectionFactory.cjs.map +1 -0
- package/dist/ObjectionFactory.d.cts +237 -4
- package/dist/ObjectionFactory.d.cts.map +1 -0
- package/dist/ObjectionFactory.d.mts +237 -4
- package/dist/ObjectionFactory.d.mts.map +1 -0
- package/dist/ObjectionFactory.mjs +264 -4
- package/dist/ObjectionFactory.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +94 -3
- package/dist/PostgresKyselyMigrator.cjs.map +1 -0
- package/dist/PostgresKyselyMigrator.d.cts +80 -3
- package/dist/PostgresKyselyMigrator.d.cts.map +1 -0
- package/dist/PostgresKyselyMigrator.d.mts +80 -3
- package/dist/PostgresKyselyMigrator.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.mjs +93 -3
- package/dist/PostgresKyselyMigrator.mjs.map +1 -0
- package/dist/{PostgresMigrator-C_QQ6q35.d.mts → PostgresMigrator-CDPnnwMJ.d.cts} +11 -5
- package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +1 -0
- package/dist/{PostgresMigrator-CeYy-eHF.d.cts → PostgresMigrator-CDPnnwMJ.d.mts} +11 -5
- package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +178 -2
- package/dist/PostgresMigrator.cjs.map +1 -0
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +175 -2
- package/dist/PostgresMigrator.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +118 -3
- package/dist/PostgresObjectionMigrator.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator.d.cts +75 -3
- package/dist/PostgresObjectionMigrator.d.cts.map +1 -0
- package/dist/PostgresObjectionMigrator.d.mts +75 -3
- package/dist/PostgresObjectionMigrator.d.mts.map +1 -0
- package/dist/PostgresObjectionMigrator.mjs +117 -3
- package/dist/PostgresObjectionMigrator.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +66 -3
- package/dist/VitestKyselyTransactionIsolator.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.d.cts +60 -3
- package/dist/VitestKyselyTransactionIsolator.d.cts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.d.mts +60 -3
- package/dist/VitestKyselyTransactionIsolator.d.mts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.mjs +65 -3
- package/dist/VitestKyselyTransactionIsolator.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +62 -3
- package/dist/VitestObjectionTransactionIsolator.cjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.d.cts +56 -3
- package/dist/VitestObjectionTransactionIsolator.d.cts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.d.mts +56 -3
- package/dist/VitestObjectionTransactionIsolator.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.mjs +61 -3
- package/dist/VitestObjectionTransactionIsolator.mjs.map +1 -0
- package/dist/VitestTransactionIsolator.cjs +187 -4
- package/dist/VitestTransactionIsolator.cjs.map +1 -0
- package/dist/VitestTransactionIsolator.d.cts +219 -2
- package/dist/VitestTransactionIsolator.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator.d.mts +219 -2
- package/dist/VitestTransactionIsolator.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator.mjs +184 -2
- package/dist/VitestTransactionIsolator.mjs.map +1 -0
- package/dist/aws.cjs +3 -4
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +3 -8
- package/dist/aws.d.cts.map +1 -1
- package/dist/aws.d.mts +3 -8
- package/dist/aws.d.mts.map +1 -1
- package/dist/aws.mjs +1 -2
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs +2 -2
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +4 -6
- package/dist/benchmark.d.cts.map +1 -1
- package/dist/benchmark.d.mts +4 -6
- package/dist/benchmark.d.mts.map +1 -1
- package/dist/benchmark.mjs +1 -1
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +31 -15
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +13142 -4
- package/dist/better-auth.d.cts.map +1 -1
- package/dist/better-auth.d.mts +13142 -4
- package/dist/better-auth.d.mts.map +1 -1
- package/dist/better-auth.mjs +29 -13
- package/dist/better-auth.mjs.map +1 -1
- package/dist/browser.cjs +127 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +47 -0
- package/dist/browser.d.cts.map +1 -0
- package/dist/browser.d.mts +47 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +125 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/context.cjs +80 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +55 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.mts +55 -0
- package/dist/context.d.mts.map +1 -0
- package/dist/context.mjs +73 -0
- package/dist/context.mjs.map +1 -0
- package/dist/faker.cjs +262 -8
- package/dist/faker.cjs.map +1 -0
- package/dist/faker.d.cts +162 -2
- package/dist/faker.d.cts.map +1 -0
- package/dist/faker.d.mts +162 -2
- package/dist/faker.d.mts.map +1 -0
- package/dist/faker.mjs +255 -2
- package/dist/faker.mjs.map +1 -0
- package/dist/helpers.cjs +6 -5
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -5
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +1 -5
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +1 -2
- package/dist/helpers.mjs.map +1 -1
- package/dist/initScript.cjs +15 -15
- package/dist/initScript.cjs.map +1 -1
- package/dist/initScript.d.cts +2 -4
- package/dist/initScript.d.cts.map +1 -1
- package/dist/initScript.d.mts +2 -4
- package/dist/initScript.d.mts.map +1 -1
- package/dist/initScript.mjs +10 -12
- package/dist/initScript.mjs.map +1 -1
- package/dist/kysely.cjs +10 -13
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +10 -14
- package/dist/kysely.d.cts.map +1 -1
- package/dist/kysely.d.mts +10 -14
- package/dist/kysely.d.mts.map +1 -1
- package/dist/kysely.mjs +10 -14
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs +3 -4
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -5
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +1 -5
- package/dist/logger.d.mts.map +1 -1
- package/dist/logger.mjs +1 -2
- package/dist/logger.mjs.map +1 -1
- package/dist/mailbox.cjs +95 -0
- package/dist/mailbox.cjs.map +1 -0
- package/dist/mailbox.d.cts +58 -0
- package/dist/mailbox.d.cts.map +1 -0
- package/dist/mailbox.d.mts +58 -0
- package/dist/mailbox.d.mts.map +1 -0
- package/dist/mailbox.mjs +92 -0
- package/dist/mailbox.mjs.map +1 -0
- package/dist/objection.cjs +10 -13
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +10 -14
- package/dist/objection.d.cts.map +1 -1
- package/dist/objection.d.mts +10 -14
- package/dist/objection.d.mts.map +1 -1
- package/dist/objection.mjs +10 -14
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.cjs +31 -2
- package/dist/os/directory.cjs.map +1 -0
- package/dist/os/directory.d.cts +9 -2
- package/dist/os/directory.d.cts.map +1 -0
- package/dist/os/directory.d.mts +9 -2
- package/dist/os/directory.d.mts.map +1 -0
- package/dist/os/directory.mjs +25 -2
- package/dist/os/directory.mjs.map +1 -0
- package/dist/os/index.cjs +3 -3
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/os/index.mjs +2 -3
- package/dist/requestContext.cjs +10 -11
- package/dist/requestContext.cjs.map +1 -1
- package/dist/requestContext.d.cts +4 -8
- package/dist/requestContext.d.cts.map +1 -1
- package/dist/requestContext.d.mts +4 -8
- package/dist/requestContext.d.mts.map +1 -1
- package/dist/requestContext.mjs +1 -2
- package/dist/requestContext.mjs.map +1 -1
- package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-VH7oDXx4.cjs} +8 -10
- package/dist/timer.cjs +2 -2
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +1 -4
- package/dist/timer.d.cts.map +1 -1
- package/dist/timer.d.mts +1 -4
- package/dist/timer.d.mts.map +1 -1
- package/dist/timer.mjs +1 -1
- package/dist/timer.mjs.map +1 -1
- package/dist/transactions.cjs +123 -0
- package/dist/transactions.cjs.map +1 -0
- package/dist/transactions.d.cts +44 -0
- package/dist/transactions.d.cts.map +1 -0
- package/dist/transactions.d.mts +44 -0
- package/dist/transactions.d.mts.map +1 -0
- package/dist/transactions.mjs +118 -0
- package/dist/transactions.mjs.map +1 -0
- package/package.json +59 -16
- package/dist/Factory-BFVnMMCC.mjs +0 -51
- package/dist/Factory-BFVnMMCC.mjs.map +0 -1
- package/dist/Factory-BOX312yd.d.cts +0 -147
- package/dist/Factory-BOX312yd.d.cts.map +0 -1
- package/dist/Factory-BhjUOBWN.cjs +0 -57
- package/dist/Factory-BhjUOBWN.cjs.map +0 -1
- package/dist/Factory-C6W78ulZ.d.mts +0 -147
- package/dist/Factory-C6W78ulZ.d.mts.map +0 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs +0 -246
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +0 -1
- package/dist/KyselyFactory-Cc2UmOJk.d.mts +0 -228
- package/dist/KyselyFactory-Cc2UmOJk.d.mts.map +0 -1
- package/dist/KyselyFactory-DMswpwji.mjs +0 -241
- package/dist/KyselyFactory-DMswpwji.mjs.map +0 -1
- package/dist/KyselyFactory-Dy5zzV4B.d.cts +0 -228
- package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +0 -1
- package/dist/ObjectionFactory-BYnPr9ZP.d.mts +0 -241
- package/dist/ObjectionFactory-BYnPr9ZP.d.mts.map +0 -1
- package/dist/ObjectionFactory-BeFBYcan.cjs +0 -272
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +0 -1
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts +0 -241
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +0 -1
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs +0 -267
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +0 -1
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +0 -84
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +0 -1
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +0 -101
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +0 -84
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +0 -1
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +0 -95
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +0 -1
- package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +0 -1
- package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +0 -1
- package/dist/PostgresMigrator-DVAY04qN.mjs +0 -166
- package/dist/PostgresMigrator-DVAY04qN.mjs.map +0 -1
- package/dist/PostgresMigrator-M9jpzOvN.cjs +0 -172
- package/dist/PostgresMigrator-M9jpzOvN.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +0 -79
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +0 -1
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +0 -79
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +0 -1
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +0 -123
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +0 -118
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs +0 -67
- package/dist/VitestKyselyTransactionIsolator-1Saieke7.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs +0 -72
- package/dist/VitestKyselyTransactionIsolator-BjJSXryR.cjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts +0 -64
- package/dist/VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts +0 -64
- package/dist/VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs +0 -63
- package/dist/VitestObjectionTransactionIsolator-B_VSWFum.mjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts +0 -60
- package/dist/VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts +0 -60
- package/dist/VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs +0 -68
- package/dist/VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map +0 -1
- package/dist/VitestTransactionIsolator-BLaw80cx.d.mts +0 -223
- package/dist/VitestTransactionIsolator-BLaw80cx.d.mts.map +0 -1
- package/dist/VitestTransactionIsolator-CvwPecpl.mjs +0 -188
- package/dist/VitestTransactionIsolator-CvwPecpl.mjs.map +0 -1
- package/dist/VitestTransactionIsolator-DyiX-QtK.cjs +0 -206
- package/dist/VitestTransactionIsolator-DyiX-QtK.cjs.map +0 -1
- package/dist/VitestTransactionIsolator-glcxyS_R.d.cts +0 -223
- package/dist/VitestTransactionIsolator-glcxyS_R.d.cts.map +0 -1
- package/dist/directory-BxjqmtCT.mjs +0 -27
- package/dist/directory-BxjqmtCT.mjs.map +0 -1
- package/dist/directory-DD_xQoSh.cjs +0 -33
- package/dist/directory-DD_xQoSh.cjs.map +0 -1
- package/dist/directory-DGOcVlKD.d.cts +0 -13
- package/dist/directory-DGOcVlKD.d.cts.map +0 -1
- package/dist/directory-DiQ_DkaF.d.mts +0 -13
- package/dist/directory-DiQ_DkaF.d.mts.map +0 -1
- package/dist/faker-B14IEMIN.cjs +0 -304
- package/dist/faker-B14IEMIN.cjs.map +0 -1
- package/dist/faker-BGKYFoCT.mjs +0 -262
- package/dist/faker-BGKYFoCT.mjs.map +0 -1
- package/dist/faker-Cg76aFNO.d.cts +0 -166
- package/dist/faker-Cg76aFNO.d.cts.map +0 -1
- package/dist/faker-D9gz7KjY.d.mts +0 -166
- package/dist/faker-D9gz7KjY.d.mts.map +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BLaw80cx.mjs";
|
|
2
|
-
import { Kysely, Transaction } from "kysely";
|
|
3
|
-
|
|
4
|
-
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Kysely-specific implementation of the Vitest transaction isolator.
|
|
8
|
-
* Provides automatic transaction rollback for test isolation using Kysely's transaction API.
|
|
9
|
-
* Each test runs within a database transaction that is rolled back after completion,
|
|
10
|
-
* ensuring a clean state between tests without the overhead of recreating data.
|
|
11
|
-
*
|
|
12
|
-
* @template Database - The database schema type
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
|
|
17
|
-
* import { db } from './database';
|
|
18
|
-
*
|
|
19
|
-
* // Create isolator instance
|
|
20
|
-
* const isolator = new VitestKyselyTransactionIsolator<Database>();
|
|
21
|
-
*
|
|
22
|
-
* // In your test setup
|
|
23
|
-
* beforeEach(async () => {
|
|
24
|
-
* await isolator.start(db);
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* afterEach(async () => {
|
|
28
|
-
* await isolator.rollback();
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* // Tests run in isolated transactions
|
|
32
|
-
* it('should create user', async () => {
|
|
33
|
-
* const user = await db.insertInto('users')
|
|
34
|
-
* .values({ name: 'Test User' })
|
|
35
|
-
* .returningAll()
|
|
36
|
-
* .executeTakeFirst();
|
|
37
|
-
*
|
|
38
|
-
* expect(user).toBeDefined();
|
|
39
|
-
* // This data will be rolled back after the test
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTransactionIsolator<Kysely<Database>, Transaction<Database>> {
|
|
44
|
-
/**
|
|
45
|
-
* Closes the pool. Safe to implement now that it runs in the file's
|
|
46
|
-
* teardown rather than after every test, where it would have closed the
|
|
47
|
-
* connection the next test was about to use.
|
|
48
|
-
*/
|
|
49
|
-
destroy(conn: Kysely<Database>): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a Kysely transaction with the specified isolation level.
|
|
52
|
-
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
53
|
-
*
|
|
54
|
-
* @param conn - The Kysely database connection
|
|
55
|
-
* @param level - The transaction isolation level
|
|
56
|
-
* @param fn - The function to execute within the transaction
|
|
57
|
-
* @returns Promise that resolves when the transaction completes
|
|
58
|
-
*/
|
|
59
|
-
transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator.d.ts.map
|
|
62
|
-
//#endregion
|
|
63
|
-
export { VitestKyselyTransactionIsolator };
|
|
64
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator-CwlTo6yf.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestKyselyTransactionIsolator-CwlTo6yf.d.mts","names":[],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2CA;;;;;;;;;;;;;;;;;AAE2C;;;;;;;;;;;;;;;;;;cAF9B,kDAEH,kCACT,OAAO,WACP,YAAY;;;;;;gBAOQ,OAAO,YAAY;;;;;;;;;;iBAahC,OAAO,kBACN,0BACG,YAAY,cAAc,gBAClC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-glcxyS_R.cjs";
|
|
2
|
-
import { Kysely, Transaction } from "kysely";
|
|
3
|
-
|
|
4
|
-
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Kysely-specific implementation of the Vitest transaction isolator.
|
|
8
|
-
* Provides automatic transaction rollback for test isolation using Kysely's transaction API.
|
|
9
|
-
* Each test runs within a database transaction that is rolled back after completion,
|
|
10
|
-
* ensuring a clean state between tests without the overhead of recreating data.
|
|
11
|
-
*
|
|
12
|
-
* @template Database - The database schema type
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';
|
|
17
|
-
* import { db } from './database';
|
|
18
|
-
*
|
|
19
|
-
* // Create isolator instance
|
|
20
|
-
* const isolator = new VitestKyselyTransactionIsolator<Database>();
|
|
21
|
-
*
|
|
22
|
-
* // In your test setup
|
|
23
|
-
* beforeEach(async () => {
|
|
24
|
-
* await isolator.start(db);
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* afterEach(async () => {
|
|
28
|
-
* await isolator.rollback();
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* // Tests run in isolated transactions
|
|
32
|
-
* it('should create user', async () => {
|
|
33
|
-
* const user = await db.insertInto('users')
|
|
34
|
-
* .values({ name: 'Test User' })
|
|
35
|
-
* .returningAll()
|
|
36
|
-
* .executeTakeFirst();
|
|
37
|
-
*
|
|
38
|
-
* expect(user).toBeDefined();
|
|
39
|
-
* // This data will be rolled back after the test
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTransactionIsolator<Kysely<Database>, Transaction<Database>> {
|
|
44
|
-
/**
|
|
45
|
-
* Closes the pool. Safe to implement now that it runs in the file's
|
|
46
|
-
* teardown rather than after every test, where it would have closed the
|
|
47
|
-
* connection the next test was about to use.
|
|
48
|
-
*/
|
|
49
|
-
destroy(conn: Kysely<Database>): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a Kysely transaction with the specified isolation level.
|
|
52
|
-
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
53
|
-
*
|
|
54
|
-
* @param conn - The Kysely database connection
|
|
55
|
-
* @param level - The transaction isolation level
|
|
56
|
-
* @param fn - The function to execute within the transaction
|
|
57
|
-
* @returns Promise that resolves when the transaction completes
|
|
58
|
-
*/
|
|
59
|
-
transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator.d.ts.map
|
|
62
|
-
//#endregion
|
|
63
|
-
export { VitestKyselyTransactionIsolator };
|
|
64
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator-DJasVuIZ.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestKyselyTransactionIsolator-DJasVuIZ.d.cts","names":[],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2CA;;;;;;;;;;;;;;;;;AAE2C;;;;;;;;;;;;;;;;;;cAF9B,kDAEH,kCACT,OAAO,WACP,YAAY;;;;;;gBAOQ,OAAO,YAAY;;;;;;;;;;iBAahC,OAAO,kBACN,0BACG,YAAY,cAAc,gBAClC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CvwPecpl.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/VitestObjectionTransactionIsolator.ts
|
|
4
|
-
/**
|
|
5
|
-
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
6
|
-
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
7
|
-
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
-
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
13
|
-
* import { knex } from './database';
|
|
14
|
-
* import { User } from './models';
|
|
15
|
-
* import { test } from 'vitest';
|
|
16
|
-
*
|
|
17
|
-
* // Create isolator instance
|
|
18
|
-
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
19
|
-
*
|
|
20
|
-
* // Use with wrapped test API
|
|
21
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
22
|
-
*
|
|
23
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
24
|
-
* const user = await User.query(trx)
|
|
25
|
-
* .insert({ name: 'Test User' });
|
|
26
|
-
*
|
|
27
|
-
* expect(user).toBeDefined();
|
|
28
|
-
* // This data will be rolled back after the test
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
var VitestObjectionTransactionIsolator = class extends VitestPostgresTransactionIsolator {
|
|
33
|
-
async destroy(_conn) {}
|
|
34
|
-
/**
|
|
35
|
-
* Creates a Knex transaction with the specified isolation level.
|
|
36
|
-
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
37
|
-
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
38
|
-
*
|
|
39
|
-
* @param conn - The Knex database connection
|
|
40
|
-
* @param level - The transaction isolation level
|
|
41
|
-
* @param fn - The function to execute within the transaction
|
|
42
|
-
* @returns Promise that resolves when the transaction completes
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
47
|
-
* // Use transaction with Objection models
|
|
48
|
-
* await User.query(trx).insert({ name: 'Test' });
|
|
49
|
-
* await Post.query(trx).where('userId', user.id).delete();
|
|
50
|
-
* });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
async transact(connection, level, fn) {
|
|
54
|
-
const isolationLevel = level.toLowerCase();
|
|
55
|
-
await connection.transaction(async (trx) => {
|
|
56
|
-
await fn(trx);
|
|
57
|
-
}, { isolationLevel });
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
export { VitestObjectionTransactionIsolator };
|
|
63
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-B_VSWFum.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestObjectionTransactionIsolator-B_VSWFum.mjs","names":["_conn: Knex<any, any[]>","connection: Knex","level: IsolationLevel","fn: (trx: Knex.Transaction) => Promise<void>"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n\tKnex,\n\tKnex.Transaction\n> {\n\tasync destroy(_conn: Knex<any, any[]>): Promise<void> {}\n\t/**\n\t * Creates a Knex transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t * This transaction can be used with Objection.js models via Model.query(trx).\n\t *\n\t * @param conn - The Knex database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t *\n\t * @example\n\t * ```typescript\n\t * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n\t * // Use transaction with Objection models\n\t * await User.query(trx).insert({ name: 'Test' });\n\t * await Post.query(trx).where('userId', user.id).delete();\n\t * });\n\t * ```\n\t */\n\tasync transact(\n\t\tconnection: Knex,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Knex.Transaction) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n\t\tawait connection.transaction(\n\t\t\tasync (trx) => {\n\t\t\t\tawait fn(trx);\n\t\t\t},\n\t\t\t{\n\t\t\t\tisolationLevel,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwD,kCAGtD;CACD,MAAM,QAAQA,OAAwC,CAAE;;;;;;;;;;;;;;;;;;;;CAoBxD,MAAM,SACLC,YACAC,OACAC,IACgB;EAChB,MAAM,iBAAiB,MAAM,aAAa;AAE1C,QAAM,WAAW,YAChB,OAAO,QAAQ;AACd,SAAM,GAAG,IAAI;EACb,GACD,EACC,eACA,EACD;CACD;AACD"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-glcxyS_R.cjs";
|
|
2
|
-
import { Knex } from "knex";
|
|
3
|
-
|
|
4
|
-
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
8
|
-
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
9
|
-
* Each test runs within a database transaction that is rolled back after completion,
|
|
10
|
-
* ensuring a clean state between tests without the overhead of recreating data.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
15
|
-
* import { knex } from './database';
|
|
16
|
-
* import { User } from './models';
|
|
17
|
-
* import { test } from 'vitest';
|
|
18
|
-
*
|
|
19
|
-
* // Create isolator instance
|
|
20
|
-
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
21
|
-
*
|
|
22
|
-
* // Use with wrapped test API
|
|
23
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
24
|
-
*
|
|
25
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
26
|
-
* const user = await User.query(trx)
|
|
27
|
-
* .insert({ name: 'Test User' });
|
|
28
|
-
*
|
|
29
|
-
* expect(user).toBeDefined();
|
|
30
|
-
* // This data will be rolled back after the test
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
|
|
35
|
-
destroy(_conn: Knex<any, any[]>): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a Knex transaction with the specified isolation level.
|
|
38
|
-
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
39
|
-
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
40
|
-
*
|
|
41
|
-
* @param conn - The Knex database connection
|
|
42
|
-
* @param level - The transaction isolation level
|
|
43
|
-
* @param fn - The function to execute within the transaction
|
|
44
|
-
* @returns Promise that resolves when the transaction completes
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
49
|
-
* // Use transaction with Objection models
|
|
50
|
-
* await User.query(trx).insert({ name: 'Test' });
|
|
51
|
-
* await Post.query(trx).where('userId', user.id).delete();
|
|
52
|
-
* });
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator.d.ts.map
|
|
58
|
-
//#endregion
|
|
59
|
-
export { VitestObjectionTransactionIsolator };
|
|
60
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-CTTjvTPO.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestObjectionTransactionIsolator-CTTjvTPO.d.cts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;AAAyF;;;;;;;;;;;;;;cAA5E,kCAAA,SAA2C,kCACvD,MACA,IAAA,CAAK;iBAEgB,mBAAmB;;;;;;;;;;;;;;;;;;;;uBAqB3B,aACL,0BACG,IAAA,CAAK,gBAAgB,gBAC7B"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BLaw80cx.mjs";
|
|
2
|
-
import { Knex } from "knex";
|
|
3
|
-
|
|
4
|
-
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
8
|
-
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
9
|
-
* Each test runs within a database transaction that is rolled back after completion,
|
|
10
|
-
* ensuring a clean state between tests without the overhead of recreating data.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
15
|
-
* import { knex } from './database';
|
|
16
|
-
* import { User } from './models';
|
|
17
|
-
* import { test } from 'vitest';
|
|
18
|
-
*
|
|
19
|
-
* // Create isolator instance
|
|
20
|
-
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
21
|
-
*
|
|
22
|
-
* // Use with wrapped test API
|
|
23
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
24
|
-
*
|
|
25
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
26
|
-
* const user = await User.query(trx)
|
|
27
|
-
* .insert({ name: 'Test User' });
|
|
28
|
-
*
|
|
29
|
-
* expect(user).toBeDefined();
|
|
30
|
-
* // This data will be rolled back after the test
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
declare class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<Knex, Knex.Transaction> {
|
|
35
|
-
destroy(_conn: Knex<any, any[]>): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a Knex transaction with the specified isolation level.
|
|
38
|
-
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
39
|
-
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
40
|
-
*
|
|
41
|
-
* @param conn - The Knex database connection
|
|
42
|
-
* @param level - The transaction isolation level
|
|
43
|
-
* @param fn - The function to execute within the transaction
|
|
44
|
-
* @returns Promise that resolves when the transaction completes
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
49
|
-
* // Use transaction with Objection models
|
|
50
|
-
* await User.query(trx).insert({ name: 'Test' });
|
|
51
|
-
* await Post.query(trx).where('userId', user.id).delete();
|
|
52
|
-
* });
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator.d.ts.map
|
|
58
|
-
//#endregion
|
|
59
|
-
export { VitestObjectionTransactionIsolator };
|
|
60
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-CyZG6nq4.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestObjectionTransactionIsolator-CyZG6nq4.d.mts","names":[],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;AAAyF;;;;;;;;;;;;;;cAA5E,kCAAA,SAA2C,kCACvD,MACA,IAAA,CAAK;iBAEgB,mBAAmB;;;;;;;;;;;;;;;;;;;;uBAqB3B,aACL,0BACG,IAAA,CAAK,gBAAgB,gBAC7B"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-DyiX-QtK.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/VitestObjectionTransactionIsolator.ts
|
|
4
|
-
/**
|
|
5
|
-
* Objection.js-specific implementation of the Vitest transaction isolator.
|
|
6
|
-
* Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.
|
|
7
|
-
* Each test runs within a database transaction that is rolled back after completion,
|
|
8
|
-
* ensuring a clean state between tests without the overhead of recreating data.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';
|
|
13
|
-
* import { knex } from './database';
|
|
14
|
-
* import { User } from './models';
|
|
15
|
-
* import { test } from 'vitest';
|
|
16
|
-
*
|
|
17
|
-
* // Create isolator instance
|
|
18
|
-
* const isolator = new VitestObjectionTransactionIsolator(test);
|
|
19
|
-
*
|
|
20
|
-
* // Use with wrapped test API
|
|
21
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction(knex);
|
|
22
|
-
*
|
|
23
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
24
|
-
* const user = await User.query(trx)
|
|
25
|
-
* .insert({ name: 'Test User' });
|
|
26
|
-
*
|
|
27
|
-
* expect(user).toBeDefined();
|
|
28
|
-
* // This data will be rolled back after the test
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
var VitestObjectionTransactionIsolator = class extends require_VitestTransactionIsolator.VitestPostgresTransactionIsolator {
|
|
33
|
-
async destroy(_conn) {}
|
|
34
|
-
/**
|
|
35
|
-
* Creates a Knex transaction with the specified isolation level.
|
|
36
|
-
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
37
|
-
* This transaction can be used with Objection.js models via Model.query(trx).
|
|
38
|
-
*
|
|
39
|
-
* @param conn - The Knex database connection
|
|
40
|
-
* @param level - The transaction isolation level
|
|
41
|
-
* @param fn - The function to execute within the transaction
|
|
42
|
-
* @returns Promise that resolves when the transaction completes
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {
|
|
47
|
-
* // Use transaction with Objection models
|
|
48
|
-
* await User.query(trx).insert({ name: 'Test' });
|
|
49
|
-
* await Post.query(trx).where('userId', user.id).delete();
|
|
50
|
-
* });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
async transact(connection, level, fn) {
|
|
54
|
-
const isolationLevel = level.toLowerCase();
|
|
55
|
-
await connection.transaction(async (trx) => {
|
|
56
|
-
await fn(trx);
|
|
57
|
-
}, { isolationLevel });
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
Object.defineProperty(exports, 'VitestObjectionTransactionIsolator', {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return VitestObjectionTransactionIsolator;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-DDoJTu7e.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestObjectionTransactionIsolator-DDoJTu7e.cjs","names":["VitestPostgresTransactionIsolator","_conn: Knex<any, any[]>","connection: Knex","level: IsolationLevel","fn: (trx: Knex.Transaction) => Promise<void>"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n\ttype IsolationLevel,\n\tVitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n\tKnex,\n\tKnex.Transaction\n> {\n\tasync destroy(_conn: Knex<any, any[]>): Promise<void> {}\n\t/**\n\t * Creates a Knex transaction with the specified isolation level.\n\t * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n\t * This transaction can be used with Objection.js models via Model.query(trx).\n\t *\n\t * @param conn - The Knex database connection\n\t * @param level - The transaction isolation level\n\t * @param fn - The function to execute within the transaction\n\t * @returns Promise that resolves when the transaction completes\n\t *\n\t * @example\n\t * ```typescript\n\t * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n\t * // Use transaction with Objection models\n\t * await User.query(trx).insert({ name: 'Test' });\n\t * await Post.query(trx).where('userId', user.id).delete();\n\t * });\n\t * ```\n\t */\n\tasync transact(\n\t\tconnection: Knex,\n\t\tlevel: IsolationLevel,\n\t\tfn: (trx: Knex.Transaction) => Promise<void>,\n\t): Promise<void> {\n\t\tconst isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n\t\tawait connection.transaction(\n\t\t\tasync (trx) => {\n\t\t\t\tawait fn(trx);\n\t\t\t},\n\t\t\t{\n\t\t\t\tisolationLevel,\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwDA,oEAGtD;CACD,MAAM,QAAQC,OAAwC,CAAE;;;;;;;;;;;;;;;;;;;;CAoBxD,MAAM,SACLC,YACAC,OACAC,IACgB;EAChB,MAAM,iBAAiB,MAAM,aAAa;AAE1C,QAAM,WAAW,YAChB,OAAO,QAAQ;AACd,SAAM,GAAG,IAAI;EACb,GACD,EACC,eACA,EACD;CACD;AACD"}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { Service } from "@geekmidas/services";
|
|
2
|
-
import { TestAPI } from "vitest";
|
|
3
|
-
|
|
4
|
-
//#region src/VitestTransactionIsolator.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Type definition for test fixtures that provide transaction access.
|
|
8
|
-
* Used with Vitest's test.extend() API to inject transactions into tests.
|
|
9
|
-
*
|
|
10
|
-
* @template Transaction - The transaction type specific to the database driver
|
|
11
|
-
* @template Extended - Additional context properties provided by the extend function
|
|
12
|
-
*/
|
|
13
|
-
interface DatabaseFixtures<Transaction, _Extended = object> {
|
|
14
|
-
/**
|
|
15
|
-
* The database transaction available to the test.
|
|
16
|
-
* All database operations should use this transaction to ensure proper rollback.
|
|
17
|
-
*/
|
|
18
|
-
trx: Transaction;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Combined fixtures type that merges the base transaction fixture with extended context.
|
|
22
|
-
*/
|
|
23
|
-
type ExtendedDatabaseFixtures<Transaction, Extended = object> = DatabaseFixtures<Transaction> & Extended;
|
|
24
|
-
/**
|
|
25
|
-
* Function type for extending test context with additional properties.
|
|
26
|
-
* Receives the transaction and returns additional context to be merged with { trx }.
|
|
27
|
-
*
|
|
28
|
-
* @template Transaction - The transaction type
|
|
29
|
-
* @template Extended - The type of additional context to provide
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const extendContext: ExtendContextFn<Transaction<DB>, { factory: KyselyFactory }> =
|
|
34
|
-
* (trx) => ({ factory: new KyselyFactory(builders, seeds, trx) });
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
type ExtendContextFn<Transaction, Extended> = (trx: Transaction) => Extended | Promise<Extended>;
|
|
38
|
-
/**
|
|
39
|
-
* PostgreSQL transaction isolation levels.
|
|
40
|
-
* Controls the visibility of concurrent transactions.
|
|
41
|
-
*
|
|
42
|
-
* @see https://www.postgresql.org/docs/current/transaction-iso.html
|
|
43
|
-
*/
|
|
44
|
-
declare enum IsolationLevel {
|
|
45
|
-
/**
|
|
46
|
-
* Lowest isolation level. Allows dirty reads.
|
|
47
|
-
* Not recommended for testing.
|
|
48
|
-
*/
|
|
49
|
-
READ_UNCOMMITTED = "READ UNCOMMITTED",
|
|
50
|
-
/**
|
|
51
|
-
* Default PostgreSQL isolation level.
|
|
52
|
-
* Prevents dirty reads but allows non-repeatable reads.
|
|
53
|
-
*/
|
|
54
|
-
READ_COMMITTED = "READ COMMITTED",
|
|
55
|
-
/**
|
|
56
|
-
* Prevents dirty reads and non-repeatable reads.
|
|
57
|
-
* Recommended for most test scenarios.
|
|
58
|
-
*/
|
|
59
|
-
REPEATABLE_READ = "REPEATABLE READ",
|
|
60
|
-
/**
|
|
61
|
-
* Highest isolation level. Prevents all phenomena.
|
|
62
|
-
* May cause performance overhead in tests.
|
|
63
|
-
*/
|
|
64
|
-
SERIALIZABLE = "SERIALIZABLE",
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Abstract base class for implementing database transaction isolation in Vitest tests.
|
|
68
|
-
* Provides automatic transaction rollback after each test to maintain test isolation.
|
|
69
|
-
* Subclasses must implement the transact() method for their specific database driver.
|
|
70
|
-
*
|
|
71
|
-
* @template TConn - The database connection type
|
|
72
|
-
* @template Transaction - The transaction type
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // Implement for your database driver
|
|
77
|
-
* class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {
|
|
78
|
-
* async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {
|
|
79
|
-
* await conn.transaction(level, fn);
|
|
80
|
-
* }
|
|
81
|
-
* }
|
|
82
|
-
*
|
|
83
|
-
* // Use in tests
|
|
84
|
-
* const isolator = new MyDatabaseIsolator(test);
|
|
85
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction(db);
|
|
86
|
-
*
|
|
87
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
88
|
-
* await trx.insert('users', { name: 'Test' });
|
|
89
|
-
* // Data is automatically rolled back after test
|
|
90
|
-
* });
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
declare abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {
|
|
94
|
-
private readonly api;
|
|
95
|
-
/**
|
|
96
|
-
* Abstract method to create a transaction with the specified isolation level.
|
|
97
|
-
* Must be implemented by subclasses for specific database drivers.
|
|
98
|
-
*
|
|
99
|
-
* @param conn - The database connection
|
|
100
|
-
* @param isolationLevel - The transaction isolation level
|
|
101
|
-
* @param fn - The function to execute within the transaction
|
|
102
|
-
* @returns Promise that resolves when the transaction completes
|
|
103
|
-
*/
|
|
104
|
-
abstract transact(conn: TConn, isolationLevel: IsolationLevel, fn: (trx: Transaction) => Promise<void>): Promise<void>;
|
|
105
|
-
abstract destroy(conn: TConn): Promise<void>;
|
|
106
|
-
/**
|
|
107
|
-
* Creates a new VitestPostgresTransactionIsolator instance.
|
|
108
|
-
*
|
|
109
|
-
* @param api - The Vitest test API (usually the `test` export from vitest)
|
|
110
|
-
*/
|
|
111
|
-
constructor(api: TestAPI);
|
|
112
|
-
/**
|
|
113
|
-
* Creates a wrapped version of Vitest's test API that provides transaction isolation.
|
|
114
|
-
* Each test will run within a database transaction that is automatically rolled back.
|
|
115
|
-
*
|
|
116
|
-
* @param options - Configuration options for transaction wrapping
|
|
117
|
-
* @returns A wrapped test API with transaction support
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction({
|
|
122
|
-
* connection: db,
|
|
123
|
-
* setup: async (trx) => {
|
|
124
|
-
* await trx.insert('settings', { key: 'test', value: 'true' });
|
|
125
|
-
* },
|
|
126
|
-
* fixtures: {
|
|
127
|
-
* factory: (trx) => new Factory(trx),
|
|
128
|
-
* },
|
|
129
|
-
* });
|
|
130
|
-
*
|
|
131
|
-
* isolatedTest('test with transaction', async ({ trx, factory }) => {
|
|
132
|
-
* const user = await factory.insert('user', { name: 'Test' });
|
|
133
|
-
* expect(user).toBeDefined();
|
|
134
|
-
* });
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
wrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(options: TransactionWrapperOptions<TConn, Transaction, Extended>): TestAPI<DatabaseFixtures<Transaction, object> & Extended>;
|
|
138
|
-
}
|
|
139
|
-
type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;
|
|
140
|
-
/**
|
|
141
|
-
* Where a connection comes from: a construct, or a function returning one.
|
|
142
|
-
*
|
|
143
|
-
* A construct is preferred, because it builds the client through the same
|
|
144
|
-
* `connect()` production uses. A hand-rolled client missing `CamelCasePlugin`
|
|
145
|
-
* writes `createdAt` where the app writes `created_at`, and the test passes
|
|
146
|
-
* while production does not. The URL is read from `process.env`.
|
|
147
|
-
*/
|
|
148
|
-
type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn> | ConnectableConstruct<Conn>;
|
|
149
|
-
/**
|
|
150
|
-
* Options for wrapping Vitest tests with database transaction isolation.
|
|
151
|
-
*/
|
|
152
|
-
/**
|
|
153
|
-
* Anything that owns a service handing back a connection — a database
|
|
154
|
-
* construct, structurally, so testkit depends on no construct package.
|
|
155
|
-
*/
|
|
156
|
-
interface ConnectableConstruct<TConn> {
|
|
157
|
-
readonly service: Service<string, TConn>;
|
|
158
|
-
}
|
|
159
|
-
interface TransactionWrapperOptions<TConn, Transaction, Extended extends Record<string, unknown> = {}> {
|
|
160
|
-
/** Where the connection comes from — a construct, or a function returning one */
|
|
161
|
-
connection: DatabaseConnection<TConn>;
|
|
162
|
-
/** Optional setup function to run within the transaction before each test */
|
|
163
|
-
setup?: (trx: Transaction) => Promise<void>;
|
|
164
|
-
/** Transaction isolation level (defaults to REPEATABLE_READ) */
|
|
165
|
-
isolationLevel?: IsolationLevel;
|
|
166
|
-
/** Additional fixtures that depend on the transaction */
|
|
167
|
-
fixtures?: FixtureCreators<Transaction, Extended>;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Type for fixture creator functions that depend on the transaction.
|
|
171
|
-
* Each function receives the transaction and returns the fixture value.
|
|
172
|
-
*/
|
|
173
|
-
type FixtureCreators<Transaction, Extended extends Record<string, unknown>> = { [K in keyof Extended]: (trx: Transaction) => Extended[K] | Promise<Extended[K]> };
|
|
174
|
-
/**
|
|
175
|
-
* The test API returned by extendWithFixtures.
|
|
176
|
-
* Provides access to both the transaction (trx) and all extended fixtures.
|
|
177
|
-
*
|
|
178
|
-
* @template Transaction - The transaction type
|
|
179
|
-
* @template Extended - The type of additional fixtures provided
|
|
180
|
-
* @template BaseTest - The base wrapped test type
|
|
181
|
-
*/
|
|
182
|
-
type TestWithExtendedFixtures<Transaction, Extended extends Record<string, unknown>, BaseTest extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>> = BaseTest & {
|
|
183
|
-
<C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction> & Extended & C) => Promise<void>): void;
|
|
184
|
-
<C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction> & Extended & C) => Promise<void>): void;
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Extends a wrapped test API with additional fixtures that depend on the transaction.
|
|
188
|
-
* This allows composing test context with factories, repositories, or other helpers.
|
|
189
|
-
*
|
|
190
|
-
* @template Transaction - The transaction type
|
|
191
|
-
* @template Extended - The type of additional context to provide
|
|
192
|
-
* @param wrappedTest - The base wrapped test from wrapVitestWithTransaction
|
|
193
|
-
* @param fixtures - Object mapping fixture names to creator functions
|
|
194
|
-
* @returns An extended test API with both trx and the additional fixtures
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* import { wrapVitestKyselyTransaction, extendWithFixtures } from '@geekmidas/testkit/kysely';
|
|
199
|
-
*
|
|
200
|
-
* // Create base wrapped test
|
|
201
|
-
* const baseTest = wrapVitestKyselyTransaction(test, {
|
|
202
|
-
* connection: db,
|
|
203
|
-
* setup: createTestTables,
|
|
204
|
-
* });
|
|
205
|
-
*
|
|
206
|
-
* // Extend with fixtures
|
|
207
|
-
* const it = extendWithFixtures(baseTest, {
|
|
208
|
-
* factory: (trx) => new KyselyFactory(builders, seeds, trx),
|
|
209
|
-
* userRepo: (trx) => new UserRepository(trx),
|
|
210
|
-
* });
|
|
211
|
-
*
|
|
212
|
-
* // Use in tests - trx and all fixtures are available
|
|
213
|
-
* it('should create user with factory', async ({ trx, factory, userRepo }) => {
|
|
214
|
-
* const user = await factory.insert('user', { name: 'Test' });
|
|
215
|
-
* expect(user).toBeDefined();
|
|
216
|
-
* });
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
declare function extendWithFixtures<Transaction, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = any>(wrappedTest: T, fixtures: FixtureCreators<Transaction, Extended>): TestWithExtendedFixtures<Transaction, Extended, T>;
|
|
220
|
-
//# sourceMappingURL=VitestTransactionIsolator.d.ts.map
|
|
221
|
-
//#endregion
|
|
222
|
-
export { ConnectableConstruct, DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures };
|
|
223
|
-
//# sourceMappingURL=VitestTransactionIsolator-BLaw80cx.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VitestTransactionIsolator-BLaw80cx.d.mts","names":[],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWA;AAWA;;;;AAGoC,UAdnB,gBAcmB,CAAA,WAAA,EAAA,YAAA,MAAA,CAAA,CAAA;EAAQ;AAe5C;;;EACiB,GACZ,EA1BC,WA0BD;;;AAAkB;AAQvB;AAkDsB,KA9EV,wBA8EU,CAAA,WAAiC,EAAA,WAAA,MAAA,CAAA,GA3EnD,gBA2EmD,CA3ElC,WA2EkC,CAAA,GA3EnB,QA2EmB;;;;;;;;;;;;;;AAkD5C,KA9GC,eA8GD,CAAA,WAAA,EAAA,QAAA,CAAA,GAAA,CAAA,GAAA,EA7GL,WA6GK,EAAA,GA5GN,QA4GM,GA5GK,OA4GL,CA5Ga,QA4Gb,CAAA;;;;;AAAuD;AA8FlE;AAAgC,aAlMpB,cAAA;EAkMoB;;;AAA6B;EAUjD,gBAAA,GAAA,kBAAkB;EAAA;;;;EAEF,cAAzB,GAAA,gBAAA;EAAoB;AAgBvB;;;EACwC,eAArB,GAAA,iBAAA;EAAO;AAG1B;;;EAGwB,YAGQ,GAAA,cAAA;;;;;;;;AAML;AAO3B;;;;;;;;;;AAM2B;AAW3B;;;;;;;;;AAUY,uBA9NU,iCA8NV,CAAA,KAAA,EAAA,WAAA,CAAA,CAAA;EAAgB,iBAAgB,GAAA;EAAQ;;;;;;;AAQtC;AAqCd;EAAkC,SAAA,QAAA,CAAA,IAAA,EAhQ1B,KAgQ0B,EAAA,cAAA,EA/PhB,cA+PgB,EAAA,EAAA,EAAA,CAAA,GAAA,EA9PtB,WA8PsB,EAAA,GA9PN,OA8PM,CAAA,IAAA,CAAA,CAAA,EA7P9B,OA6P8B,CAAA,IAAA,CAAA;EAAA,SAEhB,OAAA,CAAA,IAAA,EA7PM,KA6PN,CAAA,EA7Pc,OA6Pd,CAAA,IAAA,CAAA;EAAM;;;;;EAKwB,WAArC,CAAA,GAAA,EA5PwB,OA4PxB;EAAe;;;;AACC;;;;;;;;;;;;;;;;;;;;;6CAlOiB,uCACjC,0BAA0B,OAAO,aAAa,YAAS,QAAA,iBAAA,uBAAA;;KA8FtD,mCAAmC,OAAO,QAAQ;;;;;;;;;KAUlD,2BACT,qBAAqB,QACrB,qBAAqB;;;;;;;;UAgBP;oBACE,gBAAgB;;UAGlB,+DAGC;;cAGL,mBAAmB;;gBAEjB,gBAAgB;;mBAEb;;aAEN,gBAAgB,aAAa;;;;;;KAO7B,8CAEM,yCAEL,iBACN,gBACD,SAAS,KAAK,QAAQ,SAAS;;;;;;;;;KAWzB,uDAEM,0CACA,WAAW,qBAAqB,WAChD,sBAEE;iDAIQ,iBAAiB,eAAe,WAAW,MAChD;kEAMK,iBAAiB,eAAe,WAAW,MAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqCS,iDAEE,mCAEP,WAAW,uCAER,aACH,gBAAgB,aAAa,YACrC,yBAAyB,aAAa,UAAU"}
|