@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/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostgresMigrator } from "./PostgresMigrator-
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-DbuJGAVy.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/PostgresObjectionMigrator.ts
|
|
4
4
|
/**
|
|
@@ -114,4 +114,5 @@ var PostgresObjectionMigrator = class extends PostgresMigrator {
|
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
//#endregion
|
|
117
|
-
export { PostgresObjectionMigrator };
|
|
117
|
+
export { PostgresObjectionMigrator };
|
|
118
|
+
//# sourceMappingURL=PostgresObjectionMigrator-DPj2pOpX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresObjectionMigrator-DPj2pOpX.mjs","names":["options: {\n uri: string;\n knex: Knex;\n }","migration: string"],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Objection.js ORM with Knex.\n * Extends PostgresMigrator to provide Knex-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import knex from 'knex';\n * import { PostgresObjectionMigrator } from '@geekmidas/testkit';\n *\n * // Create Knex instance\n * const db = knex({\n * client: 'pg',\n * connection: uri,\n * migrations: {\n * directory: path.join(__dirname, 'migrations'),\n * extension: 'ts'\n * }\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresObjectionMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * knex: db\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresObjectionMigrator extends PostgresMigrator {\n /**\n * Creates a new PostgresObjectionMigrator instance.\n *\n * @param options - Configuration options\n * @param options.uri - PostgreSQL connection URI\n * @param options.knex - Knex database instance configured with migrations\n */\n constructor(\n private options: {\n uri: string;\n knex: Knex;\n },\n ) {\n super(options.uri);\n }\n\n /**\n * Executes Knex migrations to the latest version.\n * Implements the abstract migrate() method from PostgresMigrator.\n *\n * @throws Error if migrations fail to apply\n * @returns Promise that resolves when all migrations are applied\n */\n async migrate(): Promise<void> {\n try {\n // Run migrations to latest\n const [batchNo, migrations] = await this.options.knex.migrate.latest();\n\n if (migrations.length > 0) {\n logger.log(\n `Applied batch ${batchNo} with ${migrations.length} migrations:`,\n );\n migrations.forEach((migration: string) => {\n logger.log(` - ${migration}`);\n });\n } else {\n logger.log('No pending migrations to apply');\n }\n } catch (error) {\n logger.error('Failed to apply migrations:', error);\n throw error;\n } finally {\n // Always destroy the connection pool\n await this.options.knex.destroy();\n }\n }\n\n /**\n * Rolls back the last batch of migrations.\n * Useful for testing migration rollback scenarios.\n *\n * @returns Promise that resolves when rollback is complete\n */\n async rollback(): Promise<void> {\n try {\n const [batchNo, migrations] = await this.options.knex.migrate.rollback();\n\n if (migrations.length > 0) {\n logger.log(\n `Rolled back batch ${batchNo} with ${migrations.length} migrations:`,\n );\n migrations.forEach((migration: string) => {\n logger.log(` - ${migration}`);\n });\n } else {\n logger.log('No migrations to rollback');\n }\n } catch (error) {\n logger.error('Failed to rollback migrations:', error);\n throw error;\n } finally {\n await this.options.knex.destroy();\n }\n }\n\n /**\n * Gets the current migration status.\n * Returns information about completed and pending migrations.\n *\n * @returns Promise with migration status information\n */\n async status(): Promise<{\n completed: string[];\n pending: string[];\n }> {\n try {\n const completed = await this.options.knex.migrate.list();\n const [, pending] = await this.options.knex.migrate.currentVersion();\n\n return {\n completed: Array.isArray(completed[0]) ? completed[0] : [],\n pending: Array.isArray(pending) ? pending : [],\n };\n } finally {\n await this.options.knex.destroy();\n }\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCf,IAAa,4BAAb,cAA+C,iBAAiB;;;;;;;;CAQ9D,YACUA,SAIR;AACA,QAAM,QAAQ,IAAI;EALV;CAMT;;;;;;;;CASD,MAAM,UAAyB;AAC7B,MAAI;GAEF,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAEtE,OAAI,WAAW,SAAS,GAAG;AACzB,WAAO,KACJ,gBAAgB,QAAQ,QAAQ,WAAW,OAAO,cACpD;AACD,eAAW,QAAQ,CAACC,cAAsB;AACxC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC/B,EAAC;GACH,MACC,QAAO,IAAI,iCAAiC;EAE/C,SAAQ,OAAO;AACd,UAAO,MAAM,+BAA+B,MAAM;AAClD,SAAM;EACP,UAAS;AAER,SAAM,KAAK,QAAQ,KAAK,SAAS;EAClC;CACF;;;;;;;CAQD,MAAM,WAA0B;AAC9B,MAAI;GACF,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,UAAU;AAExE,OAAI,WAAW,SAAS,GAAG;AACzB,WAAO,KACJ,oBAAoB,QAAQ,QAAQ,WAAW,OAAO,cACxD;AACD,eAAW,QAAQ,CAACA,cAAsB;AACxC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC/B,EAAC;GACH,MACC,QAAO,IAAI,4BAA4B;EAE1C,SAAQ,OAAO;AACd,UAAO,MAAM,kCAAkC,MAAM;AACrD,SAAM;EACP,UAAS;AACR,SAAM,KAAK,QAAQ,KAAK,SAAS;EAClC;CACF;;;;;;;CAQD,MAAM,SAGH;AACD,MAAI;GACF,MAAM,YAAY,MAAM,KAAK,QAAQ,KAAK,QAAQ,MAAM;GACxD,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,gBAAgB;AAEpE,UAAO;IACL,WAAW,MAAM,QAAQ,UAAU,GAAG,GAAG,UAAU,KAAK,CAAE;IAC1D,SAAS,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAE;GAC/C;EACF,UAAS;AACR,SAAM,KAAK,QAAQ,KAAK,SAAS;EAClC;CACF;AACF"}
|
package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostgresMigrator } from "./PostgresMigrator-
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-DQaRxoaY.mjs";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
3
|
|
|
4
4
|
//#region src/PostgresObjectionMigrator.d.ts
|
|
@@ -74,4 +74,5 @@ declare class PostgresObjectionMigrator extends PostgresMigrator {
|
|
|
74
74
|
}>;
|
|
75
75
|
}
|
|
76
76
|
//#endregion
|
|
77
|
-
export { PostgresObjectionMigrator };
|
|
77
|
+
export { PostgresObjectionMigrator };
|
|
78
|
+
//# sourceMappingURL=PostgresObjectionMigrator-D_hCcrQu.d.mts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./PostgresMigrator-
|
|
2
|
-
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-
|
|
1
|
+
import "./PostgresMigrator-DQaRxoaY.mjs";
|
|
2
|
+
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-D_hCcrQu.mjs";
|
|
3
3
|
export { PostgresObjectionMigrator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./PostgresMigrator-
|
|
2
|
-
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-
|
|
1
|
+
import "./PostgresMigrator-DbuJGAVy.mjs";
|
|
2
|
+
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-DPj2pOpX.mjs";
|
|
3
3
|
|
|
4
4
|
export { PostgresObjectionMigrator };
|
|
@@ -56,4 +56,5 @@ var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIso
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
//#endregion
|
|
59
|
-
export { VitestKyselyTransactionIsolator };
|
|
59
|
+
export { VitestKyselyTransactionIsolator };
|
|
60
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator-BxjlD1YM.mjs","names":["conn: Kysely<Database>","level: IsolationLevel","fn: (trx: Transaction<Database>) => Promise<void>"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n Database,\n> extends VitestPostgresTransactionIsolator<\n Kysely<Database>,\n Transaction<Database>\n> {\n async destroy(conn: Kysely<Database>): Promise<void> {\n // return conn.destroy();\n }\n /**\n * Creates a Kysely transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n *\n * @param conn - The Kysely database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n async transact(\n conn: Kysely<Database>,\n level: IsolationLevel,\n fn: (trx: Transaction<Database>) => Promise<void>,\n ): Promise<void> {\n const isolationLevel =\n level.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n }\n // Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEU,kCAGR;CACA,MAAM,QAAQA,MAAuC,CAEpD;;;;;;;;;;CAUD,MAAM,SACJA,MACAC,OACAC,IACe;EACf,MAAM,iBACJ,MAAM,mBAAmB;AAC3B,QAAM,KAAK,aAAa,CAAC,kBAAkB,eAAe,CAAC,QAAQ,GAAG;CACvE;AAEF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
2
2
|
import { Kysely, Transaction } from "kysely";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
@@ -54,4 +54,5 @@ declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTr
|
|
|
54
54
|
transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
|
-
export { VitestKyselyTransactionIsolator };
|
|
57
|
+
export { VitestKyselyTransactionIsolator };
|
|
58
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-COCVfvfr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator-Cst3vFjb.cjs","names":["VitestPostgresTransactionIsolator","conn: Kysely<Database>","level: IsolationLevel","fn: (trx: Transaction<Database>) => Promise<void>"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n Database,\n> extends VitestPostgresTransactionIsolator<\n Kysely<Database>,\n Transaction<Database>\n> {\n async destroy(conn: Kysely<Database>): Promise<void> {\n // return conn.destroy();\n }\n /**\n * Creates a Kysely transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n *\n * @param conn - The Kysely database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n async transact(\n conn: Kysely<Database>,\n level: IsolationLevel,\n fn: (trx: Transaction<Database>) => Promise<void>,\n ): Promise<void> {\n const isolationLevel =\n level.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n }\n // Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEUA,oEAGR;CACA,MAAM,QAAQC,MAAuC,CAEpD;;;;;;;;;;CAUD,MAAM,SACJA,MACAC,OACAC,IACe;EACf,MAAM,iBACJ,MAAM,mBAAmB;AAC3B,QAAM,KAAK,aAAa,CAAC,kBAAkB,eAAe,CAAC,QAAQ,GAAG;CACvE;AAEF"}
|
|
@@ -54,4 +54,5 @@ declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTr
|
|
|
54
54
|
transact(conn: Kysely<Database>, level: IsolationLevel, fn: (trx: Transaction<Database>) => Promise<void>): Promise<void>;
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
|
-
export { VitestKyselyTransactionIsolator };
|
|
57
|
+
export { VitestKyselyTransactionIsolator };
|
|
58
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-DYUYVEh9.d.cts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-COCVfvfr.mjs";
|
|
3
3
|
export { VitestKyselyTransactionIsolator };
|
|
@@ -59,4 +59,5 @@ var VitestObjectionTransactionIsolator = class extends VitestPostgresTransaction
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
|
-
export { VitestObjectionTransactionIsolator };
|
|
62
|
+
export { VitestObjectionTransactionIsolator };
|
|
63
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator-BU-jXEhz.mjs","names":["conn: Knex<any, any[]>","connection: Knex","level: IsolationLevel","fn: (trx: Knex.Transaction) => Promise<void>"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n Knex,\n Knex.Transaction\n> {\n async destroy(conn: Knex<any, any[]>): Promise<void> {}\n /**\n * Creates a Knex transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n * This transaction can be used with Objection.js models via Model.query(trx).\n *\n * @param conn - The Knex database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n *\n * @example\n * ```typescript\n * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n * // Use transaction with Objection models\n * await User.query(trx).insert({ name: 'Test' });\n * await Post.query(trx).where('userId', user.id).delete();\n * });\n * ```\n */\n async transact(\n connection: Knex,\n level: IsolationLevel,\n fn: (trx: Knex.Transaction) => Promise<void>,\n ): Promise<void> {\n const isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n await connection.transaction(\n async (trx) => {\n await fn(trx);\n },\n {\n isolationLevel,\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwD,kCAGtD;CACA,MAAM,QAAQA,MAAuC,CAAE;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACJC,YACAC,OACAC,IACe;EACf,MAAM,iBAAiB,MAAM,aAAa;AAE1C,QAAM,WAAW,YACf,OAAO,QAAQ;AACb,SAAM,GAAG,IAAI;EACd,GACD,EACE,eACD,EACF;CACF;AACF"}
|
|
@@ -55,4 +55,5 @@ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransacti
|
|
|
55
55
|
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
-
export { VitestObjectionTransactionIsolator };
|
|
58
|
+
export { VitestObjectionTransactionIsolator };
|
|
59
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator-DzeF4UAq.cjs","names":["VitestPostgresTransactionIsolator","conn: Knex<any, any[]>","connection: Knex","level: IsolationLevel","fn: (trx: Knex.Transaction) => Promise<void>"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n Knex,\n Knex.Transaction\n> {\n async destroy(conn: Knex<any, any[]>): Promise<void> {}\n /**\n * Creates a Knex transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n * This transaction can be used with Objection.js models via Model.query(trx).\n *\n * @param conn - The Knex database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n *\n * @example\n * ```typescript\n * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n * // Use transaction with Objection models\n * await User.query(trx).insert({ name: 'Test' });\n * await Post.query(trx).where('userId', user.id).delete();\n * });\n * ```\n */\n async transact(\n connection: Knex,\n level: IsolationLevel,\n fn: (trx: Knex.Transaction) => Promise<void>,\n ): Promise<void> {\n const isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n await connection.transaction(\n async (trx) => {\n await fn(trx);\n },\n {\n isolationLevel,\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwDA,oEAGtD;CACA,MAAM,QAAQC,MAAuC,CAAE;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACJC,YACAC,OACAC,IACe;EACf,MAAM,iBAAiB,MAAM,aAAa;AAE1C,QAAM,WAAW,YACf,OAAO,QAAQ;AACb,SAAM,GAAG,IAAI;EACd,GACD,EACE,eACD,EACF;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
@@ -55,4 +55,5 @@ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransacti
|
|
|
55
55
|
transact(connection: Knex, level: IsolationLevel, fn: (trx: Knex.Transaction) => Promise<void>): Promise<void>;
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
-
export { VitestObjectionTransactionIsolator };
|
|
58
|
+
export { VitestObjectionTransactionIsolator };
|
|
59
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-b973r9O1.d.mts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-b973r9O1.mjs";
|
|
3
3
|
export { VitestObjectionTransactionIsolator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestTransactionIsolator-BQ5FpLtC.cjs","names":["api: TestAPI","createConnection: DatabaseConnection<TConn>","setup?: (trx: Transaction) => Promise<void>","level: IsolationLevel","testError: Error | undefined"],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":["import type { TestAPI } from 'vitest';\n\n/**\n * Type definition for test fixtures that provide transaction access.\n * Used with Vitest's test.extend() API to inject transactions into tests.\n *\n * @template Transaction - The transaction type specific to the database driver\n */\nexport interface DatabaseFixtures<Transaction> {\n /**\n * The database transaction available to the test.\n * All database operations should use this transaction to ensure proper rollback.\n */\n trx: Transaction;\n}\n\n/**\n * PostgreSQL transaction isolation levels.\n * Controls the visibility of concurrent transactions.\n *\n * @see https://www.postgresql.org/docs/current/transaction-iso.html\n */\nexport enum IsolationLevel {\n /**\n * Lowest isolation level. Allows dirty reads.\n * Not recommended for testing.\n */\n READ_UNCOMMITTED = 'READ UNCOMMITTED',\n /**\n * Default PostgreSQL isolation level.\n * Prevents dirty reads but allows non-repeatable reads.\n */\n READ_COMMITTED = 'READ COMMITTED',\n /**\n * Prevents dirty reads and non-repeatable reads.\n * Recommended for most test scenarios.\n */\n REPEATABLE_READ = 'REPEATABLE READ',\n /**\n * Highest isolation level. Prevents all phenomena.\n * May cause performance overhead in tests.\n */\n SERIALIZABLE = 'SERIALIZABLE',\n}\n\n/**\n * Abstract base class for implementing database transaction isolation in Vitest tests.\n * Provides automatic transaction rollback after each test to maintain test isolation.\n * Subclasses must implement the transact() method for their specific database driver.\n *\n * @template TConn - The database connection type\n * @template Transaction - The transaction type\n *\n * @example\n * ```typescript\n * // Implement for your database driver\n * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {\n * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {\n * await conn.transaction(level, fn);\n * }\n * }\n *\n * // Use in tests\n * const isolator = new MyDatabaseIsolator(test);\n * const isolatedTest = isolator.wrapVitestWithTransaction(db);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * await trx.insert('users', { name: 'Test' });\n * // Data is automatically rolled back after test\n * });\n * ```\n */\nexport abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {\n /**\n * Abstract method to create a transaction with the specified isolation level.\n * Must be implemented by subclasses for specific database drivers.\n *\n * @param conn - The database connection\n * @param isolationLevel - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n abstract transact(\n conn: TConn,\n isolationLevel: IsolationLevel,\n fn: (trx: Transaction) => Promise<void>,\n ): Promise<void>;\n\n abstract destroy(conn: TConn): Promise<void>;\n /**\n * Creates a new VitestPostgresTransactionIsolator instance.\n *\n * @param api - The Vitest test API (usually the `test` export from vitest)\n */\n constructor(private readonly api: TestAPI) {}\n\n /**\n * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n * Each test will run within a database transaction that is automatically rolled back.\n *\n * @param conn - The database connection to use\n * @param setup - Optional setup function to run within the transaction before each test\n * @param level - The transaction isolation level (defaults to REPEATABLE_READ)\n * @returns A wrapped test API with transaction support\n *\n * @example\n * ```typescript\n * const isolatedTest = isolator.wrapVitestWithTransaction(db, async (trx) => {\n * // Optional setup: create common test data\n * await trx.insert('settings', { key: 'test', value: 'true' });\n * });\n *\n * isolatedTest('test with transaction', async ({ trx }) => {\n * const user = await trx.insert('users', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\n wrapVitestWithTransaction(\n createConnection: DatabaseConnection<TConn>,\n setup?: (trx: Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n ) {\n return this.api.extend<DatabaseFixtures<Transaction>>({\n // This fixture automatically provides a transaction to each test\n trx: async ({}, use) => {\n // Create a custom error class for rollback\n class TestRollback extends Error {\n constructor() {\n super('Test rollback');\n this.name = 'TestRollback';\n }\n }\n\n let testError: Error | undefined;\n const conn = await createConnection();\n try {\n await this.transact(conn, level, async (transaction) => {\n try {\n // Provide the transaction to the test\n await setup?.(transaction);\n await use(transaction);\n } catch (error) {\n // Capture any test errors\n testError = error as Error;\n }\n\n // Always throw to trigger rollback\n throw new TestRollback();\n });\n } catch (error) {\n // Only rethrow if it's not our rollback error\n if (!(error instanceof TestRollback)) {\n throw error;\n }\n\n // If the test had an error, throw it now\n if (testError) {\n throw testError;\n }\n } finally {\n await this.destroy(conn);\n }\n },\n });\n }\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n"],"mappings":";;;;;;;;AAsBA,IAAY,4DAAL;;;;;AAKL;;;;;AAKA;;;;;AAKA;;;;;AAKA;;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAsB,oCAAtB,MAA4E;;;;;;CAsB1E,YAA6BA,KAAc;EAAd;CAAgB;;;;;;;;;;;;;;;;;;;;;;;CAwB7C,0BACEC,kBACAC,OACAC,QAAwB,eAAe,iBACvC;AACA,SAAO,KAAK,IAAI,OAAsC,EAEpD,KAAK,OAAO,EAAE,EAAE,QAAQ;GAEtB,MAAM,qBAAqB,MAAM;IAC/B,cAAc;AACZ,WAAM,gBAAgB;AACtB,UAAK,OAAO;IACb;GACF;GAED,IAAIC;GACJ,MAAM,OAAO,MAAM,kBAAkB;AACrC,OAAI;AACF,UAAM,KAAK,SAAS,MAAM,OAAO,OAAO,gBAAgB;AACtD,SAAI;AAEF,YAAM,QAAQ,YAAY;AAC1B,YAAM,IAAI,YAAY;KACvB,SAAQ,OAAO;AAEd,kBAAY;KACb;AAGD,WAAM,IAAI;IACX,EAAC;GACH,SAAQ,OAAO;AAEd,UAAM,iBAAiB,cACrB,OAAM;AAIR,QAAI,UACF,OAAM;GAET,UAAS;AACR,UAAM,KAAK,QAAQ,KAAK;GACzB;EACF,EACF,EAAC;CACH;AACF"}
|
package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts}
RENAMED
|
@@ -118,4 +118,5 @@ declare abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {
|
|
|
118
118
|
type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;
|
|
119
119
|
type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;
|
|
120
120
|
//#endregion
|
|
121
|
-
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
|
|
121
|
+
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
|
|
122
|
+
//# sourceMappingURL=VitestTransactionIsolator-CsfJBxcb.d.mts.map
|
|
@@ -117,4 +117,5 @@ var VitestPostgresTransactionIsolator = class {
|
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
//#endregion
|
|
120
|
-
export { IsolationLevel, VitestPostgresTransactionIsolator };
|
|
120
|
+
export { IsolationLevel, VitestPostgresTransactionIsolator };
|
|
121
|
+
//# sourceMappingURL=VitestTransactionIsolator-CskiiJbW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VitestTransactionIsolator-CskiiJbW.mjs","names":["api: TestAPI","createConnection: DatabaseConnection<TConn>","setup?: (trx: Transaction) => Promise<void>","level: IsolationLevel","testError: Error | undefined"],"sources":["../src/VitestTransactionIsolator.ts"],"sourcesContent":["import type { TestAPI } from 'vitest';\n\n/**\n * Type definition for test fixtures that provide transaction access.\n * Used with Vitest's test.extend() API to inject transactions into tests.\n *\n * @template Transaction - The transaction type specific to the database driver\n */\nexport interface DatabaseFixtures<Transaction> {\n /**\n * The database transaction available to the test.\n * All database operations should use this transaction to ensure proper rollback.\n */\n trx: Transaction;\n}\n\n/**\n * PostgreSQL transaction isolation levels.\n * Controls the visibility of concurrent transactions.\n *\n * @see https://www.postgresql.org/docs/current/transaction-iso.html\n */\nexport enum IsolationLevel {\n /**\n * Lowest isolation level. Allows dirty reads.\n * Not recommended for testing.\n */\n READ_UNCOMMITTED = 'READ UNCOMMITTED',\n /**\n * Default PostgreSQL isolation level.\n * Prevents dirty reads but allows non-repeatable reads.\n */\n READ_COMMITTED = 'READ COMMITTED',\n /**\n * Prevents dirty reads and non-repeatable reads.\n * Recommended for most test scenarios.\n */\n REPEATABLE_READ = 'REPEATABLE READ',\n /**\n * Highest isolation level. Prevents all phenomena.\n * May cause performance overhead in tests.\n */\n SERIALIZABLE = 'SERIALIZABLE',\n}\n\n/**\n * Abstract base class for implementing database transaction isolation in Vitest tests.\n * Provides automatic transaction rollback after each test to maintain test isolation.\n * Subclasses must implement the transact() method for their specific database driver.\n *\n * @template TConn - The database connection type\n * @template Transaction - The transaction type\n *\n * @example\n * ```typescript\n * // Implement for your database driver\n * class MyDatabaseIsolator extends VitestPostgresTransactionIsolator<MyDB, MyTx> {\n * async transact(conn: MyDB, level: IsolationLevel, fn: (tx: MyTx) => Promise<void>) {\n * await conn.transaction(level, fn);\n * }\n * }\n *\n * // Use in tests\n * const isolator = new MyDatabaseIsolator(test);\n * const isolatedTest = isolator.wrapVitestWithTransaction(db);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * await trx.insert('users', { name: 'Test' });\n * // Data is automatically rolled back after test\n * });\n * ```\n */\nexport abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {\n /**\n * Abstract method to create a transaction with the specified isolation level.\n * Must be implemented by subclasses for specific database drivers.\n *\n * @param conn - The database connection\n * @param isolationLevel - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n abstract transact(\n conn: TConn,\n isolationLevel: IsolationLevel,\n fn: (trx: Transaction) => Promise<void>,\n ): Promise<void>;\n\n abstract destroy(conn: TConn): Promise<void>;\n /**\n * Creates a new VitestPostgresTransactionIsolator instance.\n *\n * @param api - The Vitest test API (usually the `test` export from vitest)\n */\n constructor(private readonly api: TestAPI) {}\n\n /**\n * Creates a wrapped version of Vitest's test API that provides transaction isolation.\n * Each test will run within a database transaction that is automatically rolled back.\n *\n * @param conn - The database connection to use\n * @param setup - Optional setup function to run within the transaction before each test\n * @param level - The transaction isolation level (defaults to REPEATABLE_READ)\n * @returns A wrapped test API with transaction support\n *\n * @example\n * ```typescript\n * const isolatedTest = isolator.wrapVitestWithTransaction(db, async (trx) => {\n * // Optional setup: create common test data\n * await trx.insert('settings', { key: 'test', value: 'true' });\n * });\n *\n * isolatedTest('test with transaction', async ({ trx }) => {\n * const user = await trx.insert('users', { name: 'Test' });\n * expect(user).toBeDefined();\n * });\n * ```\n */\n wrapVitestWithTransaction(\n createConnection: DatabaseConnection<TConn>,\n setup?: (trx: Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n ) {\n return this.api.extend<DatabaseFixtures<Transaction>>({\n // This fixture automatically provides a transaction to each test\n trx: async ({}, use) => {\n // Create a custom error class for rollback\n class TestRollback extends Error {\n constructor() {\n super('Test rollback');\n this.name = 'TestRollback';\n }\n }\n\n let testError: Error | undefined;\n const conn = await createConnection();\n try {\n await this.transact(conn, level, async (transaction) => {\n try {\n // Provide the transaction to the test\n await setup?.(transaction);\n await use(transaction);\n } catch (error) {\n // Capture any test errors\n testError = error as Error;\n }\n\n // Always throw to trigger rollback\n throw new TestRollback();\n });\n } catch (error) {\n // Only rethrow if it's not our rollback error\n if (!(error instanceof TestRollback)) {\n throw error;\n }\n\n // If the test had an error, throw it now\n if (testError) {\n throw testError;\n }\n } finally {\n await this.destroy(conn);\n }\n },\n });\n }\n}\n\nexport type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;\nexport type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;\n"],"mappings":";;;;;;;AAsBA,IAAY,4DAAL;;;;;AAKL;;;;;AAKA;;;;;AAKA;;;;;AAKA;;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BD,IAAsB,oCAAtB,MAA4E;;;;;;CAsB1E,YAA6BA,KAAc;EAAd;CAAgB;;;;;;;;;;;;;;;;;;;;;;;CAwB7C,0BACEC,kBACAC,OACAC,QAAwB,eAAe,iBACvC;AACA,SAAO,KAAK,IAAI,OAAsC,EAEpD,KAAK,OAAO,EAAE,EAAE,QAAQ;GAEtB,MAAM,qBAAqB,MAAM;IAC/B,cAAc;AACZ,WAAM,gBAAgB;AACtB,UAAK,OAAO;IACb;GACF;GAED,IAAIC;GACJ,MAAM,OAAO,MAAM,kBAAkB;AACrC,OAAI;AACF,UAAM,KAAK,SAAS,MAAM,OAAO,OAAO,gBAAgB;AACtD,SAAI;AAEF,YAAM,QAAQ,YAAY;AAC1B,YAAM,IAAI,YAAY;KACvB,SAAQ,OAAO;AAEd,kBAAY;KACb;AAGD,WAAM,IAAI;IACX,EAAC;GACH,SAAQ,OAAO;AAEd,UAAM,iBAAiB,cACrB,OAAM;AAIR,QAAI,UACF,OAAM;GAET,UAAS;AACR,UAAM,KAAK,QAAQ,KAAK;GACzB;EACF,EACF,EAAC;CACH;AACF"}
|
|
@@ -118,4 +118,5 @@ declare abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {
|
|
|
118
118
|
type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;
|
|
119
119
|
type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;
|
|
120
120
|
//#endregion
|
|
121
|
-
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
|
|
121
|
+
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
|
|
122
|
+
//# sourceMappingURL=VitestTransactionIsolator-DdLNODZg.d.cts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
2
2
|
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, IsolationLevel, VitestPostgresTransactionIsolator };
|
package/dist/aws.cjs
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
3
|
+
|
|
4
|
+
//#region src/aws.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared test utilities for AWS Lambda adapter testing
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a mock AWS Lambda Context for testing
|
|
10
|
+
*/
|
|
11
|
+
function createMockContext() {
|
|
12
|
+
return {
|
|
13
|
+
awsRequestId: "test-request-id",
|
|
14
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
15
|
+
functionName: "test-function",
|
|
16
|
+
functionVersion: "1",
|
|
17
|
+
invokedFunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:test-function",
|
|
18
|
+
memoryLimitInMB: "128",
|
|
19
|
+
logGroupName: "/aws/lambda/test-function",
|
|
20
|
+
logStreamName: "2024/01/01/[$LATEST]abcdef123456",
|
|
21
|
+
getRemainingTimeInMillis: () => 5e3,
|
|
22
|
+
done: vitest.vi.fn(),
|
|
23
|
+
fail: vitest.vi.fn(),
|
|
24
|
+
succeed: vitest.vi.fn()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
29
|
+
*/
|
|
30
|
+
function createMockV1Event(overrides = {}) {
|
|
31
|
+
return {
|
|
32
|
+
body: null,
|
|
33
|
+
headers: {
|
|
34
|
+
"content-type": "application/json",
|
|
35
|
+
"user-agent": "test-agent",
|
|
36
|
+
host: "test.example.com"
|
|
37
|
+
},
|
|
38
|
+
multiValueHeaders: {},
|
|
39
|
+
httpMethod: "GET",
|
|
40
|
+
isBase64Encoded: false,
|
|
41
|
+
path: "/test",
|
|
42
|
+
pathParameters: null,
|
|
43
|
+
queryStringParameters: null,
|
|
44
|
+
multiValueQueryStringParameters: null,
|
|
45
|
+
stageVariables: null,
|
|
46
|
+
requestContext: {
|
|
47
|
+
accountId: "123456789012",
|
|
48
|
+
apiId: "api-id",
|
|
49
|
+
authorizer: null,
|
|
50
|
+
protocol: "HTTP/1.1",
|
|
51
|
+
httpMethod: "GET",
|
|
52
|
+
path: "/test",
|
|
53
|
+
stage: "test",
|
|
54
|
+
requestId: "request-id",
|
|
55
|
+
requestTimeEpoch: 17040672e5,
|
|
56
|
+
resourceId: "resource-id",
|
|
57
|
+
resourcePath: "/test",
|
|
58
|
+
identity: {
|
|
59
|
+
accessKey: null,
|
|
60
|
+
accountId: null,
|
|
61
|
+
apiKey: null,
|
|
62
|
+
apiKeyId: null,
|
|
63
|
+
caller: null,
|
|
64
|
+
cognitoAuthenticationProvider: null,
|
|
65
|
+
cognitoAuthenticationType: null,
|
|
66
|
+
cognitoIdentityId: null,
|
|
67
|
+
cognitoIdentityPoolId: null,
|
|
68
|
+
principalOrgId: null,
|
|
69
|
+
sourceIp: "127.0.0.1",
|
|
70
|
+
user: null,
|
|
71
|
+
userAgent: "test-agent",
|
|
72
|
+
userArn: null,
|
|
73
|
+
clientCert: null
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
resource: "/test",
|
|
77
|
+
...overrides
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
82
|
+
*/
|
|
83
|
+
function createMockV2Event(overrides = {}) {
|
|
84
|
+
return {
|
|
85
|
+
version: "2.0",
|
|
86
|
+
routeKey: "GET /test",
|
|
87
|
+
rawPath: "/test",
|
|
88
|
+
rawQueryString: "",
|
|
89
|
+
headers: {
|
|
90
|
+
"content-type": "application/json",
|
|
91
|
+
"user-agent": "test-agent",
|
|
92
|
+
host: "test.example.com"
|
|
93
|
+
},
|
|
94
|
+
requestContext: {
|
|
95
|
+
accountId: "123456789012",
|
|
96
|
+
apiId: "api-id",
|
|
97
|
+
domainName: "test.example.com",
|
|
98
|
+
domainPrefix: "api",
|
|
99
|
+
requestId: "request-id",
|
|
100
|
+
routeKey: "GET /test",
|
|
101
|
+
stage: "test",
|
|
102
|
+
time: "01/Jan/2024:00:00:00 +0000",
|
|
103
|
+
timeEpoch: 17040672e5,
|
|
104
|
+
http: {
|
|
105
|
+
method: "GET",
|
|
106
|
+
path: "/test",
|
|
107
|
+
protocol: "HTTP/1.1",
|
|
108
|
+
sourceIp: "127.0.0.1",
|
|
109
|
+
userAgent: "test-agent"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
body: void 0,
|
|
113
|
+
pathParameters: void 0,
|
|
114
|
+
isBase64Encoded: false,
|
|
115
|
+
stageVariables: void 0,
|
|
116
|
+
queryStringParameters: void 0,
|
|
117
|
+
cookies: void 0,
|
|
118
|
+
...overrides
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
exports.createMockContext = createMockContext;
|
|
124
|
+
exports.createMockV1Event = createMockV1Event;
|
|
125
|
+
exports.createMockV2Event = createMockV2Event;
|
|
126
|
+
//# sourceMappingURL=aws.cjs.map
|
package/dist/aws.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.cjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n APIGatewayProxyEvent,\n APIGatewayProxyEventV2,\n Context,\n} from 'aws-lambda';\nimport { vi } from 'vitest';\n\n/**\n * Shared test utilities for AWS Lambda adapter testing\n */\n\n/**\n * Creates a mock AWS Lambda Context for testing\n */\nexport function createMockContext(): Context {\n return {\n awsRequestId: 'test-request-id',\n callbackWaitsForEmptyEventLoop: false,\n functionName: 'test-function',\n functionVersion: '1',\n invokedFunctionArn:\n 'arn:aws:lambda:us-east-1:123456789012:function:test-function',\n memoryLimitInMB: '128',\n logGroupName: '/aws/lambda/test-function',\n logStreamName: '2024/01/01/[$LATEST]abcdef123456',\n getRemainingTimeInMillis: () => 5000,\n done: vi.fn(),\n fail: vi.fn(),\n succeed: vi.fn(),\n };\n}\n\n/**\n * Creates a mock AWS API Gateway V1 (REST API) event for testing\n */\nexport function createMockV1Event(\n overrides: Partial<APIGatewayProxyEvent> = {},\n): APIGatewayProxyEvent {\n return {\n body: null,\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'test-agent',\n host: 'test.example.com',\n },\n multiValueHeaders: {},\n httpMethod: 'GET',\n isBase64Encoded: false,\n path: '/test',\n pathParameters: null,\n queryStringParameters: null,\n multiValueQueryStringParameters: null,\n stageVariables: null,\n requestContext: {\n accountId: '123456789012',\n apiId: 'api-id',\n authorizer: null,\n protocol: 'HTTP/1.1',\n httpMethod: 'GET',\n path: '/test',\n stage: 'test',\n requestId: 'request-id',\n requestTimeEpoch: 1704067200000,\n resourceId: 'resource-id',\n resourcePath: '/test',\n identity: {\n accessKey: null,\n accountId: null,\n apiKey: null,\n apiKeyId: null,\n caller: null,\n cognitoAuthenticationProvider: null,\n cognitoAuthenticationType: null,\n cognitoIdentityId: null,\n cognitoIdentityPoolId: null,\n principalOrgId: null,\n sourceIp: '127.0.0.1',\n user: null,\n userAgent: 'test-agent',\n userArn: null,\n clientCert: null,\n },\n },\n resource: '/test',\n ...overrides,\n };\n}\n\n/**\n * Creates a mock AWS API Gateway V2 (HTTP API) event for testing\n */\nexport function createMockV2Event(\n overrides: Partial<APIGatewayProxyEventV2> = {},\n): APIGatewayProxyEventV2 {\n return {\n version: '2.0',\n routeKey: 'GET /test',\n rawPath: '/test',\n rawQueryString: '',\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'test-agent',\n host: 'test.example.com',\n },\n requestContext: {\n accountId: '123456789012',\n apiId: 'api-id',\n domainName: 'test.example.com',\n domainPrefix: 'api',\n requestId: 'request-id',\n routeKey: 'GET /test',\n stage: 'test',\n time: '01/Jan/2024:00:00:00 +0000',\n timeEpoch: 1704067200000,\n http: {\n method: 'GET',\n path: '/test',\n protocol: 'HTTP/1.1',\n sourceIp: '127.0.0.1',\n userAgent: 'test-agent',\n },\n },\n body: undefined,\n pathParameters: undefined,\n isBase64Encoded: false,\n stageVariables: undefined,\n queryStringParameters: undefined,\n cookies: undefined,\n ...overrides,\n };\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAgB,oBAA6B;AAC3C,QAAO;EACL,cAAc;EACd,gCAAgC;EAChC,cAAc;EACd,iBAAiB;EACjB,oBACE;EACF,iBAAiB;EACjB,cAAc;EACd,eAAe;EACf,0BAA0B,MAAM;EAChC,MAAM,UAAG,IAAI;EACb,MAAM,UAAG,IAAI;EACb,SAAS,UAAG,IAAI;CACjB;AACF;;;;AAKD,SAAgB,kBACdA,YAA2C,CAAE,GACvB;AACtB,QAAO;EACL,MAAM;EACN,SAAS;GACP,gBAAgB;GAChB,cAAc;GACd,MAAM;EACP;EACD,mBAAmB,CAAE;EACrB,YAAY;EACZ,iBAAiB;EACjB,MAAM;EACN,gBAAgB;EAChB,uBAAuB;EACvB,iCAAiC;EACjC,gBAAgB;EAChB,gBAAgB;GACd,WAAW;GACX,OAAO;GACP,YAAY;GACZ,UAAU;GACV,YAAY;GACZ,MAAM;GACN,OAAO;GACP,WAAW;GACX,kBAAkB;GAClB,YAAY;GACZ,cAAc;GACd,UAAU;IACR,WAAW;IACX,WAAW;IACX,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,+BAA+B;IAC/B,2BAA2B;IAC3B,mBAAmB;IACnB,uBAAuB;IACvB,gBAAgB;IAChB,UAAU;IACV,MAAM;IACN,WAAW;IACX,SAAS;IACT,YAAY;GACb;EACF;EACD,UAAU;EACV,GAAG;CACJ;AACF;;;;AAKD,SAAgB,kBACdC,YAA6C,CAAE,GACvB;AACxB,QAAO;EACL,SAAS;EACT,UAAU;EACV,SAAS;EACT,gBAAgB;EAChB,SAAS;GACP,gBAAgB;GAChB,cAAc;GACd,MAAM;EACP;EACD,gBAAgB;GACd,WAAW;GACX,OAAO;GACP,YAAY;GACZ,cAAc;GACd,WAAW;GACX,UAAU;GACV,OAAO;GACP,MAAM;GACN,WAAW;GACX,MAAM;IACJ,QAAQ;IACR,MAAM;IACN,UAAU;IACV,UAAU;IACV,WAAW;GACZ;EACF;EACD;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA,GAAG;CACJ;AACF"}
|
package/dist/aws.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, Context } from "aws-lambda";
|
|
2
|
+
|
|
3
|
+
//#region src/aws.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared test utilities for AWS Lambda adapter testing
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a mock AWS Lambda Context for testing
|
|
10
|
+
*/
|
|
11
|
+
declare function createMockContext(): Context;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
14
|
+
*/
|
|
15
|
+
declare function createMockV1Event(overrides?: Partial<APIGatewayProxyEvent>): APIGatewayProxyEvent;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
18
|
+
*/
|
|
19
|
+
declare function createMockV2Event(overrides?: Partial<APIGatewayProxyEventV2>): APIGatewayProxyEventV2;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createMockContext, createMockV1Event, createMockV2Event };
|
|
22
|
+
//# sourceMappingURL=aws.d.cts.map
|
package/dist/aws.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, Context } from "aws-lambda";
|
|
2
|
+
|
|
3
|
+
//#region src/aws.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Shared test utilities for AWS Lambda adapter testing
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a mock AWS Lambda Context for testing
|
|
10
|
+
*/
|
|
11
|
+
declare function createMockContext(): Context;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
14
|
+
*/
|
|
15
|
+
declare function createMockV1Event(overrides?: Partial<APIGatewayProxyEvent>): APIGatewayProxyEvent;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
18
|
+
*/
|
|
19
|
+
declare function createMockV2Event(overrides?: Partial<APIGatewayProxyEventV2>): APIGatewayProxyEventV2;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createMockContext, createMockV1Event, createMockV2Event };
|
|
22
|
+
//# sourceMappingURL=aws.d.mts.map
|
package/dist/aws.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/aws.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shared test utilities for AWS Lambda adapter testing
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a mock AWS Lambda Context for testing
|
|
9
|
+
*/
|
|
10
|
+
function createMockContext() {
|
|
11
|
+
return {
|
|
12
|
+
awsRequestId: "test-request-id",
|
|
13
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
14
|
+
functionName: "test-function",
|
|
15
|
+
functionVersion: "1",
|
|
16
|
+
invokedFunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:test-function",
|
|
17
|
+
memoryLimitInMB: "128",
|
|
18
|
+
logGroupName: "/aws/lambda/test-function",
|
|
19
|
+
logStreamName: "2024/01/01/[$LATEST]abcdef123456",
|
|
20
|
+
getRemainingTimeInMillis: () => 5e3,
|
|
21
|
+
done: vi.fn(),
|
|
22
|
+
fail: vi.fn(),
|
|
23
|
+
succeed: vi.fn()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
28
|
+
*/
|
|
29
|
+
function createMockV1Event(overrides = {}) {
|
|
30
|
+
return {
|
|
31
|
+
body: null,
|
|
32
|
+
headers: {
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
"user-agent": "test-agent",
|
|
35
|
+
host: "test.example.com"
|
|
36
|
+
},
|
|
37
|
+
multiValueHeaders: {},
|
|
38
|
+
httpMethod: "GET",
|
|
39
|
+
isBase64Encoded: false,
|
|
40
|
+
path: "/test",
|
|
41
|
+
pathParameters: null,
|
|
42
|
+
queryStringParameters: null,
|
|
43
|
+
multiValueQueryStringParameters: null,
|
|
44
|
+
stageVariables: null,
|
|
45
|
+
requestContext: {
|
|
46
|
+
accountId: "123456789012",
|
|
47
|
+
apiId: "api-id",
|
|
48
|
+
authorizer: null,
|
|
49
|
+
protocol: "HTTP/1.1",
|
|
50
|
+
httpMethod: "GET",
|
|
51
|
+
path: "/test",
|
|
52
|
+
stage: "test",
|
|
53
|
+
requestId: "request-id",
|
|
54
|
+
requestTimeEpoch: 17040672e5,
|
|
55
|
+
resourceId: "resource-id",
|
|
56
|
+
resourcePath: "/test",
|
|
57
|
+
identity: {
|
|
58
|
+
accessKey: null,
|
|
59
|
+
accountId: null,
|
|
60
|
+
apiKey: null,
|
|
61
|
+
apiKeyId: null,
|
|
62
|
+
caller: null,
|
|
63
|
+
cognitoAuthenticationProvider: null,
|
|
64
|
+
cognitoAuthenticationType: null,
|
|
65
|
+
cognitoIdentityId: null,
|
|
66
|
+
cognitoIdentityPoolId: null,
|
|
67
|
+
principalOrgId: null,
|
|
68
|
+
sourceIp: "127.0.0.1",
|
|
69
|
+
user: null,
|
|
70
|
+
userAgent: "test-agent",
|
|
71
|
+
userArn: null,
|
|
72
|
+
clientCert: null
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
resource: "/test",
|
|
76
|
+
...overrides
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
81
|
+
*/
|
|
82
|
+
function createMockV2Event(overrides = {}) {
|
|
83
|
+
return {
|
|
84
|
+
version: "2.0",
|
|
85
|
+
routeKey: "GET /test",
|
|
86
|
+
rawPath: "/test",
|
|
87
|
+
rawQueryString: "",
|
|
88
|
+
headers: {
|
|
89
|
+
"content-type": "application/json",
|
|
90
|
+
"user-agent": "test-agent",
|
|
91
|
+
host: "test.example.com"
|
|
92
|
+
},
|
|
93
|
+
requestContext: {
|
|
94
|
+
accountId: "123456789012",
|
|
95
|
+
apiId: "api-id",
|
|
96
|
+
domainName: "test.example.com",
|
|
97
|
+
domainPrefix: "api",
|
|
98
|
+
requestId: "request-id",
|
|
99
|
+
routeKey: "GET /test",
|
|
100
|
+
stage: "test",
|
|
101
|
+
time: "01/Jan/2024:00:00:00 +0000",
|
|
102
|
+
timeEpoch: 17040672e5,
|
|
103
|
+
http: {
|
|
104
|
+
method: "GET",
|
|
105
|
+
path: "/test",
|
|
106
|
+
protocol: "HTTP/1.1",
|
|
107
|
+
sourceIp: "127.0.0.1",
|
|
108
|
+
userAgent: "test-agent"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
body: void 0,
|
|
112
|
+
pathParameters: void 0,
|
|
113
|
+
isBase64Encoded: false,
|
|
114
|
+
stageVariables: void 0,
|
|
115
|
+
queryStringParameters: void 0,
|
|
116
|
+
cookies: void 0,
|
|
117
|
+
...overrides
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { createMockContext, createMockV1Event, createMockV2Event };
|
|
123
|
+
//# sourceMappingURL=aws.mjs.map
|
package/dist/aws.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.mjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n APIGatewayProxyEvent,\n APIGatewayProxyEventV2,\n Context,\n} from 'aws-lambda';\nimport { vi } from 'vitest';\n\n/**\n * Shared test utilities for AWS Lambda adapter testing\n */\n\n/**\n * Creates a mock AWS Lambda Context for testing\n */\nexport function createMockContext(): Context {\n return {\n awsRequestId: 'test-request-id',\n callbackWaitsForEmptyEventLoop: false,\n functionName: 'test-function',\n functionVersion: '1',\n invokedFunctionArn:\n 'arn:aws:lambda:us-east-1:123456789012:function:test-function',\n memoryLimitInMB: '128',\n logGroupName: '/aws/lambda/test-function',\n logStreamName: '2024/01/01/[$LATEST]abcdef123456',\n getRemainingTimeInMillis: () => 5000,\n done: vi.fn(),\n fail: vi.fn(),\n succeed: vi.fn(),\n };\n}\n\n/**\n * Creates a mock AWS API Gateway V1 (REST API) event for testing\n */\nexport function createMockV1Event(\n overrides: Partial<APIGatewayProxyEvent> = {},\n): APIGatewayProxyEvent {\n return {\n body: null,\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'test-agent',\n host: 'test.example.com',\n },\n multiValueHeaders: {},\n httpMethod: 'GET',\n isBase64Encoded: false,\n path: '/test',\n pathParameters: null,\n queryStringParameters: null,\n multiValueQueryStringParameters: null,\n stageVariables: null,\n requestContext: {\n accountId: '123456789012',\n apiId: 'api-id',\n authorizer: null,\n protocol: 'HTTP/1.1',\n httpMethod: 'GET',\n path: '/test',\n stage: 'test',\n requestId: 'request-id',\n requestTimeEpoch: 1704067200000,\n resourceId: 'resource-id',\n resourcePath: '/test',\n identity: {\n accessKey: null,\n accountId: null,\n apiKey: null,\n apiKeyId: null,\n caller: null,\n cognitoAuthenticationProvider: null,\n cognitoAuthenticationType: null,\n cognitoIdentityId: null,\n cognitoIdentityPoolId: null,\n principalOrgId: null,\n sourceIp: '127.0.0.1',\n user: null,\n userAgent: 'test-agent',\n userArn: null,\n clientCert: null,\n },\n },\n resource: '/test',\n ...overrides,\n };\n}\n\n/**\n * Creates a mock AWS API Gateway V2 (HTTP API) event for testing\n */\nexport function createMockV2Event(\n overrides: Partial<APIGatewayProxyEventV2> = {},\n): APIGatewayProxyEventV2 {\n return {\n version: '2.0',\n routeKey: 'GET /test',\n rawPath: '/test',\n rawQueryString: '',\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'test-agent',\n host: 'test.example.com',\n },\n requestContext: {\n accountId: '123456789012',\n apiId: 'api-id',\n domainName: 'test.example.com',\n domainPrefix: 'api',\n requestId: 'request-id',\n routeKey: 'GET /test',\n stage: 'test',\n time: '01/Jan/2024:00:00:00 +0000',\n timeEpoch: 1704067200000,\n http: {\n method: 'GET',\n path: '/test',\n protocol: 'HTTP/1.1',\n sourceIp: '127.0.0.1',\n userAgent: 'test-agent',\n },\n },\n body: undefined,\n pathParameters: undefined,\n isBase64Encoded: false,\n stageVariables: undefined,\n queryStringParameters: undefined,\n cookies: undefined,\n ...overrides,\n };\n}\n"],"mappings":";;;;;;;;;AAcA,SAAgB,oBAA6B;AAC3C,QAAO;EACL,cAAc;EACd,gCAAgC;EAChC,cAAc;EACd,iBAAiB;EACjB,oBACE;EACF,iBAAiB;EACjB,cAAc;EACd,eAAe;EACf,0BAA0B,MAAM;EAChC,MAAM,GAAG,IAAI;EACb,MAAM,GAAG,IAAI;EACb,SAAS,GAAG,IAAI;CACjB;AACF;;;;AAKD,SAAgB,kBACdA,YAA2C,CAAE,GACvB;AACtB,QAAO;EACL,MAAM;EACN,SAAS;GACP,gBAAgB;GAChB,cAAc;GACd,MAAM;EACP;EACD,mBAAmB,CAAE;EACrB,YAAY;EACZ,iBAAiB;EACjB,MAAM;EACN,gBAAgB;EAChB,uBAAuB;EACvB,iCAAiC;EACjC,gBAAgB;EAChB,gBAAgB;GACd,WAAW;GACX,OAAO;GACP,YAAY;GACZ,UAAU;GACV,YAAY;GACZ,MAAM;GACN,OAAO;GACP,WAAW;GACX,kBAAkB;GAClB,YAAY;GACZ,cAAc;GACd,UAAU;IACR,WAAW;IACX,WAAW;IACX,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,+BAA+B;IAC/B,2BAA2B;IAC3B,mBAAmB;IACnB,uBAAuB;IACvB,gBAAgB;IAChB,UAAU;IACV,MAAM;IACN,WAAW;IACX,SAAS;IACT,YAAY;GACb;EACF;EACD,UAAU;EACV,GAAG;CACJ;AACF;;;;AAKD,SAAgB,kBACdC,YAA6C,CAAE,GACvB;AACxB,QAAO;EACL,SAAS;EACT,UAAU;EACV,SAAS;EACT,gBAAgB;EAChB,SAAS;GACP,gBAAgB;GAChB,cAAc;GACd,MAAM;EACP;EACD,gBAAgB;GACd,WAAW;GACX,OAAO;GACP,YAAY;GACZ,cAAc;GACd,WAAW;GACX,UAAU;GACV,OAAO;GACP,MAAM;GACN,WAAW;GACX,MAAM;IACJ,QAAQ;IACR,MAAM;IACN,UAAU;IACV,UAAU;IACV,WAAW;GACZ;EACF;EACD;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA,GAAG;CACJ;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { it } from "vitest";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
//#region src/os/directory.ts
|
|
8
|
+
const itWithDir = it.extend({ dir: async ({}, use) => {
|
|
9
|
+
const tempDir = os.tmpdir();
|
|
10
|
+
const directoryName = crypto.randomUUID().replace(/-/g, "").toUpperCase();
|
|
11
|
+
const dir = path.join(tempDir, directoryName);
|
|
12
|
+
await fs.mkdir(dir, { recursive: true });
|
|
13
|
+
await use(dir);
|
|
14
|
+
await fs.rm(dir, {
|
|
15
|
+
recursive: true,
|
|
16
|
+
force: true
|
|
17
|
+
});
|
|
18
|
+
} });
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { itWithDir };
|
|
22
|
+
//# sourceMappingURL=directory-B-Ozljzk.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-B-Ozljzk.mjs","names":[],"sources":["../src/os/directory.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { it } from 'vitest';\n\nexport const itWithDir = it.extend<DirectoryFixtures>({\n // This fixture automatically provides a transaction to each test\n dir: async ({}, use) => {\n const tempDir = os.tmpdir();\n const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();\n const dir = path.join(tempDir, directoryName);\n await fs.mkdir(dir, { recursive: true });\n await use(dir);\n await fs.rm(dir, { recursive: true, force: true });\n },\n});\n\nexport interface DirectoryFixtures {\n dir: string;\n}\n"],"mappings":";;;;;;;AAMA,MAAa,YAAY,GAAG,OAA0B,EAEpD,KAAK,OAAO,EAAE,EAAE,QAAQ;CACtB,MAAM,UAAU,GAAG,QAAQ;CAC3B,MAAM,gBAAgB,OAAO,YAAY,CAAC,QAAQ,MAAM,GAAG,CAAC,aAAa;CACzE,MAAM,MAAM,KAAK,KAAK,SAAS,cAAc;AAC7C,OAAM,GAAG,MAAM,KAAK,EAAE,WAAW,KAAM,EAAC;AACxC,OAAM,IAAI,IAAI;AACd,OAAM,GAAG,GAAG,KAAK;EAAE,WAAW;EAAM,OAAO;CAAM,EAAC;AACnD,EACF,EAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as vitest0 from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/os/directory.d.ts
|
|
4
|
+
declare const itWithDir: vitest0.TestAPI<{
|
|
5
|
+
dir: string;
|
|
6
|
+
}>;
|
|
7
|
+
interface DirectoryFixtures {
|
|
8
|
+
dir: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DirectoryFixtures, itWithDir };
|
|
12
|
+
//# sourceMappingURL=directory-B4oYx02C.d.mts.map
|