@geekmidas/testkit 0.0.12 → 0.0.14

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 (99) hide show
  1. package/README.md +1 -1
  2. package/dist/{Factory-Bm44VKa-.d.cts → Factory-D7P3bKKb.d.mts} +2 -2
  3. package/dist/{Factory-tjCDNgUK.d.mts → Factory-pNV7ZQ7-.d.cts} +2 -2
  4. package/dist/Factory.d.cts +2 -2
  5. package/dist/Factory.d.mts +2 -2
  6. package/dist/{KyselyFactory-BoPDDitt.d.cts → KyselyFactory-72P98y5I.d.mts} +3 -3
  7. package/dist/{KyselyFactory-C3Bc3p4L.mjs → KyselyFactory-BcYkC0t2.mjs} +1 -1
  8. package/dist/{KyselyFactory-CXtfmMfK.cjs → KyselyFactory-Cf0o2YxO.cjs} +1 -1
  9. package/dist/{KyselyFactory-D82j74t9.d.mts → KyselyFactory-DLBrYWxU.d.cts} +3 -3
  10. package/dist/KyselyFactory.cjs +1 -1
  11. package/dist/KyselyFactory.d.cts +3 -3
  12. package/dist/KyselyFactory.d.mts +3 -3
  13. package/dist/KyselyFactory.mjs +1 -1
  14. package/dist/{ObjectionFactory-qIICOph3.mjs → ObjectionFactory-8hebmnai.mjs} +20 -4
  15. package/dist/{ObjectionFactory-BWMTXsxH.d.cts → ObjectionFactory-B40NQWSe.d.mts} +2 -2
  16. package/dist/{ObjectionFactory-DxIxJagq.cjs → ObjectionFactory-CDriunkS.cjs} +20 -4
  17. package/dist/{ObjectionFactory-CEG5qUrm.d.mts → ObjectionFactory-D3l1VuyX.d.cts} +2 -2
  18. package/dist/ObjectionFactory.cjs +1 -1
  19. package/dist/ObjectionFactory.d.cts +3 -3
  20. package/dist/ObjectionFactory.d.mts +3 -3
  21. package/dist/ObjectionFactory.mjs +1 -1
  22. package/dist/{VitestKyselyTransactionIsolator-ClCazkBO.d.mts → VitestKyselyTransactionIsolator-CnxpE9cH.d.mts} +2 -1
  23. package/dist/{VitestKyselyTransactionIsolator-UE1J-UoP.d.cts → VitestKyselyTransactionIsolator-DYUYVEh9.d.cts} +2 -1
  24. package/dist/{VitestKyselyTransactionIsolator-BKGT9nEG.mjs → VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs} +4 -1
  25. package/dist/{VitestKyselyTransactionIsolator-CIlpIO78.cjs → VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs} +4 -1
  26. package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
  27. package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
  28. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  29. package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
  30. package/dist/{VitestObjectionTransactionIsolator-CO2nTi9r.d.cts → VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts} +3 -2
  31. package/dist/{VitestObjectionTransactionIsolator-D264iuPy.d.mts → VitestObjectionTransactionIsolator-DIM79dCq.d.mts} +3 -2
  32. package/dist/{VitestObjectionTransactionIsolator-BPoLUFop.mjs → VitestObjectionTransactionIsolator-DVtJG2F3.mjs} +6 -3
  33. package/dist/{VitestObjectionTransactionIsolator-DyqLp_in.cjs → VitestObjectionTransactionIsolator-LP4B0cqW.cjs} +6 -3
  34. package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
  35. package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
  36. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  37. package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
  38. package/dist/{VitestTransactionIsolator-CruLTRRi.cjs → VitestTransactionIsolator-BQ5FpLtC.cjs} +5 -2
  39. package/dist/{VitestTransactionIsolator-BWwK-ca6.mjs → VitestTransactionIsolator-CskiiJbW.mjs} +5 -2
  40. package/dist/{VitestTransactionIsolator-DHf2MxmC.d.cts → VitestTransactionIsolator-DdLNODZg.d.cts} +8 -5
  41. package/dist/{VitestTransactionIsolator-Xqyjlmw6.d.mts → VitestTransactionIsolator-zdyiS_SY.d.mts} +8 -5
  42. package/dist/VitestTransactionIsolator.cjs +1 -1
  43. package/dist/VitestTransactionIsolator.d.cts +2 -2
  44. package/dist/VitestTransactionIsolator.d.mts +2 -2
  45. package/dist/VitestTransactionIsolator.mjs +1 -1
  46. package/dist/__tests__/KyselyFactory.spec.cjs +6 -6
  47. package/dist/__tests__/KyselyFactory.spec.mjs +6 -6
  48. package/dist/__tests__/ObjectionFactory.spec.cjs +288 -450
  49. package/dist/__tests__/ObjectionFactory.spec.mjs +289 -451
  50. package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +397 -0
  51. package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +1 -0
  52. package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +1 -0
  53. package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +396 -0
  54. package/dist/__tests__/PostgresMigrator.spec.cjs +1 -1
  55. package/dist/__tests__/PostgresMigrator.spec.mjs +1 -1
  56. package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +1 -1
  57. package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +1 -1
  58. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +7 -16
  59. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +7 -16
  60. package/dist/__tests__/integration.spec.cjs +6 -6
  61. package/dist/__tests__/integration.spec.mjs +6 -6
  62. package/dist/{faker-km9UhOS6.d.cts → faker-BSH1EMtg.d.cts} +2 -2
  63. package/dist/{faker-ChuHaYMR.d.mts → faker-C-Iuk_R1.d.mts} +2 -2
  64. package/dist/faker.d.cts +1 -1
  65. package/dist/faker.d.mts +1 -1
  66. package/dist/{helpers-BEmjyUVE.mjs → helpers-B4TXg3Wp.mjs} +11 -36
  67. package/dist/{helpers-CNMBePuj.cjs → helpers-Bf0nXhbu.cjs} +10 -41
  68. package/dist/{kysely-Cx_1pZYc.mjs → kysely-BsDbvw3r.mjs} +4 -4
  69. package/dist/{kysely-CBfCXxUn.cjs → kysely-CP1iJMvq.cjs} +4 -4
  70. package/dist/kysely.cjs +4 -4
  71. package/dist/kysely.d.cts +6 -6
  72. package/dist/kysely.d.mts +6 -6
  73. package/dist/kysely.mjs +4 -4
  74. package/dist/{objection-lsMgM5gP.mjs → objection-BEPk9h-g.mjs} +5 -5
  75. package/dist/{objection-CCD8fMLj.cjs → objection-Di7JSist.cjs} +5 -5
  76. package/dist/objection.cjs +4 -4
  77. package/dist/objection.d.cts +7 -7
  78. package/dist/objection.d.mts +7 -7
  79. package/dist/objection.mjs +4 -4
  80. package/package.json +3 -3
  81. package/src/Factory.ts +4 -1
  82. package/src/KyselyFactory.ts +6 -2
  83. package/src/ObjectionFactory.ts +34 -4
  84. package/src/VitestKyselyTransactionIsolator.ts +3 -0
  85. package/src/VitestObjectionTransactionIsolator.ts +5 -2
  86. package/src/VitestTransactionIsolator.ts +11 -8
  87. package/src/__tests__/KyselyFactory.spec.ts +1 -1
  88. package/src/__tests__/ObjectionFactory.spec.ts +423 -542
  89. package/src/__tests__/PostgresKyselyMigrator.spec.ts +690 -0
  90. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +1 -10
  91. package/src/__tests__/integration.spec.ts +1 -1
  92. package/src/kysely.ts +6 -3
  93. package/src/objection.ts +7 -4
  94. package/test/helpers.ts +13 -21
  95. package/dist/example.cjs +0 -22
  96. package/dist/example.d.cts +0 -26
  97. package/dist/example.d.mts +0 -26
  98. package/dist/example.mjs +0 -22
  99. package/src/example.ts +0 -45
