@geekmidas/testkit 0.0.4 → 0.0.6

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.
Files changed (68) hide show
  1. package/dist/Factory.mjs +1 -1
  2. package/dist/{KyselyFactory-BGvSMLtd.cjs → KyselyFactory-BX7Kv2uP.cjs} +1 -1
  3. package/dist/{KyselyFactory-ionH4gvk.mjs → KyselyFactory-pOMOFQWE.mjs} +2 -2
  4. package/dist/KyselyFactory.cjs +2 -2
  5. package/dist/KyselyFactory.mjs +3 -3
  6. package/dist/{ObjectionFactory-CFrtXe7i.mjs → ObjectionFactory-ChuX8sZN.mjs} +1 -1
  7. package/dist/ObjectionFactory.mjs +2 -2
  8. package/dist/{PostgresKyselyMigrator-CbtiZgfI.mjs → PostgresKyselyMigrator-D8fm35-s.mjs} +1 -1
  9. package/dist/{PostgresKyselyMigrator-Cxf2Dp9y.cjs → PostgresKyselyMigrator-JTY2LfwD.cjs} +2 -2
  10. package/dist/PostgresKyselyMigrator.cjs +2 -2
  11. package/dist/PostgresKyselyMigrator.mjs +2 -2
  12. package/dist/{PostgresMigrator-eqyAFSf-.cjs → PostgresMigrator-Bz-tnjB6.cjs} +1 -1
  13. package/dist/PostgresMigrator.cjs +1 -1
  14. package/dist/PostgresMigrator.mjs +1 -1
  15. package/dist/{VitestKyselyTransactionIsolator-DXjWQtDN.mjs → VitestKyselyTransactionIsolator-D-qpeVKO.mjs} +1 -1
  16. package/dist/{VitestKyselyTransactionIsolator-Dh2AgJDd.cjs → VitestKyselyTransactionIsolator-jF6Ohyu_.cjs} +1 -1
  17. package/dist/VitestKyselyTransactionIsolator.cjs +2 -3
  18. package/dist/VitestKyselyTransactionIsolator.mjs +2 -3
  19. package/dist/{VitestTransactionIsolator-zK5NJ7DQ.cjs → VitestTransactionIsolator-BK9UsrKt.cjs} +4 -2
  20. package/dist/{VitestTransactionIsolator-pLwsDo_A.mjs → VitestTransactionIsolator-e-R3p_X8.mjs} +4 -3
  21. package/dist/VitestTransactionIsolator.cjs +1 -2
  22. package/dist/VitestTransactionIsolator.mjs +1 -2
  23. package/dist/__tests__/Factory.spec.cjs +42 -42
  24. package/dist/__tests__/Factory.spec.mjs +23 -24
  25. package/dist/__tests__/KyselyFactory.spec.cjs +80 -80
  26. package/dist/__tests__/KyselyFactory.spec.mjs +74 -74
  27. package/dist/__tests__/ObjectionFactory.spec.cjs +80 -81
  28. package/dist/__tests__/ObjectionFactory.spec.mjs +52 -53
  29. package/dist/__tests__/PostgresMigrator.spec.cjs +59 -60
  30. package/dist/__tests__/PostgresMigrator.spec.mjs +31 -32
  31. package/dist/__tests__/faker.spec.cjs +60 -60
  32. package/dist/__tests__/faker.spec.mjs +35 -36
  33. package/dist/__tests__/integration.spec.cjs +44 -41
  34. package/dist/__tests__/integration.spec.mjs +45 -43
  35. package/dist/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
  36. package/dist/example.cjs +2 -2
  37. package/dist/example.mjs +3 -3
  38. package/dist/{faker-h6CkRloU.cjs → faker-caz-8zt8.cjs} +1 -1
  39. package/dist/faker.cjs +1 -1
  40. package/dist/faker.mjs +1 -1
  41. package/dist/{helpers-C2NH7xcz.cjs → helpers-B2CfbaTC.cjs} +1 -1
  42. package/dist/helpers-DN4sJO4i.mjs +13 -0
  43. package/dist/helpers-DOtYCEvZ.cjs +19 -0
  44. package/dist/helpers.cjs +2 -6
  45. package/dist/helpers.mjs +2 -5
  46. package/dist/kysely-C1-aHdnU.mjs +11 -0
  47. package/dist/kysely-DL3C2eM4.cjs +16 -0
  48. package/dist/kysely.cjs +8 -15
  49. package/dist/kysely.mjs +8 -15
  50. package/dist/objection.mjs +2 -2
  51. package/package.json +2 -1
  52. package/src/VitestTransactionIsolator.ts +4 -2
  53. package/src/__tests__/KyselyFactory.spec.ts +4 -6
  54. package/src/__tests__/integration.spec.ts +8 -3
  55. package/src/helpers.ts +1 -18
  56. package/src/kysely.ts +3 -1
  57. package/dist/dist-BM2KvLG1.mjs +0 -5618
  58. package/dist/dist-DE3gAxQI.cjs +0 -5736
  59. package/dist/helpers-BnARb5Ap.mjs +0 -19
  60. package/dist/helpers-C_RZk04R.cjs +0 -31
  61. package/dist/magic-string.es-C6yzoryu.mjs +0 -1014
  62. package/dist/magic-string.es-jdtJrR0A.cjs +0 -1015
  63. package/dist/vi.bdSIJ99Y-BgRxGeO2.mjs +0 -9382
  64. package/dist/vi.bdSIJ99Y-CFuzUeY6.cjs +0 -9393
  65. /package/dist/{Factory-D52Lsc6Z.mjs → Factory-DlzMkMzb.mjs} +0 -0
  66. /package/dist/{PostgresMigrator-DqeuPy-e.mjs → PostgresMigrator-CEoRKTdq.mjs} +0 -0
  67. /package/dist/{faker-cGCFcrj2.mjs → faker-BwaXA_RF.mjs} +0 -0
  68. /package/dist/{helpers-CukcFAU9.mjs → helpers-Rf5F71r9.mjs} +0 -0
