@geekmidas/testkit 0.0.14 → 0.0.16
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/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
- package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-Cmr3s3-s.d.mts} +3 -2
- package/dist/Factory-WMhTNZ9S.cjs +2 -1
- package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
- package/dist/Factory-z2m01hMj.mjs +2 -1
- package/dist/Factory-z2m01hMj.mjs.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
- package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
- package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
- package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
- package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-Cx3sezwH.d.mts} +4 -3
- package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
- package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
- package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C-59Hjwj.d.mts} +4 -3
- package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
- package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
- package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
- package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
- package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
- package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs → VitestKyselyTransactionIsolator-BxjlD1YM.mjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/{VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs → VitestKyselyTransactionIsolator-Cst3vFjb.cjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-DVtJG2F3.mjs → VitestObjectionTransactionIsolator-BU-jXEhz.mjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/{VitestObjectionTransactionIsolator-LP4B0cqW.cjs → VitestObjectionTransactionIsolator-DzeF4UAq.cjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
- package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs +126 -0
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +22 -0
- package/dist/aws.d.mts +22 -0
- package/dist/aws.mjs +123 -0
- package/dist/aws.mjs.map +1 -0
- package/dist/directory-B-Ozljzk.mjs +22 -0
- package/dist/directory-B-Ozljzk.mjs.map +1 -0
- package/dist/directory-B4oYx02C.d.mts +12 -0
- package/dist/directory-BUcnztHI.d.cts +12 -0
- package/dist/directory-BVC8g7cX.cjs +28 -0
- package/dist/directory-BVC8g7cX.cjs.map +1 -0
- package/dist/faker-B14IEMIN.cjs +2 -1
- package/dist/faker-B14IEMIN.cjs.map +1 -0
- package/dist/faker-BGKYFoCT.mjs +2 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -0
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
- package/dist/{faker-C-Iuk_R1.d.mts → faker-DHh7xs4u.d.mts} +4 -3
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/helpers.cjs +48 -2
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +2 -1
- package/dist/helpers.d.mts +2 -1
- package/dist/helpers.mjs +47 -2
- package/dist/helpers.mjs.map +1 -0
- package/dist/kysely.cjs +66 -3
- package/dist/kysely.cjs.map +1 -0
- package/dist/kysely.d.cts +5 -4
- package/dist/kysely.d.mts +9 -8
- package/dist/kysely.mjs +68 -5
- package/dist/kysely.mjs.map +1 -0
- package/dist/logger.cjs +23 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +22 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/objection.cjs +81 -3
- package/dist/objection.cjs.map +1 -0
- package/dist/objection.d.cts +5 -4
- package/dist/objection.d.mts +9 -8
- package/dist/objection.mjs +83 -5
- package/dist/objection.mjs.map +1 -0
- package/dist/os/directory.cjs +3 -0
- package/dist/os/directory.d.cts +2 -0
- package/dist/os/directory.d.mts +2 -0
- package/dist/os/directory.mjs +3 -0
- package/dist/os/index.cjs +3 -0
- package/dist/os/index.d.cts +2 -0
- package/dist/os/index.d.mts +2 -0
- package/dist/os/index.mjs +3 -0
- package/dist/timer.cjs +9 -0
- package/dist/timer.cjs.map +1 -0
- package/dist/timer.d.cts +5 -0
- package/dist/timer.d.mts +5 -0
- package/dist/timer.mjs +8 -0
- package/dist/timer.mjs.map +1 -0
- package/package.json +25 -3
- package/src/VitestKyselyTransactionIsolator.ts +2 -2
- package/src/VitestObjectionTransactionIsolator.ts +1 -3
- package/src/aws.ts +131 -0
- package/src/logger.ts +18 -0
- package/src/os/directory.ts +21 -0
- package/src/os/index.ts +1 -0
- package/src/timer.ts +3 -0
- package/dist/__tests__/Factory.spec.cjs +0 -139
- package/dist/__tests__/Factory.spec.d.cts +0 -1
- package/dist/__tests__/Factory.spec.d.mts +0 -1
- package/dist/__tests__/Factory.spec.mjs +0 -138
- package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
- package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
- package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
- package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
- package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
- package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
- package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
- package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
- package/dist/__tests__/faker.spec.cjs +0 -115
- package/dist/__tests__/faker.spec.d.cts +0 -1
- package/dist/__tests__/faker.spec.d.mts +0 -1
- package/dist/__tests__/faker.spec.mjs +0 -114
- package/dist/__tests__/integration.spec.cjs +0 -282
- package/dist/__tests__/integration.spec.d.cts +0 -1
- package/dist/__tests__/integration.spec.d.mts +0 -1
- package/dist/__tests__/integration.spec.mjs +0 -281
- package/dist/helpers-B4TXg3Wp.mjs +0 -86
- package/dist/helpers-Bf0nXhbu.cjs +0 -116
- package/dist/helpers-BuPmgzyQ.mjs +0 -47
- package/dist/helpers-nEUtQ7eo.cjs +0 -53
- package/dist/kysely-BsDbvw3r.mjs +0 -67
- package/dist/kysely-CP1iJMvq.cjs +0 -72
- package/dist/objection-BEPk9h-g.mjs +0 -82
- package/dist/objection-Di7JSist.cjs +0 -87
package/dist/kysely.mjs
CHANGED
|
@@ -1,10 +1,73 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
2
|
import "./faker-BGKYFoCT.mjs";
|
|
3
3
|
import { KyselyFactory } from "./KyselyFactory-BcYkC0t2.mjs";
|
|
4
|
-
import "./PostgresMigrator-
|
|
5
|
-
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-
|
|
4
|
+
import "./PostgresMigrator-DbuJGAVy.mjs";
|
|
5
|
+
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
8
|
-
import { wrapVitestKyselyTransaction } from "./kysely-BsDbvw3r.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BxjlD1YM.mjs";
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
//#region src/kysely.ts
|
|
10
|
+
/**
|
|
11
|
+
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
12
|
+
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
13
|
+
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
14
|
+
*
|
|
15
|
+
* @template Database - The database schema type
|
|
16
|
+
* @param api - The Vitest test API (usually `test` from vitest)
|
|
17
|
+
* @param db - The Kysely database instance
|
|
18
|
+
* @param setup - Optional setup function to run before each test in the transaction
|
|
19
|
+
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
20
|
+
* @returns A wrapped test API that provides transaction isolation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { test } from 'vitest';
|
|
25
|
+
* import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';
|
|
26
|
+
* import { db } from './database';
|
|
27
|
+
*
|
|
28
|
+
* // Create isolated test with automatic rollback
|
|
29
|
+
* const isolatedTest = wrapVitestKyselyTransaction(test, db);
|
|
30
|
+
*
|
|
31
|
+
* // Use in tests - each test gets its own transaction
|
|
32
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
33
|
+
* const user = await trx
|
|
34
|
+
* .insertInto('users')
|
|
35
|
+
* .values({ name: 'Test User', email: 'test@example.com' })
|
|
36
|
+
* .returningAll()
|
|
37
|
+
* .executeTakeFirst();
|
|
38
|
+
*
|
|
39
|
+
* expect(user).toBeDefined();
|
|
40
|
+
* // User is automatically rolled back after test
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // With setup function for common test data
|
|
44
|
+
* const testWithSetup = wrapVitestKyselyTransaction(
|
|
45
|
+
* test,
|
|
46
|
+
* db,
|
|
47
|
+
* async (trx) => {
|
|
48
|
+
* // Create common test data
|
|
49
|
+
* await trx.insertInto('settings')
|
|
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();
|
|
61
|
+
*
|
|
62
|
+
* expect(setting?.value).toBe('true');
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function wrapVitestKyselyTransaction(api, connection, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
67
|
+
const wrapper = new VitestKyselyTransactionIsolator(api);
|
|
68
|
+
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
73
|
+
//# sourceMappingURL=kysely.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely.mjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel"],"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 IsolationLevel,\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';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param db - The Kysely database instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, db);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestKyselyTransaction(\n * test,\n * db,\n * async (trx) => {\n * // Create common test data\n * await trx.insertInto('settings')\n * .values({ key: 'test_mode', value: 'true' })\n * .execute();\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await trx\n * .selectFrom('settings')\n * .where('key', '=', 'test_mode')\n * .selectAll()\n * .executeTakeFirst();\n *\n * expect(setting?.value).toBe('true');\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<Database>(\n api: TestAPI,\n connection: DatabaseConnection<Kysely<Database>>,\n setup?: (trx: Transaction<Database>) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(connection, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwB,eAAe,iBACvC;CACA,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE"}
|
package/dist/logger.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
3
|
+
|
|
4
|
+
//#region src/logger.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a mock Logger for testing
|
|
7
|
+
*/
|
|
8
|
+
function createMockLogger() {
|
|
9
|
+
const logger = {
|
|
10
|
+
debug: vitest.vi.fn(),
|
|
11
|
+
info: vitest.vi.fn(),
|
|
12
|
+
warn: vitest.vi.fn(),
|
|
13
|
+
error: vitest.vi.fn(),
|
|
14
|
+
fatal: vitest.vi.fn(),
|
|
15
|
+
trace: vitest.vi.fn(),
|
|
16
|
+
child: vitest.vi.fn(() => logger)
|
|
17
|
+
};
|
|
18
|
+
return logger;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.createMockLogger = createMockLogger;
|
|
23
|
+
//# sourceMappingURL=logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.cjs","names":["logger: Logger"],"sources":["../src/logger.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { vi } from 'vitest';\n\n/**\n * Creates a mock Logger for testing\n */\nexport function createMockLogger(): Logger {\n const logger: Logger = {\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n fatal: vi.fn(),\n trace: vi.fn(),\n child: vi.fn(() => logger),\n };\n return logger;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,mBAA2B;CACzC,MAAMA,SAAiB;EACrB,OAAO,UAAG,IAAI;EACd,MAAM,UAAG,IAAI;EACb,MAAM,UAAG,IAAI;EACb,OAAO,UAAG,IAAI;EACd,OAAO,UAAG,IAAI;EACd,OAAO,UAAG,IAAI;EACd,OAAO,UAAG,GAAG,MAAM,OAAO;CAC3B;AACD,QAAO;AACR"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from "@geekmidas/logger";
|
|
2
|
+
|
|
3
|
+
//#region src/logger.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a mock Logger for testing
|
|
7
|
+
*/
|
|
8
|
+
declare function createMockLogger(): Logger;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { createMockLogger };
|
|
11
|
+
//# sourceMappingURL=logger.d.cts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from "@geekmidas/logger";
|
|
2
|
+
|
|
3
|
+
//#region src/logger.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a mock Logger for testing
|
|
7
|
+
*/
|
|
8
|
+
declare function createMockLogger(): Logger;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { createMockLogger };
|
|
11
|
+
//# sourceMappingURL=logger.d.mts.map
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/logger.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a mock Logger for testing
|
|
6
|
+
*/
|
|
7
|
+
function createMockLogger() {
|
|
8
|
+
const logger = {
|
|
9
|
+
debug: vi.fn(),
|
|
10
|
+
info: vi.fn(),
|
|
11
|
+
warn: vi.fn(),
|
|
12
|
+
error: vi.fn(),
|
|
13
|
+
fatal: vi.fn(),
|
|
14
|
+
trace: vi.fn(),
|
|
15
|
+
child: vi.fn(() => logger)
|
|
16
|
+
};
|
|
17
|
+
return logger;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createMockLogger };
|
|
22
|
+
//# sourceMappingURL=logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":["logger: Logger"],"sources":["../src/logger.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { vi } from 'vitest';\n\n/**\n * Creates a mock Logger for testing\n */\nexport function createMockLogger(): Logger {\n const logger: Logger = {\n debug: vi.fn(),\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n fatal: vi.fn(),\n trace: vi.fn(),\n child: vi.fn(() => logger),\n };\n return logger;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,mBAA2B;CACzC,MAAMA,SAAiB;EACrB,OAAO,GAAG,IAAI;EACd,MAAM,GAAG,IAAI;EACb,MAAM,GAAG,IAAI;EACb,OAAO,GAAG,IAAI;EACd,OAAO,GAAG,IAAI;EACd,OAAO,GAAG,IAAI;EACd,OAAO,GAAG,GAAG,MAAM,OAAO;CAC3B;AACD,QAAO;AACR"}
|
package/dist/objection.cjs
CHANGED
|
@@ -4,11 +4,89 @@ const require_ObjectionFactory = require('./ObjectionFactory-CDriunkS.cjs');
|
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
7
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-
|
|
8
|
-
const require_objection = require('./objection-Di7JSist.cjs');
|
|
7
|
+
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-DzeF4UAq.cjs');
|
|
9
8
|
|
|
9
|
+
//#region src/objection.ts
|
|
10
|
+
/**
|
|
11
|
+
* Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
|
|
12
|
+
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
13
|
+
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
14
|
+
*
|
|
15
|
+
* @param api - The Vitest test API (usually `test` from vitest)
|
|
16
|
+
* @param conn - The Knex database connection instance
|
|
17
|
+
* @param setup - Optional setup function to run before each test in the transaction
|
|
18
|
+
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
19
|
+
* @returns A wrapped test API that provides transaction isolation
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { test } from 'vitest';
|
|
24
|
+
* import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
|
|
25
|
+
* import { knex } from './database';
|
|
26
|
+
* import { User, Post } from './models';
|
|
27
|
+
*
|
|
28
|
+
* // Create isolated test with automatic rollback
|
|
29
|
+
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
30
|
+
*
|
|
31
|
+
* // Use in tests - each test gets its own transaction
|
|
32
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
33
|
+
* const user = await User.query(trx)
|
|
34
|
+
* .insert({ name: 'Test User', email: 'test@example.com' });
|
|
35
|
+
*
|
|
36
|
+
* expect(user).toBeDefined();
|
|
37
|
+
* // User is automatically rolled back after test
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // With setup function for common test data
|
|
41
|
+
* const testWithSetup = wrapVitestObjectionTransaction(
|
|
42
|
+
* test,
|
|
43
|
+
* knex,
|
|
44
|
+
* async (trx) => {
|
|
45
|
+
* // Create common test data
|
|
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');
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // Example with factory and transaction
|
|
62
|
+
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
63
|
+
* const factory = new ObjectionFactory(builders, seeds, knex);
|
|
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);
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function wrapVitestObjectionTransaction(api, conn, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
82
|
+
const wrapper = new require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator(api);
|
|
83
|
+
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
10
87
|
exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
|
|
11
88
|
exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
|
|
12
89
|
exports.PostgresObjectionMigrator = require_PostgresObjectionMigrator.PostgresObjectionMigrator;
|
|
13
90
|
exports.VitestObjectionTransactionIsolator = require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator;
|
|
14
|
-
exports.wrapVitestObjectionTransaction =
|
|
91
|
+
exports.wrapVitestObjectionTransaction = wrapVitestObjectionTransaction;
|
|
92
|
+
//# sourceMappingURL=objection.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objection.cjs","names":["api: TestAPI","conn: DatabaseConnection<Knex>","setup?: (trx: Knex.Transaction) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestObjectionTransactionIsolator"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n IsolationLevel,\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';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param conn - The Knex database connection instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, Post } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestObjectionTransaction(\n * test,\n * knex,\n * async (trx) => {\n * // Create common test data\n * await knex('settings')\n * .transacting(trx)\n * .insert({ key: 'test_mode', value: 'true' });\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await knex('settings')\n * .transacting(trx)\n * .where('key', 'test_mode')\n * .first();\n *\n * expect(setting?.value).toBe('true');\n * });\n *\n * // Example with factory and transaction\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * isolatedTest('creates related data', async ({ trx }) => {\n * // Factory can use the transaction\n * const user = await User.query(trx).insert({ name: 'Author' });\n * const posts = await Post.query(trx).insert([\n * { title: 'Post 1', userId: user.id },\n * { title: 'Post 2', userId: user.id }\n * ]);\n *\n * const userWithPosts = await User.query(trx)\n * .findById(user.id)\n * .withGraphFetched('posts');\n *\n * expect(userWithPosts.posts).toHaveLength(2);\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction(\n api: TestAPI,\n conn: DatabaseConnection<Knex>,\n setup?: (trx: Knex.Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(conn, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,+BACdA,KACAC,MACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,MAAM,OAAO,MAAM;AAC7D"}
|
package/dist/objection.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-Cg76aFNO.cjs";
|
|
2
|
+
import "./Factory-BZ8uMoXl.cjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-C4X78k0B.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-CZHHcCOv.cjs";
|
|
6
6
|
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
|
|
@@ -85,4 +85,5 @@ declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConn
|
|
|
85
85
|
trx: Knex.Transaction<any, any[]>;
|
|
86
86
|
}>;
|
|
87
87
|
//#endregion
|
|
88
|
-
export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
|
|
88
|
+
export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
|
|
89
|
+
//# sourceMappingURL=objection.d.cts.map
|
package/dist/objection.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
4
|
-
import "./PostgresMigrator-
|
|
5
|
-
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-
|
|
6
|
-
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./faker-DHh7xs4u.mjs";
|
|
2
|
+
import "./Factory-Cmr3s3-s.mjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-C-59Hjwj.mjs";
|
|
4
|
+
import "./PostgresMigrator-DQaRxoaY.mjs";
|
|
5
|
+
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-D_hCcrQu.mjs";
|
|
6
|
+
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
7
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-b973r9O1.mjs";
|
|
8
8
|
import { TestAPI } from "vitest";
|
|
9
9
|
import { Knex } from "knex";
|
|
10
10
|
|
|
@@ -85,4 +85,5 @@ declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConn
|
|
|
85
85
|
trx: Knex.Transaction<any, any[]>;
|
|
86
86
|
}>;
|
|
87
87
|
//#endregion
|
|
88
|
-
export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
|
|
88
|
+
export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
|
|
89
|
+
//# sourceMappingURL=objection.d.mts.map
|
package/dist/objection.mjs
CHANGED
|
@@ -1,10 +1,88 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
2
|
import "./faker-BGKYFoCT.mjs";
|
|
3
3
|
import { ObjectionFactory } from "./ObjectionFactory-8hebmnai.mjs";
|
|
4
|
-
import "./PostgresMigrator-
|
|
5
|
-
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-
|
|
4
|
+
import "./PostgresMigrator-DbuJGAVy.mjs";
|
|
5
|
+
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-DPj2pOpX.mjs";
|
|
6
6
|
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
7
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
8
|
-
import { wrapVitestObjectionTransaction } from "./objection-BEPk9h-g.mjs";
|
|
7
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-BU-jXEhz.mjs";
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
//#region src/objection.ts
|
|
10
|
+
/**
|
|
11
|
+
* Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
|
|
12
|
+
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
13
|
+
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
14
|
+
*
|
|
15
|
+
* @param api - The Vitest test API (usually `test` from vitest)
|
|
16
|
+
* @param conn - The Knex database connection instance
|
|
17
|
+
* @param setup - Optional setup function to run before each test in the transaction
|
|
18
|
+
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
19
|
+
* @returns A wrapped test API that provides transaction isolation
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { test } from 'vitest';
|
|
24
|
+
* import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
|
|
25
|
+
* import { knex } from './database';
|
|
26
|
+
* import { User, Post } from './models';
|
|
27
|
+
*
|
|
28
|
+
* // Create isolated test with automatic rollback
|
|
29
|
+
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
30
|
+
*
|
|
31
|
+
* // Use in tests - each test gets its own transaction
|
|
32
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
33
|
+
* const user = await User.query(trx)
|
|
34
|
+
* .insert({ name: 'Test User', email: 'test@example.com' });
|
|
35
|
+
*
|
|
36
|
+
* expect(user).toBeDefined();
|
|
37
|
+
* // User is automatically rolled back after test
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // With setup function for common test data
|
|
41
|
+
* const testWithSetup = wrapVitestObjectionTransaction(
|
|
42
|
+
* test,
|
|
43
|
+
* knex,
|
|
44
|
+
* async (trx) => {
|
|
45
|
+
* // Create common test data
|
|
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');
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // Example with factory and transaction
|
|
62
|
+
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
63
|
+
* const factory = new ObjectionFactory(builders, seeds, knex);
|
|
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);
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function wrapVitestObjectionTransaction(api, conn, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
82
|
+
const wrapper = new VitestObjectionTransactionIsolator(api);
|
|
83
|
+
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
|
|
88
|
+
//# sourceMappingURL=objection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objection.mjs","names":["api: TestAPI","conn: DatabaseConnection<Knex>","setup?: (trx: Knex.Transaction) => Promise<void>","level: IsolationLevel"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n IsolationLevel,\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';\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param conn - The Knex database connection instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\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, Post } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\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 * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestObjectionTransaction(\n * test,\n * knex,\n * async (trx) => {\n * // Create common test data\n * await knex('settings')\n * .transacting(trx)\n * .insert({ key: 'test_mode', value: 'true' });\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await knex('settings')\n * .transacting(trx)\n * .where('key', 'test_mode')\n * .first();\n *\n * expect(setting?.value).toBe('true');\n * });\n *\n * // Example with factory and transaction\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * isolatedTest('creates related data', async ({ trx }) => {\n * // Factory can use the transaction\n * const user = await User.query(trx).insert({ name: 'Author' });\n * const posts = await Post.query(trx).insert([\n * { title: 'Post 1', userId: user.id },\n * { title: 'Post 2', userId: user.id }\n * ]);\n *\n * const userWithPosts = await User.query(trx)\n * .findById(user.id)\n * .withGraphFetched('posts');\n *\n * expect(userWithPosts.posts).toHaveLength(2);\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction(\n api: TestAPI,\n conn: DatabaseConnection<Knex>,\n setup?: (trx: Knex.Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(conn, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,+BACdA,KACAC,MACAC,OACAC,QAAwB,eAAe,iBACvC;CACA,MAAM,UAAU,IAAI,mCAAmC;AAEvD,QAAO,QAAQ,0BAA0B,MAAM,OAAO,MAAM;AAC7D"}
|
package/dist/timer.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.cjs","names":["ms: number"],"sources":["../src/timer.ts"],"sourcesContent":["export function waitFor(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;AAAA,SAAgB,QAAQA,IAAY;AAClC,QAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;AACxD"}
|
package/dist/timer.d.cts
ADDED
package/dist/timer.d.mts
ADDED
package/dist/timer.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.mjs","names":["ms: number"],"sources":["../src/timer.ts"],"sourcesContent":["export function waitFor(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";AAAA,SAAgB,QAAQA,IAAY;AAClC,QAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;AACxD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/testkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -9,19 +9,40 @@
|
|
|
9
9
|
"import": "./dist/objection.mjs",
|
|
10
10
|
"require": "./dist/objection.cjs"
|
|
11
11
|
},
|
|
12
|
+
"./timer": {
|
|
13
|
+
"types": "./dist/timer.d.ts",
|
|
14
|
+
"import": "./dist/timer.mjs",
|
|
15
|
+
"require": "./dist/timer.cjs"
|
|
16
|
+
},
|
|
12
17
|
"./kysely": {
|
|
13
18
|
"types": "./dist/kysely.d.ts",
|
|
14
19
|
"import": "./dist/kysely.mjs",
|
|
15
20
|
"require": "./dist/kysely.cjs"
|
|
16
21
|
},
|
|
22
|
+
"./os": {
|
|
23
|
+
"types": "./dist/os/index.d.ts",
|
|
24
|
+
"import": "./dist/os/index.mjs",
|
|
25
|
+
"require": "./dist/os/index.cjs"
|
|
26
|
+
},
|
|
17
27
|
"./faker": {
|
|
18
28
|
"types": "./dist/faker.d.ts",
|
|
19
29
|
"import": "./dist/faker.mjs",
|
|
20
30
|
"require": "./dist/faker.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./aws": {
|
|
33
|
+
"types": "./dist/aws.d.ts",
|
|
34
|
+
"import": "./dist/aws.mjs",
|
|
35
|
+
"require": "./dist/aws.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./logger": {
|
|
38
|
+
"types": "./dist/logger.d.ts",
|
|
39
|
+
"import": "./dist/logger.mjs",
|
|
40
|
+
"require": "./dist/logger.cjs"
|
|
21
41
|
}
|
|
22
42
|
},
|
|
23
43
|
"dependencies": {
|
|
24
|
-
"@faker-js/faker": "~9.9.0"
|
|
44
|
+
"@faker-js/faker": "~9.9.0",
|
|
45
|
+
"@geekmidas/logger": "0.0.1"
|
|
25
46
|
},
|
|
26
47
|
"devDependencies": {
|
|
27
48
|
"@types/pg": "~8.15.4"
|
|
@@ -37,6 +58,7 @@
|
|
|
37
58
|
"objection": "~3.1.5",
|
|
38
59
|
"db-errors": "~0.2.3",
|
|
39
60
|
"vitest": "~3.2.4",
|
|
40
|
-
"@
|
|
61
|
+
"@types/aws-lambda": ">=8.10.92",
|
|
62
|
+
"@geekmidas/envkit": "0.0.7"
|
|
41
63
|
}
|
|
42
64
|
}
|
|
@@ -47,8 +47,8 @@ export class VitestKyselyTransactionIsolator<
|
|
|
47
47
|
Kysely<Database>,
|
|
48
48
|
Transaction<Database>
|
|
49
49
|
> {
|
|
50
|
-
destroy(conn: Kysely<Database>): Promise<void> {
|
|
51
|
-
return conn.destroy();
|
|
50
|
+
async destroy(conn: Kysely<Database>): Promise<void> {
|
|
51
|
+
// return conn.destroy();
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Creates a Kysely transaction with the specified isolation level.
|
|
@@ -36,9 +36,7 @@ export class VitestObjectionTransactionIsolator extends VitestPostgresTransactio
|
|
|
36
36
|
Knex,
|
|
37
37
|
Knex.Transaction
|
|
38
38
|
> {
|
|
39
|
-
destroy(conn: Knex<any, any[]>): Promise<void> {
|
|
40
|
-
return conn.destroy();
|
|
41
|
-
}
|
|
39
|
+
async destroy(conn: Knex<any, any[]>): Promise<void> {}
|
|
42
40
|
/**
|
|
43
41
|
* Creates a Knex transaction with the specified isolation level.
|
|
44
42
|
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|