@@ -12,8 +12,6 @@ class User extends Model {
12
12
 
13
13
  id!: number;
14
14
  name!: string;
15
- email!: string;
16
- role?: string;
17
15
  createdAt!: Date;
18
16
  updatedAt?: Date;
19
17
 
@@ -108,13 +106,9 @@ class Comment extends Model {
108
106
  }
109
107
 
110
108
  // Create database connection
111
- const knex = createKnexDb();
112
-
113
- // Bind models to Knex instance
114
- Model.knex(knex);
115
109
 
116
110
  // Create wrapped test with transaction isolation
117
- const it = wrapVitestObjectionTransaction(base, knex, async (trx) => {
111
+ const it = wrapVitestObjectionTransaction(base, createKnexDb, async (trx) => {
118
112
  // Create tables in the transaction
119
113
  await createTestTablesKnex(trx);
120
114
  });
@@ -125,8 +119,6 @@ describe('VitestObjectionTransactionIsolator', () => {
125
119
  // Create a user within the transaction
126
120
  const user = await User.query(trx).insert({
127
121
  name: 'Test User',
128
- email: 'test@example.com',
129
- role: 'user',
130
122
  });
131
123
 
132
124
  expect(user).toBeDefined();
@@ -136,7 +128,6 @@ describe('VitestObjectionTransactionIsolator', () => {
136
128
  // Verify user exists in transaction
137
129
  const foundUser = await User.query(trx).findById(user.id);
138
130
  expect(foundUser).toBeDefined();
139
- expect(foundUser?.email).toBe(user.email);
140
131
 
141
132
  // Data will be rolled back after this test
142
133
  });
@@ -5,7 +5,7 @@ import { KyselyFactory } from '../KyselyFactory';
5
5
  import { createKyselyDb } from '../helpers';
6
6
  import { wrapVitestKyselyTransaction } from '../kysely';
7
7
 
8
- const db = createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
8
+ const db = () => createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
9
9
  const it = wrapVitestKyselyTransaction<TestDatabase>(
10
10
  base,
11
11
  db,
package/src/kysely.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import type { Kysely, Transaction } from 'kysely';
2
2
  import type { TestAPI } from 'vitest';
3
3
  import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
4
- import { IsolationLevel } from './VitestTransactionIsolator';
4
+ import {
5
+ type DatabaseConnection,
6
+ IsolationLevel,
7
+ } from './VitestTransactionIsolator';
5
8
 
6
9
  /**
7
10
  * Kysely-specific exports for test utilities.
@@ -71,11 +74,11 @@ export { IsolationLevel } from './VitestTransactionIsolator';
71
74
  */
72
75
  export function wrapVitestKyselyTransaction<Database>(
73
76
  api: TestAPI,
74
- db: Kysely<Database>,
77
+ connection: DatabaseConnection<Kysely<Database>>,
75
78
  setup?: (trx: Transaction<Database>) => Promise<void>,
76
79
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
77
80
  ) {
78
81
  const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
79
82
 
80
- return wrapper.wrapVitestWithTransaction(db, setup, level);
83
+ return wrapper.wrapVitestWithTransaction(connection, setup, level);
81
84
  }
package/src/objection.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import type { Knex } from 'knex';
2
2
  import type { TestAPI } from 'vitest';
3
3
  import { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
4
- import { IsolationLevel } from './VitestTransactionIsolator';
4
+ import {
5
+ type DatabaseConnection,
6
+ IsolationLevel,
7
+ } from './VitestTransactionIsolator';
5
8
 
6
9
  /**
7
10
  * Objection.js-specific exports for test utilities.
@@ -20,7 +23,7 @@ export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
20
23
  * This ensures tests don't affect each other's data and run faster than truncating tables.
21
24
  *
22
25
  * @param api - The Vitest test API (usually `test` from vitest)
23
- * @param knex - The Knex database connection instance
26
+ * @param conn - The Knex database connection instance
24
27
  * @param setup - Optional setup function to run before each test in the transaction
25
28
  * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
26
29
  * @returns A wrapped test API that provides transaction isolation
@@ -87,11 +90,11 @@ export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
87
90
  */
88
91
  export function wrapVitestObjectionTransaction(
89
92
  api: TestAPI,
90
- knex: Knex,
93
+ conn: DatabaseConnection<Knex>,
91
94
  setup?: (trx: Knex.Transaction) => Promise<void>,
92
95
  level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
93
96
  ) {
94
97
  const wrapper = new VitestObjectionTransactionIsolator(api);
95
98
 
96
- return wrapper.wrapVitestWithTransaction(knex, setup, level);
99
+ return wrapper.wrapVitestWithTransaction(conn, setup, level);
97
100
  }
package/test/helpers.ts CHANGED
@@ -165,49 +165,41 @@ export async function createTestTables(
165
165
  export async function createTestTablesKnex(
166
166
  trx: Knex.Transaction,
167
167
  ): Promise<void> {
168
- // Create users table
169
- await trx.schema.createTable('users', (table) => {
170
- table.bigIncrements('id').primary();
168
+ // Create simple users table for testing factory
169
+ await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
170
+ await trx.schema.createTableIfNotExists('users', (table) => {
171
+ table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
171
172
  table.string('name').notNullable();
172
- table.string('email').notNullable().unique();
173
- table.string('role').defaultTo('user');
174
- table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
175
- table.timestamp('updated_at').defaultTo(trx.fn.now()).notNullable();
176
173
  });
177
174
 
178
- // Create posts table
179
- await trx.schema.createTable('posts', (table) => {
180
- table.bigIncrements('id').primary();
175
+ // Create simple posts table for testing factory
176
+ await trx.schema.createTableIfNotExists('posts', (table) => {
177
+ table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
181
178
  table.string('title').notNullable();
182
- table.text('content').notNullable();
183
179
  table
184
- .bigInteger('user_id')
180
+ .uuid('user_id')
185
181
  .notNullable()
186
182
  .references('id')
187
183
  .inTable('users')
188
184
  .onDelete('cascade');
189
- table.boolean('published').defaultTo(false);
190
- table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
191
- table.timestamp('updated_at').defaultTo(trx.fn.now()).notNullable();
192
185
  });
193
186
 
194
- // Create comments table
195
- await trx.schema.createTable('comments', (table) => {
196
- table.bigIncrements('id').primary();
187
+ // Create simple comments table for testing factory
188
+ await trx.schema.createTableIfNotExists('comments', (table) => {
189
+ table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
197
190
  table.text('content').notNullable();
198
191
  table
199
- .bigInteger('post_id')
192
+ .uuid('post_id')
200
193
  .notNullable()
201
194
  .references('id')
202
195
  .inTable('posts')
203
196
  .onDelete('cascade');
204
197
  table
205
- .bigInteger('user_id')
198
+ .uuid('user_id')
206
199
  .notNullable()
207
200
  .references('id')
208
201
  .inTable('users')
209
202
  .onDelete('cascade');
210
- table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
211
203
  });
212
204
  }
213
205
 
package/dist/example.cjs DELETED
@@ -1,22 +0,0 @@
1
- require('./Factory-WMhTNZ9S.cjs');
2
- require('./faker-B14IEMIN.cjs');
3
- const require_KyselyFactory = require('./KyselyFactory-CXtfmMfK.cjs');
4
-
5
- //#region src/example.ts
6
- const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder({
7
- table: "users",
8
- defaults: async (attrs) => ({
9
- name: "John Doe",
10
- email: `user${Date.now()}@example.com`,
11
- createdAt: /* @__PURE__ */ new Date()
12
- })
13
- });
14
- const builders = { user: userBuilder };
15
- const factory = new require_KyselyFactory.KyselyFactory(builders, {}, {});
16
- factory.insert("user", {
17
- name: "Jane Doe",
18
- email: `user${Date.now()}@example.com`,
19
- createdAt: /* @__PURE__ */ new Date()
20
- });
21
-
22
- //#endregion
@@ -1,26 +0,0 @@
1
- import { FakerFactory } from "./faker-km9UhOS6.cjs";
2
- import * as kysely0 from "kysely";
3
-
4
- //#region src/example.d.ts
5
- interface Database {
6
- users: {
7
- id: number;
8
- name: string;
9
- email: string;
10
- createdAt: Date;
11
- };
12
- posts: {
13
- id: number;
14
- title: string;
15
- content: string;
16
- userId: number;
17
- createdAt: Date;
18
- };
19
- }
20
- declare const builders: {
21
- user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
22
- };
23
- type Builders = typeof builders;
24
- type Seeds = Record<string, any>;
25
- //#endregion
26
- export { Builders, Seeds };
@@ -1,26 +0,0 @@
1
- import { FakerFactory } from "./faker-ChuHaYMR.mjs";
2
- import * as kysely0 from "kysely";
3
-
4
- //#region src/example.d.ts
5
- interface Database {
6
- users: {
7
- id: number;
8
- name: string;
9
- email: string;
10
- createdAt: Date;
11
- };
12
- posts: {
13
- id: number;
14
- title: string;
15
- content: string;
16
- userId: number;
17
- createdAt: Date;
18
- };
19
- }
20
- declare const builders: {
21
- user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
22
- };
23
- type Builders = typeof builders;
24
- type Seeds = Record<string, any>;
25
- //#endregion
26
- export { Builders, Seeds };
package/dist/example.mjs DELETED
@@ -1,22 +0,0 @@
1
- import "./Factory-z2m01hMj.mjs";
2
- import "./faker-BGKYFoCT.mjs";
3
- import { KyselyFactory } from "./KyselyFactory-C3Bc3p4L.mjs";
4
-
5
- //#region src/example.ts
6
- const userBuilder = KyselyFactory.createBuilder({
7
- table: "users",
8
- defaults: async (attrs) => ({
9
- name: "John Doe",
10
- email: `user${Date.now()}@example.com`,
11
- createdAt: /* @__PURE__ */ new Date()
12
- })
13
- });
14
- const builders = { user: userBuilder };
15
- const factory = new KyselyFactory(builders, {}, {});
16
- factory.insert("user", {
17
- name: "Jane Doe",
18
- email: `user${Date.now()}@example.com`,
19
- createdAt: /* @__PURE__ */ new Date()
20
- });
21
-
22
- //#endregion
package/src/example.ts DELETED
@@ -1,45 +0,0 @@
1
- import { KyselyFactory } from './KyselyFactory';
2
-
3
- interface Database {
4
- users: {
5
- id: number;
6
- name: string;
7
- email: string;
8
- createdAt: Date;
9
- };
10
- posts: {
11
- id: number;
12
- title: string;
13
- content: string;
14
- userId: number;
15
- createdAt: Date;
16
- };
17
- }
18
-
19
- const userBuilder = KyselyFactory.createBuilder<Database, 'users'>({
20
- table: 'users',
21
- defaults: async (attrs) => ({
22
- name: 'John Doe',
23
- email: `user${Date.now()}@example.com`,
24
- createdAt: new Date(),
25
- }),
26
- });
27
-
28
- const builders = {
29
- user: userBuilder,
30
- };
31
-
32
- export type Builders = typeof builders;
33
- export type Seeds = Record<string, any>;
34
-
35
- const factory = new KyselyFactory<Database, Builders, Seeds>(
36
- builders,
37
- {},
38
- {} as any,
39
- );
40
-
41
- factory.insert('user', {
42
- name: 'Jane Doe',
43
- email: `user${Date.now()}@example.com`,
44
- createdAt: new Date(),
45
- });