package/dist/kysely.mjs CHANGED
@@ -1,17 +1,10 @@
1
- import "./dist-BM2KvLG1.mjs";
2
- import "./Factory-D52Lsc6Z.mjs";
3
- import "./faker-cGCFcrj2.mjs";
4
- import { KyselyFactory } from "./KyselyFactory-ionH4gvk.mjs";
5
- import "./PostgresMigrator-DqeuPy-e.mjs";
6
- import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CbtiZgfI.mjs";
7
- import { IsolationLevel } from "./VitestTransactionIsolator-pLwsDo_A.mjs";
8
- import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DXjWQtDN.mjs";
1
+ import "./Factory-DlzMkMzb.mjs";
2
+ import "./faker-BwaXA_RF.mjs";
3
+ import { KyselyFactory } from "./KyselyFactory-pOMOFQWE.mjs";
4
+ import "./PostgresMigrator-CEoRKTdq.mjs";
5
+ import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-D8fm35-s.mjs";
6
+ import "./VitestTransactionIsolator-e-R3p_X8.mjs";
7
+ import "./VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
8
+ import { wrapVitestKyselyTransaction } from "./kysely-C1-aHdnU.mjs";
9
9
 
10
- //#region src/kysely.ts
11
- function wrapVitestKyselyTransaction(db, setup, level = IsolationLevel.REPEATABLE_READ) {
12
- const wrapper = new VitestKyselyTransactionIsolator();
13
- return wrapper.wrapVitestWithTransaction(db, setup, level);
14
- }
15
-
16
- //#endregion
17
10
  export { KyselyFactory, PostgresKyselyMigrator, wrapVitestKyselyTransaction };
@@ -1,4 +1,4 @@
1
- import "./Factory-D52Lsc6Z.mjs";
2
- import { ObjectionFactory } from "./ObjectionFactory-CFrtXe7i.mjs";
1
+ import "./Factory-DlzMkMzb.mjs";
2
+ import { ObjectionFactory } from "./ObjectionFactory-ChuX8sZN.mjs";
3
3
 
4
4
  export { ObjectionFactory };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/testkit",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,6 +36,7 @@
36
36
  "knex": "~3.1.0",
37
37
  "objection": "~3.1.5",
38
38
  "db-errors": "~0.2.3",
39
+ "vitest": "~3.2.4",
39
40
  "@geekmidas/envkit": "0.0.3"
40
41
  }
41
42
  }
@@ -1,4 +1,4 @@
1
- import { test as base } from 'vitest';
1
+ import type { TestAPI } from 'vitest';
2
2
 
3
3
  export interface DatabaseFixtures<Transaction> {
4
4
  trx: Transaction;
@@ -21,12 +21,14 @@ export abstract class VitestPostgresTransactionIsolator<
21
21
  fn: (trx: Transaction) => Promise<void>,
22
22
  ): Promise<void>;
23
23
 
