@geekmidas/testkit 0.0.15 → 0.0.17
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-CRquB4vz.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-72P98y5I.d.mts → KyselyFactory-BDS_QqRT.d.mts} +4 -3
- 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-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-C3tHvX1d.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-BxjlD1YM.mjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- 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/better-auth.cjs +245 -0
- package/dist/better-auth.cjs.map +1 -0
- package/dist/better-auth.d.cts +17 -0
- package/dist/better-auth.d.mts +17 -0
- package/dist/better-auth.mjs +244 -0
- package/dist/better-auth.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-C-Iuk_R1.d.mts → faker-Br8MzXil.d.mts} +4 -3
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +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 +65 -2
- 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 +67 -4
- 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 +80 -2
- 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 +82 -4
- 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 +30 -2
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/aws.ts +131 -0
- package/src/better-auth.ts +327 -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-C3h7kitU.mjs +0 -67
- package/dist/kysely-VU3MwvMD.cjs +0 -72
- package/dist/objection-BI7F86qf.mjs +0 -82
- package/dist/objection-BpLv_ZfC.cjs +0 -87
package/dist/kysely-VU3MwvMD.cjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
2
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Cst3vFjb.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/kysely.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
7
|
-
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
8
|
-
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
9
|
-
*
|
|
10
|
-
* @template Database - The database schema type
|
|
11
|
-
* @param api - The Vitest test API (usually `test` from vitest)
|
|
12
|
-
* @param db - The Kysely database instance
|
|
13
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
14
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
15
|
-
* @returns A wrapped test API that provides transaction isolation
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { test } from 'vitest';
|
|
20
|
-
* import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';
|
|
21
|
-
* import { db } from './database';
|
|
22
|
-
*
|
|
23
|
-
* // Create isolated test with automatic rollback
|
|
24
|
-
* const isolatedTest = wrapVitestKyselyTransaction(test, db);
|
|
25
|
-
*
|
|
26
|
-
* // Use in tests - each test gets its own transaction
|
|
27
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
28
|
-
* const user = await trx
|
|
29
|
-
* .insertInto('users')
|
|
30
|
-
* .values({ name: 'Test User', email: 'test@example.com' })
|
|
31
|
-
* .returningAll()
|
|
32
|
-
* .executeTakeFirst();
|
|
33
|
-
*
|
|
34
|
-
* expect(user).toBeDefined();
|
|
35
|
-
* // User is automatically rolled back after test
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* // With setup function for common test data
|
|
39
|
-
* const testWithSetup = wrapVitestKyselyTransaction(
|
|
40
|
-
* test,
|
|
41
|
-
* db,
|
|
42
|
-
* async (trx) => {
|
|
43
|
-
* // Create common test data
|
|
44
|
-
* await trx.insertInto('settings')
|
|
45
|
-
* .values({ key: 'test_mode', value: 'true' })
|
|
46
|
-
* .execute();
|
|
47
|
-
* }
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
51
|
-
* const setting = await trx
|
|
52
|
-
* .selectFrom('settings')
|
|
53
|
-
* .where('key', '=', 'test_mode')
|
|
54
|
-
* .selectAll()
|
|
55
|
-
* .executeTakeFirst();
|
|
56
|
-
*
|
|
57
|
-
* expect(setting?.value).toBe('true');
|
|
58
|
-
* });
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
function wrapVitestKyselyTransaction(api, connection, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
62
|
-
const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
|
|
63
|
-
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
Object.defineProperty(exports, 'wrapVitestKyselyTransaction', {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
get: function () {
|
|
70
|
-
return wrapVitestKyselyTransaction;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-BU-jXEhz.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/objection.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
|
|
7
|
-
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
8
|
-
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
9
|
-
*
|
|
10
|
-
* @param api - The Vitest test API (usually `test` from vitest)
|
|
11
|
-
* @param conn - The Knex database connection instance
|
|
12
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
13
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
14
|
-
* @returns A wrapped test API that provides transaction isolation
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { test } from 'vitest';
|
|
19
|
-
* import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
|
|
20
|
-
* import { knex } from './database';
|
|
21
|
-
* import { User, Post } from './models';
|
|
22
|
-
*
|
|
23
|
-
* // Create isolated test with automatic rollback
|
|
24
|
-
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
25
|
-
*
|
|
26
|
-
* // Use in tests - each test gets its own transaction
|
|
27
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
28
|
-
* const user = await User.query(trx)
|
|
29
|
-
* .insert({ name: 'Test User', email: 'test@example.com' });
|
|
30
|
-
*
|
|
31
|
-
* expect(user).toBeDefined();
|
|
32
|
-
* // User is automatically rolled back after test
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* // With setup function for common test data
|
|
36
|
-
* const testWithSetup = wrapVitestObjectionTransaction(
|
|
37
|
-
* test,
|
|
38
|
-
* knex,
|
|
39
|
-
* async (trx) => {
|
|
40
|
-
* // Create common test data
|
|
41
|
-
* await knex('settings')
|
|
42
|
-
* .transacting(trx)
|
|
43
|
-
* .insert({ key: 'test_mode', value: 'true' });
|
|
44
|
-
* }
|
|
45
|
-
* );
|
|
46
|
-
*
|
|
47
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
48
|
-
* const setting = await knex('settings')
|
|
49
|
-
* .transacting(trx)
|
|
50
|
-
* .where('key', 'test_mode')
|
|
51
|
-
* .first();
|
|
52
|
-
*
|
|
53
|
-
* expect(setting?.value).toBe('true');
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
* // Example with factory and transaction
|
|
57
|
-
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
58
|
-
* const factory = new ObjectionFactory(builders, seeds, knex);
|
|
59
|
-
*
|
|
60
|
-
* isolatedTest('creates related data', async ({ trx }) => {
|
|
61
|
-
* // Factory can use the transaction
|
|
62
|
-
* const user = await User.query(trx).insert({ name: 'Author' });
|
|
63
|
-
* const posts = await Post.query(trx).insert([
|
|
64
|
-
* { title: 'Post 1', userId: user.id },
|
|
65
|
-
* { title: 'Post 2', userId: user.id }
|
|
66
|
-
* ]);
|
|
67
|
-
*
|
|
68
|
-
* const userWithPosts = await User.query(trx)
|
|
69
|
-
* .findById(user.id)
|
|
70
|
-
* .withGraphFetched('posts');
|
|
71
|
-
*
|
|
72
|
-
* expect(userWithPosts.posts).toHaveLength(2);
|
|
73
|
-
* });
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
function wrapVitestObjectionTransaction(api, conn, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
77
|
-
const wrapper = new VitestObjectionTransactionIsolator(api);
|
|
78
|
-
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//#endregion
|
|
82
|
-
export { wrapVitestObjectionTransaction };
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
2
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-DzeF4UAq.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/objection.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
|
|
7
|
-
* Each test runs in an isolated database transaction that is rolled back after completion.
|
|
8
|
-
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
9
|
-
*
|
|
10
|
-
* @param api - The Vitest test API (usually `test` from vitest)
|
|
11
|
-
* @param conn - The Knex database connection instance
|
|
12
|
-
* @param setup - Optional setup function to run before each test in the transaction
|
|
13
|
-
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
14
|
-
* @returns A wrapped test API that provides transaction isolation
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { test } from 'vitest';
|
|
19
|
-
* import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
|
|
20
|
-
* import { knex } from './database';
|
|
21
|
-
* import { User, Post } from './models';
|
|
22
|
-
*
|
|
23
|
-
* // Create isolated test with automatic rollback
|
|
24
|
-
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
25
|
-
*
|
|
26
|
-
* // Use in tests - each test gets its own transaction
|
|
27
|
-
* isolatedTest('should create user', async ({ trx }) => {
|
|
28
|
-
* const user = await User.query(trx)
|
|
29
|
-
* .insert({ name: 'Test User', email: 'test@example.com' });
|
|
30
|
-
*
|
|
31
|
-
* expect(user).toBeDefined();
|
|
32
|
-
* // User is automatically rolled back after test
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* // With setup function for common test data
|
|
36
|
-
* const testWithSetup = wrapVitestObjectionTransaction(
|
|
37
|
-
* test,
|
|
38
|
-
* knex,
|
|
39
|
-
* async (trx) => {
|
|
40
|
-
* // Create common test data
|
|
41
|
-
* await knex('settings')
|
|
42
|
-
* .transacting(trx)
|
|
43
|
-
* .insert({ key: 'test_mode', value: 'true' });
|
|
44
|
-
* }
|
|
45
|
-
* );
|
|
46
|
-
*
|
|
47
|
-
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
48
|
-
* const setting = await knex('settings')
|
|
49
|
-
* .transacting(trx)
|
|
50
|
-
* .where('key', 'test_mode')
|
|
51
|
-
* .first();
|
|
52
|
-
*
|
|
53
|
-
* expect(setting?.value).toBe('true');
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
* // Example with factory and transaction
|
|
57
|
-
* const isolatedTest = wrapVitestObjectionTransaction(test, knex);
|
|
58
|
-
* const factory = new ObjectionFactory(builders, seeds, knex);
|
|
59
|
-
*
|
|
60
|
-
* isolatedTest('creates related data', async ({ trx }) => {
|
|
61
|
-
* // Factory can use the transaction
|
|
62
|
-
* const user = await User.query(trx).insert({ name: 'Author' });
|
|
63
|
-
* const posts = await Post.query(trx).insert([
|
|
64
|
-
* { title: 'Post 1', userId: user.id },
|
|
65
|
-
* { title: 'Post 2', userId: user.id }
|
|
66
|
-
* ]);
|
|
67
|
-
*
|
|
68
|
-
* const userWithPosts = await User.query(trx)
|
|
69
|
-
* .findById(user.id)
|
|
70
|
-
* .withGraphFetched('posts');
|
|
71
|
-
*
|
|
72
|
-
* expect(userWithPosts.posts).toHaveLength(2);
|
|
73
|
-
* });
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
function wrapVitestObjectionTransaction(api, conn, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
77
|
-
const wrapper = new require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator(api);
|
|
78
|
-
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//#endregion
|
|
82
|
-
Object.defineProperty(exports, 'wrapVitestObjectionTransaction', {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
get: function () {
|
|
85
|
-
return wrapVitestObjectionTransaction;
|
|
86
|
-
}
|
|
87
|
-
});
|