@geekmidas/testkit 0.0.15 → 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-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/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 +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 +24 -2
- 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-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/objection.cjs
CHANGED
|
@@ -5,10 +5,88 @@ require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
|
5
5
|
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
7
7
|
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-DzeF4UAq.cjs');
|
|
8
|
-
const require_objection = require('./objection-BpLv_ZfC.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
7
|
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-BU-jXEhz.mjs";
|
|
8
|
-
import { wrapVitestObjectionTransaction } from "./objection-BI7F86qf.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",
|
|
61
|
+
"@types/aws-lambda": ">=8.10.92",
|
|
40
62
|
"@geekmidas/envkit": "0.0.7"
|
|
41
63
|
}
|
|
42
64
|
}
|
package/src/aws.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
APIGatewayProxyEvent,
|
|
3
|
+
APIGatewayProxyEventV2,
|
|
4
|
+
Context,
|
|
5
|
+
} from 'aws-lambda';
|
|
6
|
+
import { vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shared test utilities for AWS Lambda adapter testing
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a mock AWS Lambda Context for testing
|
|
14
|
+
*/
|
|
15
|
+
export function createMockContext(): Context {
|
|
16
|
+
return {
|
|
17
|
+
awsRequestId: 'test-request-id',
|
|
18
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
19
|
+
functionName: 'test-function',
|
|
20
|
+
functionVersion: '1',
|
|
21
|
+
invokedFunctionArn:
|
|
22
|
+
'arn:aws:lambda:us-east-1:123456789012:function:test-function',
|
|
23
|
+
memoryLimitInMB: '128',
|
|
24
|
+
logGroupName: '/aws/lambda/test-function',
|
|
25
|
+
logStreamName: '2024/01/01/[$LATEST]abcdef123456',
|
|
26
|
+
getRemainingTimeInMillis: () => 5000,
|
|
27
|
+
done: vi.fn(),
|
|
28
|
+
fail: vi.fn(),
|
|
29
|
+
succeed: vi.fn(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
35
|
+
*/
|
|
36
|
+
export function createMockV1Event(
|
|
37
|
+
overrides: Partial<APIGatewayProxyEvent> = {},
|
|
38
|
+
): APIGatewayProxyEvent {
|
|
39
|
+
return {
|
|
40
|
+
body: null,
|
|
41
|
+
headers: {
|
|
42
|
+
'content-type': 'application/json',
|
|
43
|
+
'user-agent': 'test-agent',
|
|
44
|
+
host: 'test.example.com',
|
|
45
|
+
},
|
|
46
|
+
multiValueHeaders: {},
|
|
47
|
+
httpMethod: 'GET',
|
|
48
|
+
isBase64Encoded: false,
|
|
49
|
+
path: '/test',
|
|
50
|
+
pathParameters: null,
|
|
51
|
+
queryStringParameters: null,
|
|
52
|
+
multiValueQueryStringParameters: null,
|
|
53
|
+
stageVariables: null,
|
|
54
|
+
requestContext: {
|
|
55
|
+
accountId: '123456789012',
|
|
56
|
+
apiId: 'api-id',
|
|
57
|
+
authorizer: null,
|
|
58
|
+
protocol: 'HTTP/1.1',
|
|
59
|
+
httpMethod: 'GET',
|
|
60
|
+
path: '/test',
|
|
61
|
+
stage: 'test',
|
|
62
|
+
requestId: 'request-id',
|
|
63
|
+
requestTimeEpoch: 1704067200000,
|
|
64
|
+
resourceId: 'resource-id',
|
|
65
|
+
resourcePath: '/test',
|
|
66
|
+
identity: {
|
|
67
|
+
accessKey: null,
|
|
68
|
+
accountId: null,
|
|
69
|
+
apiKey: null,
|
|
70
|
+
apiKeyId: null,
|
|
71
|
+
caller: null,
|
|
72
|
+
cognitoAuthenticationProvider: null,
|
|
73
|
+
cognitoAuthenticationType: null,
|
|
74
|
+
cognitoIdentityId: null,
|
|
75
|
+
cognitoIdentityPoolId: null,
|
|
76
|
+
principalOrgId: null,
|
|
77
|
+
sourceIp: '127.0.0.1',
|
|
78
|
+
user: null,
|
|
79
|
+
userAgent: 'test-agent',
|
|
80
|
+
userArn: null,
|
|
81
|
+
clientCert: null,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
resource: '/test',
|
|
85
|
+
...overrides,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
91
|
+
*/
|
|
92
|
+
export function createMockV2Event(
|
|
93
|
+
overrides: Partial<APIGatewayProxyEventV2> = {},
|
|
94
|
+
): APIGatewayProxyEventV2 {
|
|
95
|
+
return {
|
|
96
|
+
version: '2.0',
|
|
97
|
+
routeKey: 'GET /test',
|
|
98
|
+
rawPath: '/test',
|
|
99
|
+
rawQueryString: '',
|
|
100
|
+
headers: {
|
|
101
|
+
'content-type': 'application/json',
|
|
102
|
+
'user-agent': 'test-agent',
|
|
103
|
+
host: 'test.example.com',
|
|
104
|
+
},
|
|
105
|
+
requestContext: {
|
|
106
|
+
accountId: '123456789012',
|
|
107
|
+
apiId: 'api-id',
|
|
108
|
+
domainName: 'test.example.com',
|
|
109
|
+
domainPrefix: 'api',
|
|
110
|
+
requestId: 'request-id',
|
|
111
|
+
routeKey: 'GET /test',
|
|
112
|
+
stage: 'test',
|
|
113
|
+
time: '01/Jan/2024:00:00:00 +0000',
|
|
114
|
+
timeEpoch: 1704067200000,
|
|
115
|
+
http: {
|
|
116
|
+
method: 'GET',
|
|
117
|
+
path: '/test',
|
|
118
|
+
protocol: 'HTTP/1.1',
|
|
119
|
+
sourceIp: '127.0.0.1',
|
|
120
|
+
userAgent: 'test-agent',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
body: undefined,
|
|
124
|
+
pathParameters: undefined,
|
|
125
|
+
isBase64Encoded: false,
|
|
126
|
+
stageVariables: undefined,
|
|
127
|
+
queryStringParameters: undefined,
|
|
128
|
+
cookies: undefined,
|
|
129
|
+
...overrides,
|
|
130
|
+
};
|
|
131
|
+
}
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Logger } from '@geekmidas/logger';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a mock Logger for testing
|
|
6
|
+
*/
|
|
7
|
+
export function createMockLogger(): Logger {
|
|
8
|
+
const logger: 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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
export const itWithDir = it.extend<DirectoryFixtures>({
|
|
8
|
+
// This fixture automatically provides a transaction to each test
|
|
9
|
+
dir: async ({}, use) => {
|
|
10
|
+
const tempDir = os.tmpdir();
|
|
11
|
+
const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();
|
|
12
|
+
const dir = path.join(tempDir, directoryName);
|
|
13
|
+
await fs.mkdir(dir, { recursive: true });
|
|
14
|
+
await use(dir);
|
|
15
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export interface DirectoryFixtures {
|
|
20
|
+
dir: string;
|
|
21
|
+
}
|
package/src/os/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { itWithDir } from './directory';
|
package/src/timer.ts
ADDED