24
+ constructor(private readonly api: TestAPI) {}
25
+
24
26
  wrapVitestWithTransaction(
25
27
  conn: Connection,
26
28
  setup?: (trx: Transaction) => Promise<void>,
27
29
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
28
30
  ) {
29
- return base.extend<DatabaseFixtures<Transaction>>({
31
+ return this.api.extend<DatabaseFixtures<Transaction>>({
30
32
  // This fixture automatically provides a transaction to each test
31
33
  trx: async ({}, use) => {
32
34
  // Create a custom error class for rollback
@@ -1,13 +1,14 @@
1
- import type { ControlledTransaction, Kysely } from 'kysely';
2
1
  import pg from 'pg';
3
- import { describe, expect } from 'vitest';
2
+ import { describe, expect, it } from 'vitest';
4
3
  import { TEST_DATABASE_CONFIG } from '../../test/globalSetup';
5
4
  import { type TestDatabase, createTestTables } from '../../test/helpers';
6
5
  import { KyselyFactory } from '../KyselyFactory';
7
- import { createKyselyDb, wrapVitestKyselyTransaction } from '../helpers';
6
+ import { createKyselyDb } from '../helpers';
7
+ import { wrapVitestKyselyTransaction } from '../kysely';
8
8
 
9
9
  const db = createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
10
10
  const itWithTransaction = wrapVitestKyselyTransaction<TestDatabase>(
11
+ it,
11
12
  db,
12
13
  createTestTables,
13
14
  );
@@ -17,9 +18,6 @@ pg.types.setTypeParser(int8TypeId, (val) => {
17
18
  return parseInt(val, 10);
18
19
  });
19
20
  describe('KyselyFactory', () => {
20
- let db: Kysely<TestDatabase>;
21
- let trx: ControlledTransaction<TestDatabase, []>;
22
-
23
21
  describe('KyselyFactory.insert', () => {
24
22
  itWithTransaction(
25
23
  'should insert a record with defaults',
@@ -1,11 +1,16 @@
1
- import { beforeAll, describe, expect } from 'vitest';
1
+ import { it as base, beforeAll, describe, expect } from 'vitest';
2
2
  import { TEST_DATABASE_CONFIG } from '../../test/globalSetup';
3
3
  import { type TestDatabase, createTestTables } from '../../test/helpers';
4
4
  import { KyselyFactory } from '../KyselyFactory';
5
- import { createKyselyDb, wrapVitestKyselyTransaction } from '../helpers';
5
+ import { createKyselyDb } from '../helpers';
6
+ import { wrapVitestKyselyTransaction } from '../kysely';
6
7
 
7
8
  const db = createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
8
- const it = wrapVitestKyselyTransaction<TestDatabase>(db, createTestTables);
9
+ const it = wrapVitestKyselyTransaction<TestDatabase>(
10
+ base,
11
+ db,
12
+ createTestTables,
13
+ );
9
14
  describe('Testkit Integration Tests', () => {
10
15
  beforeAll(async () => {});
11
16
  describe('Complex Factory Scenarios', () => {
package/src/helpers.ts CHANGED
@@ -1,22 +1,5 @@
1
- import {
2
- CamelCasePlugin,
3
- Kysely,
4
- PostgresDialect,
5
- type Transaction,
6
- } from 'kysely';
1
+ import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';
7
2
  import pg from 'pg';
8
- import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
9
- import { IsolationLevel } from './VitestTransactionIsolator';
10
-
11
- export function wrapVitestKyselyTransaction<Database>(
12
- db: Kysely<Database>,
13
- setup?: (trx: Transaction<Database>) => Promise<void>,
14
- level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
15
- ) {
16
- const wrapper = new VitestKyselyTransactionIsolator<Database>();
17
-
18
- return wrapper.wrapVitestWithTransaction(db, setup, level);
19
- }
20
3
 
21
4
  export function createKyselyDb<Database>(config: any): Kysely<Database> {
22
5
  return new Kysely({
package/src/kysely.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Kysely, Transaction } from 'kysely';
2
+ import type { TestAPI } from 'vitest';
2
3
  import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
3
4
  import { IsolationLevel } from './VitestTransactionIsolator';
4
5
 
@@ -6,11 +7,12 @@ export { KyselyFactory } from './KyselyFactory';
6
7
  export { PostgresKyselyMigrator } from './PostgresKyselyMigrator';
7
8
 
8
9
  export function wrapVitestKyselyTransaction<Database>(
10
+ api: TestAPI,
9
11
  db: Kysely<Database>,
10
12
  setup?: (trx: Transaction<Database>) => Promise<void>,
11
13
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
12
14
  ) {
13
- const wrapper = new VitestKyselyTransactionIsolator<Database>();
15
+ const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
14
16
 
15
17
  return wrapper.wrapVitestWithTransaction(db, setup, level);
16
18
  }