@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.
- package/README.md +1 -1
- package/dist/{Factory-Bm44VKa-.d.cts → Factory-D7P3bKKb.d.mts} +2 -2
- package/dist/{Factory-tjCDNgUK.d.mts → Factory-pNV7ZQ7-.d.cts} +2 -2
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/{KyselyFactory-BoPDDitt.d.cts → KyselyFactory-72P98y5I.d.mts} +3 -3
- package/dist/{KyselyFactory-C3Bc3p4L.mjs → KyselyFactory-BcYkC0t2.mjs} +1 -1
- package/dist/{KyselyFactory-CXtfmMfK.cjs → KyselyFactory-Cf0o2YxO.cjs} +1 -1
- package/dist/{KyselyFactory-D82j74t9.d.mts → KyselyFactory-DLBrYWxU.d.cts} +3 -3
- package/dist/KyselyFactory.cjs +1 -1
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/KyselyFactory.mjs +1 -1
- package/dist/{ObjectionFactory-qIICOph3.mjs → ObjectionFactory-8hebmnai.mjs} +20 -4
- package/dist/{ObjectionFactory-BWMTXsxH.d.cts → ObjectionFactory-B40NQWSe.d.mts} +2 -2
- package/dist/{ObjectionFactory-DxIxJagq.cjs → ObjectionFactory-CDriunkS.cjs} +20 -4
- package/dist/{ObjectionFactory-CEG5qUrm.d.mts → ObjectionFactory-D3l1VuyX.d.cts} +2 -2
- package/dist/ObjectionFactory.cjs +1 -1
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/ObjectionFactory.mjs +1 -1
- package/dist/{VitestKyselyTransactionIsolator-ClCazkBO.d.mts → VitestKyselyTransactionIsolator-CnxpE9cH.d.mts} +2 -1
- package/dist/{VitestKyselyTransactionIsolator-UE1J-UoP.d.cts → VitestKyselyTransactionIsolator-DYUYVEh9.d.cts} +2 -1
- package/dist/{VitestKyselyTransactionIsolator-BKGT9nEG.mjs → VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs} +4 -1
- package/dist/{VitestKyselyTransactionIsolator-CIlpIO78.cjs → VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs} +4 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
- package/dist/{VitestObjectionTransactionIsolator-CO2nTi9r.d.cts → VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts} +3 -2
- package/dist/{VitestObjectionTransactionIsolator-D264iuPy.d.mts → VitestObjectionTransactionIsolator-DIM79dCq.d.mts} +3 -2
- package/dist/{VitestObjectionTransactionIsolator-BPoLUFop.mjs → VitestObjectionTransactionIsolator-DVtJG2F3.mjs} +6 -3
- package/dist/{VitestObjectionTransactionIsolator-DyqLp_in.cjs → VitestObjectionTransactionIsolator-LP4B0cqW.cjs} +6 -3
- package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
- package/dist/{VitestTransactionIsolator-CruLTRRi.cjs → VitestTransactionIsolator-BQ5FpLtC.cjs} +5 -2
- package/dist/{VitestTransactionIsolator-BWwK-ca6.mjs → VitestTransactionIsolator-CskiiJbW.mjs} +5 -2
- package/dist/{VitestTransactionIsolator-DHf2MxmC.d.cts → VitestTransactionIsolator-DdLNODZg.d.cts} +8 -5
- package/dist/{VitestTransactionIsolator-Xqyjlmw6.d.mts → VitestTransactionIsolator-zdyiS_SY.d.mts} +8 -5
- package/dist/VitestTransactionIsolator.cjs +1 -1
- package/dist/VitestTransactionIsolator.d.cts +2 -2
- package/dist/VitestTransactionIsolator.d.mts +2 -2
- package/dist/VitestTransactionIsolator.mjs +1 -1
- package/dist/__tests__/KyselyFactory.spec.cjs +6 -6
- package/dist/__tests__/KyselyFactory.spec.mjs +6 -6
- package/dist/__tests__/ObjectionFactory.spec.cjs +288 -450
- package/dist/__tests__/ObjectionFactory.spec.mjs +289 -451
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +397 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +396 -0
- package/dist/__tests__/PostgresMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +1 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +7 -16
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +7 -16
- package/dist/__tests__/integration.spec.cjs +6 -6
- package/dist/__tests__/integration.spec.mjs +6 -6
- package/dist/{faker-km9UhOS6.d.cts → faker-BSH1EMtg.d.cts} +2 -2
- package/dist/{faker-ChuHaYMR.d.mts → faker-C-Iuk_R1.d.mts} +2 -2
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/{helpers-BEmjyUVE.mjs → helpers-B4TXg3Wp.mjs} +11 -36
- package/dist/{helpers-CNMBePuj.cjs → helpers-Bf0nXhbu.cjs} +10 -41
- package/dist/{kysely-Cx_1pZYc.mjs → kysely-BsDbvw3r.mjs} +4 -4
- package/dist/{kysely-CBfCXxUn.cjs → kysely-CP1iJMvq.cjs} +4 -4
- package/dist/kysely.cjs +4 -4
- package/dist/kysely.d.cts +6 -6
- package/dist/kysely.d.mts +6 -6
- package/dist/kysely.mjs +4 -4
- package/dist/{objection-lsMgM5gP.mjs → objection-BEPk9h-g.mjs} +5 -5
- package/dist/{objection-CCD8fMLj.cjs → objection-Di7JSist.cjs} +5 -5
- package/dist/objection.cjs +4 -4
- package/dist/objection.d.cts +7 -7
- package/dist/objection.d.mts +7 -7
- package/dist/objection.mjs +4 -4
- package/package.json +3 -3
- package/src/Factory.ts +4 -1
- package/src/KyselyFactory.ts +6 -2
- package/src/ObjectionFactory.ts +34 -4
- package/src/VitestKyselyTransactionIsolator.ts +3 -0
- package/src/VitestObjectionTransactionIsolator.ts +5 -2
- package/src/VitestTransactionIsolator.ts +11 -8
- package/src/__tests__/KyselyFactory.spec.ts +1 -1
- package/src/__tests__/ObjectionFactory.spec.ts +423 -542
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +690 -0
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +1 -10
- package/src/__tests__/integration.spec.ts +1 -1
- package/src/kysely.ts +6 -3
- package/src/objection.ts +7 -4
- package/test/helpers.ts +13 -21
- package/dist/example.cjs +0 -22
- package/dist/example.d.cts +0 -26
- package/dist/example.d.mts +0 -26
- package/dist/example.mjs +0 -22
- package/src/example.ts +0 -45
|
@@ -24,23 +24,6 @@ function createKnexDb() {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Test setup helper for Knex/Objection that creates tables within a transaction
|
|
28
|
-
*/
|
|
29
|
-
async function setupKnexTest() {
|
|
30
|
-
const db = createKnexDb();
|
|
31
|
-
const trx = await db.transaction();
|
|
32
|
-
await createTestTablesKnex(trx);
|
|
33
|
-
const cleanup = async () => {
|
|
34
|
-
await trx.rollback();
|
|
35
|
-
await db.destroy();
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
db,
|
|
39
|
-
trx,
|
|
40
|
-
cleanup
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
27
|
* Creates test tables using Kysely
|
|
45
28
|
*/
|
|
46
29
|
async function createTestTables(db) {
|
|
@@ -52,29 +35,21 @@ async function createTestTables(db) {
|
|
|
52
35
|
* Creates test tables using Knex
|
|
53
36
|
*/
|
|
54
37
|
async function createTestTablesKnex(trx) {
|
|
55
|
-
await trx.
|
|
56
|
-
|
|
38
|
+
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
39
|
+
await trx.schema.createTableIfNotExists("users", (table) => {
|
|
40
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
57
41
|
table.string("name").notNullable();
|
|
58
|
-
table.string("email").notNullable().unique();
|
|
59
|
-
table.string("role").defaultTo("user");
|
|
60
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
61
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
62
42
|
});
|
|
63
|
-
await trx.schema.
|
|
64
|
-
table.
|
|
43
|
+
await trx.schema.createTableIfNotExists("posts", (table) => {
|
|
44
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
65
45
|
table.string("title").notNullable();
|
|
66
|
-
table.
|
|
67
|
-
table.bigInteger("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
68
|
-
table.boolean("published").defaultTo(false);
|
|
69
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
70
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
46
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
71
47
|
});
|
|
72
|
-
await trx.schema.
|
|
73
|
-
table.
|
|
48
|
+
await trx.schema.createTableIfNotExists("comments", (table) => {
|
|
49
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
74
50
|
table.text("content").notNullable();
|
|
75
|
-
table.
|
|
76
|
-
table.
|
|
77
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
51
|
+
table.uuid("post_id").notNullable().references("id").inTable("posts").onDelete("cascade");
|
|
52
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
78
53
|
});
|
|
79
54
|
}
|
|
80
55
|
/**
|
|
@@ -108,4 +83,4 @@ async function createTestDatabase(dbName) {
|
|
|
108
83
|
}
|
|
109
84
|
|
|
110
85
|
//#endregion
|
|
111
|
-
export { TEST_DATABASE_CONFIG, createKnexDb, createTestDatabase, createTestTables, createTestTablesKnex
|
|
86
|
+
export { TEST_DATABASE_CONFIG, createKnexDb, createTestDatabase, createTestTables, createTestTablesKnex };
|
|
@@ -25,23 +25,6 @@ function createKnexDb() {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Test setup helper for Knex/Objection that creates tables within a transaction
|
|
29
|
-
*/
|
|
30
|
-
async function setupKnexTest() {
|
|
31
|
-
const db = createKnexDb();
|
|
32
|
-
const trx = await db.transaction();
|
|
33
|
-
await createTestTablesKnex(trx);
|
|
34
|
-
const cleanup = async () => {
|
|
35
|
-
await trx.rollback();
|
|
36
|
-
await db.destroy();
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
db,
|
|
40
|
-
trx,
|
|
41
|
-
cleanup
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
28
|
* Creates test tables using Kysely
|
|
46
29
|
*/
|
|
47
30
|
async function createTestTables(db) {
|
|
@@ -53,29 +36,21 @@ async function createTestTables(db) {
|
|
|
53
36
|
* Creates test tables using Knex
|
|
54
37
|
*/
|
|
55
38
|
async function createTestTablesKnex(trx) {
|
|
56
|
-
await trx.
|
|
57
|
-
|
|
39
|
+
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
40
|
+
await trx.schema.createTableIfNotExists("users", (table) => {
|
|
41
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
58
42
|
table.string("name").notNullable();
|
|
59
|
-
table.string("email").notNullable().unique();
|
|
60
|
-
table.string("role").defaultTo("user");
|
|
61
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
62
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
63
43
|
});
|
|
64
|
-
await trx.schema.
|
|
65
|
-
table.
|
|
44
|
+
await trx.schema.createTableIfNotExists("posts", (table) => {
|
|
45
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
66
46
|
table.string("title").notNullable();
|
|
67
|
-
table.
|
|
68
|
-
table.bigInteger("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
69
|
-
table.boolean("published").defaultTo(false);
|
|
70
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
71
|
-
table.timestamp("updated_at").defaultTo(trx.fn.now()).notNullable();
|
|
47
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
72
48
|
});
|
|
73
|
-
await trx.schema.
|
|
74
|
-
table.
|
|
49
|
+
await trx.schema.createTableIfNotExists("comments", (table) => {
|
|
50
|
+
table.uuid("id").primary().defaultTo(trx.raw("uuid_generate_v4()"));
|
|
75
51
|
table.text("content").notNullable();
|
|
76
|
-
table.
|
|
77
|
-
table.
|
|
78
|
-
table.timestamp("created_at").defaultTo(trx.fn.now()).notNullable();
|
|
52
|
+
table.uuid("post_id").notNullable().references("id").inTable("posts").onDelete("cascade");
|
|
53
|
+
table.uuid("user_id").notNullable().references("id").inTable("users").onDelete("cascade");
|
|
79
54
|
});
|
|
80
55
|
}
|
|
81
56
|
/**
|
|
@@ -138,10 +113,4 @@ Object.defineProperty(exports, 'createTestTablesKnex', {
|
|
|
138
113
|
get: function () {
|
|
139
114
|
return createTestTablesKnex;
|
|
140
115
|
}
|
|
141
|
-
});
|
|
142
|
-
Object.defineProperty(exports, 'setupKnexTest', {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return setupKnexTest;
|
|
146
|
-
}
|
|
147
116
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/kysely.ts
|
|
5
5
|
/**
|
|
@@ -58,9 +58,9 @@ import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolat
|
|
|
58
58
|
* });
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
function wrapVitestKyselyTransaction(api,
|
|
61
|
+
function wrapVitestKyselyTransaction(api, connection, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
62
62
|
const wrapper = new VitestKyselyTransactionIsolator(api);
|
|
63
|
-
return wrapper.wrapVitestWithTransaction(
|
|
63
|
+
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
2
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
2
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/kysely.ts
|
|
5
5
|
/**
|
|
@@ -58,9 +58,9 @@ const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransacti
|
|
|
58
58
|
* });
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
function wrapVitestKyselyTransaction(api,
|
|
61
|
+
function wrapVitestKyselyTransaction(api, connection, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
62
62
|
const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
|
|
63
|
-
return wrapper.wrapVitestWithTransaction(
|
|
63
|
+
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
//#endregion
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require('./Factory-WMhTNZ9S.cjs');
|
|
2
2
|
require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-Cf0o2YxO.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-CfytARcA.cjs');
|
|
6
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
7
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-
|
|
8
|
-
const require_kysely = require('./kysely-
|
|
6
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
7
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs');
|
|
8
|
+
const require_kysely = require('./kysely-CP1iJMvq.cjs');
|
|
9
9
|
|
|
10
10
|
exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
|
|
11
11
|
exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
|
package/dist/kysely.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./faker-BSH1EMtg.cjs";
|
|
2
|
+
import "./Factory-pNV7ZQ7-.cjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-DLBrYWxU.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DYUYVEh9.cjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
@@ -66,7 +66,7 @@ import { TestAPI } from "vitest";
|
|
|
66
66
|
* });
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI,
|
|
69
|
+
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection: DatabaseConnection<Kysely<Database>>, setup?: (trx: Transaction<Database>) => Promise<void>, level?: IsolationLevel): TestAPI<{
|
|
70
70
|
trx: Transaction<Database>;
|
|
71
71
|
}>;
|
|
72
72
|
//#endregion
|
package/dist/kysely.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./faker-C-Iuk_R1.mjs";
|
|
2
|
+
import "./Factory-D7P3bKKb.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-72P98y5I.mjs";
|
|
4
4
|
import "./PostgresMigrator-BlvuQl7d.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-_6yHZigp.mjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-zdyiS_SY.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-CnxpE9cH.mjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
@@ -66,7 +66,7 @@ import { TestAPI } from "vitest";
|
|
|
66
66
|
* });
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI,
|
|
69
|
+
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection: DatabaseConnection<Kysely<Database>>, setup?: (trx: Transaction<Database>) => Promise<void>, level?: IsolationLevel): TestAPI<{
|
|
70
70
|
trx: Transaction<Database>;
|
|
71
71
|
}>;
|
|
72
72
|
//#endregion
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
2
|
import "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-BcYkC0t2.mjs";
|
|
4
4
|
import "./PostgresMigrator-DxPC_gGu.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-Bdhl251C.mjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
8
|
-
import { wrapVitestKyselyTransaction } from "./kysely-
|
|
6
|
+
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs";
|
|
8
|
+
import { wrapVitestKyselyTransaction } from "./kysely-BsDbvw3r.mjs";
|
|
9
9
|
|
|
10
10
|
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-DVtJG2F3.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/objection.ts
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransaction
|
|
|
8
8
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
9
9
|
*
|
|
10
10
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
11
|
-
* @param
|
|
11
|
+
* @param conn - The Knex database connection instance
|
|
12
12
|
* @param setup - Optional setup function to run before each test in the transaction
|
|
13
13
|
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
14
14
|
* @returns A wrapped test API that provides transaction isolation
|
|
@@ -73,9 +73,9 @@ import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransaction
|
|
|
73
73
|
* });
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
function wrapVitestObjectionTransaction(api,
|
|
76
|
+
function wrapVitestObjectionTransaction(api, conn, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
77
77
|
const wrapper = new VitestObjectionTransactionIsolator(api);
|
|
78
|
-
return wrapper.wrapVitestWithTransaction(
|
|
78
|
+
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
2
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
2
|
+
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-LP4B0cqW.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/objection.ts
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTra
|
|
|
8
8
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
9
9
|
*
|
|
10
10
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
11
|
-
* @param
|
|
11
|
+
* @param conn - The Knex database connection instance
|
|
12
12
|
* @param setup - Optional setup function to run before each test in the transaction
|
|
13
13
|
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
14
14
|
* @returns A wrapped test API that provides transaction isolation
|
|
@@ -73,9 +73,9 @@ const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTra
|
|
|
73
73
|
* });
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
function wrapVitestObjectionTransaction(api,
|
|
76
|
+
function wrapVitestObjectionTransaction(api, conn, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
77
77
|
const wrapper = new require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator(api);
|
|
78
|
-
return wrapper.wrapVitestWithTransaction(
|
|
78
|
+
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
//#endregion
|
package/dist/objection.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require('./Factory-WMhTNZ9S.cjs');
|
|
2
2
|
require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_ObjectionFactory = require('./ObjectionFactory-
|
|
3
|
+
const require_ObjectionFactory = require('./ObjectionFactory-CDriunkS.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
6
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
7
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-
|
|
8
|
-
const require_objection = require('./objection-
|
|
6
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
7
|
+
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-LP4B0cqW.cjs');
|
|
8
|
+
const require_objection = require('./objection-Di7JSist.cjs');
|
|
9
9
|
|
|
10
10
|
exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
|
|
11
11
|
exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
|
package/dist/objection.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-BSH1EMtg.cjs";
|
|
2
|
+
import "./Factory-pNV7ZQ7-.cjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-D3l1VuyX.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-CZHHcCOv.cjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
|
|
7
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-CJ4ds5Qv.cjs";
|
|
8
8
|
import { Knex } from "knex";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ import { TestAPI } from "vitest";
|
|
|
16
16
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
17
17
|
*
|
|
18
18
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
19
|
-
* @param
|
|
19
|
+
* @param conn - The Knex database connection instance
|
|
20
20
|
* @param setup - Optional setup function to run before each test in the transaction
|
|
21
21
|
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
22
22
|
* @returns A wrapped test API that provides transaction isolation
|
|
@@ -81,7 +81,7 @@ import { TestAPI } from "vitest";
|
|
|
81
81
|
* });
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
|
-
declare function wrapVitestObjectionTransaction(api: TestAPI,
|
|
84
|
+
declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConnection<Knex>, setup?: (trx: Knex.Transaction) => Promise<void>, level?: IsolationLevel): TestAPI<{
|
|
85
85
|
trx: Knex.Transaction<any, any[]>;
|
|
86
86
|
}>;
|
|
87
87
|
//#endregion
|
package/dist/objection.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-C-Iuk_R1.mjs";
|
|
2
|
+
import "./Factory-D7P3bKKb.mjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-B40NQWSe.mjs";
|
|
4
4
|
import "./PostgresMigrator-BlvuQl7d.mjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-C69n7vzr.mjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-zdyiS_SY.mjs";
|
|
7
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-DIM79dCq.mjs";
|
|
8
8
|
import { TestAPI } from "vitest";
|
|
9
9
|
import { Knex } from "knex";
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ import { Knex } from "knex";
|
|
|
16
16
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
17
17
|
*
|
|
18
18
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
19
|
-
* @param
|
|
19
|
+
* @param conn - The Knex database connection instance
|
|
20
20
|
* @param setup - Optional setup function to run before each test in the transaction
|
|
21
21
|
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
22
22
|
* @returns A wrapped test API that provides transaction isolation
|
|
@@ -81,7 +81,7 @@ import { Knex } from "knex";
|
|
|
81
81
|
* });
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
|
-
declare function wrapVitestObjectionTransaction(api: TestAPI,
|
|
84
|
+
declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConnection<Knex>, setup?: (trx: Knex.Transaction) => Promise<void>, level?: IsolationLevel): TestAPI<{
|
|
85
85
|
trx: Knex.Transaction<any, any[]>;
|
|
86
86
|
}>;
|
|
87
87
|
//#endregion
|
package/dist/objection.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
2
|
import "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-8hebmnai.mjs";
|
|
4
4
|
import "./PostgresMigrator-DxPC_gGu.mjs";
|
|
5
5
|
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-G4h5FLvU.mjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
8
|
-
import { wrapVitestObjectionTransaction } from "./objection-
|
|
6
|
+
import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
|
|
7
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-DVtJG2F3.mjs";
|
|
8
|
+
import { wrapVitestObjectionTransaction } from "./objection-BEPk9h-g.mjs";
|
|
9
9
|
|
|
10
10
|
export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/testkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"require": "./dist/objection.cjs"
|
|
11
11
|
},
|
|
12
12
|
"./kysely": {
|
|
13
|
-
"types": "./dist/kysely.ts",
|
|
13
|
+
"types": "./dist/kysely.d.ts",
|
|
14
14
|
"import": "./dist/kysely.mjs",
|
|
15
15
|
"require": "./dist/kysely.cjs"
|
|
16
16
|
},
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"objection": "~3.1.5",
|
|
38
38
|
"db-errors": "~0.2.3",
|
|
39
39
|
"vitest": "~3.2.4",
|
|
40
|
-
"@geekmidas/envkit": "0.0.
|
|
40
|
+
"@geekmidas/envkit": "0.0.6"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/Factory.ts
CHANGED
|
@@ -71,7 +71,10 @@ export abstract class Factory<
|
|
|
71
71
|
builderName: K,
|
|
72
72
|
attrs?:
|
|
73
73
|
| Parameters<Builders[K]>[0]
|
|
74
|
-
| ((
|
|
74
|
+
| ((
|
|
75
|
+
idx: number,
|
|
76
|
+
faker: FakerFactory,
|
|
77
|
+
) => Promise<Parameters<Builders[K]>[0]>),
|
|
75
78
|
): Promise<Awaited<ReturnType<Builders[K]>>[]>;
|
|
76
79
|
|
|
77
80
|
/**
|
package/src/KyselyFactory.ts
CHANGED
|
@@ -286,7 +286,10 @@ export class KyselyFactory<
|
|
|
286
286
|
async insertMany<K extends keyof Builders>(
|
|
287
287
|
count: number,
|
|
288
288
|
builderName: K,
|
|
289
|
-
attrs: (
|
|
289
|
+
attrs: (
|
|
290
|
+
idx: number,
|
|
291
|
+
faker: FakerFactory,
|
|
292
|
+
) => Parameters<Builders[K]>[0] | Promise<Parameters<Builders[K]>[0]>,
|
|
290
293
|
): Promise<Awaited<ReturnType<Builders[K]>>[]>;
|
|
291
294
|
async insertMany<K extends keyof Builders>(
|
|
292
295
|
count: number,
|
|
@@ -304,7 +307,8 @@ export class KyselyFactory<
|
|
|
304
307
|
const promises: Promise<any>[] = [];
|
|
305
308
|
|
|
306
309
|
for (let i = 0; i < count; i++) {
|
|
307
|
-
const newAttrs =
|
|
310
|
+
const newAttrs =
|
|
311
|
+
typeof attrs === 'function' ? await attrs(i, faker) : attrs;
|
|
308
312
|
promises.push(this.insert(builderName, newAttrs));
|
|
309
313
|
}
|
|
310
314
|
|
package/src/ObjectionFactory.ts
CHANGED
|
@@ -144,8 +144,17 @@ export class ObjectionFactory<
|
|
|
144
144
|
// Handle insertion based on autoInsert flag
|
|
145
145
|
if (autoInsert !== false) {
|
|
146
146
|
// Auto insert is enabled by default
|
|
147
|
+
// Extract only defined values for insertion
|
|
148
|
+
const insertData = Object.entries(model).reduce((acc, [key, value]) => {
|
|
149
|
+
if (value !== undefined && key !== 'id') {
|
|
150
|
+
acc[key] = value;
|
|
151
|
+
}
|
|
152
|
+
return acc;
|
|
153
|
+
}, {} as any);
|
|
154
|
+
|
|
155
|
+
// Use static query method to insert data directly
|
|
147
156
|
// @ts-ignore
|
|
148
|
-
const result = await
|
|
157
|
+
const result = await ModelClass.query(db).insert(insertData);
|
|
149
158
|
return result as Result;
|
|
150
159
|
} else {
|
|
151
160
|
// Return model for factory to handle insertion
|
|
@@ -221,7 +230,16 @@ export class ObjectionFactory<
|
|
|
221
230
|
|
|
222
231
|
// If the builder returns a model instance, insert it
|
|
223
232
|
if (result && typeof result.$query === 'function') {
|
|
224
|
-
|
|
233
|
+
// Extract data from model, excluding undefined values and id
|
|
234
|
+
const insertData = Object.entries(result).reduce((acc, [key, value]) => {
|
|
235
|
+
if (value !== undefined && key !== 'id') {
|
|
236
|
+
acc[key] = value;
|
|
237
|
+
}
|
|
238
|
+
return acc;
|
|
239
|
+
}, {} as any);
|
|
240
|
+
|
|
241
|
+
// Use the model's constructor to get the query builder
|
|
242
|
+
return await result.constructor.query(this.db).insert(insertData);
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
// Otherwise, assume the builder handled insertion itself
|
|
@@ -283,14 +301,26 @@ export class ObjectionFactory<
|
|
|
283
301
|
const records: any[] = [];
|
|
284
302
|
for (let i = 0; i < count; i++) {
|
|
285
303
|
const newAttrs =
|
|
286
|
-
typeof attrs === 'function' ? (attrs as any)(i, faker) : attrs;
|
|
304
|
+
typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;
|
|
287
305
|
|
|
288
306
|
records.push(
|
|
289
307
|
this.builders[builderName](newAttrs, this, this.db, faker).then(
|
|
290
308
|
(record: any) => {
|
|
291
309
|
// If the builder returns a model instance, insert it
|
|
292
310
|
if (record && typeof record.$query === 'function') {
|
|
293
|
-
|
|
311
|
+
// Extract data from model, excluding undefined values and id
|
|
312
|
+
const insertData = Object.entries(record).reduce(
|
|
313
|
+
(acc, [key, value]) => {
|
|
314
|
+
if (value !== undefined && key !== 'id') {
|
|
315
|
+
acc[key] = value;
|
|
316
|
+
}
|
|
317
|
+
return acc;
|
|
318
|
+
},
|
|
319
|
+
{} as any,
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
// Use the model's constructor to get the query builder
|
|
323
|
+
return record.constructor.query(this.db).insert(insertData);
|
|
294
324
|
}
|
|
295
325
|
// Otherwise, assume the builder handled insertion itself
|
|
296
326
|
return record;
|
|
@@ -47,6 +47,9 @@ export class VitestKyselyTransactionIsolator<
|
|
|
47
47
|
Kysely<Database>,
|
|
48
48
|
Transaction<Database>
|
|
49
49
|
> {
|
|
50
|
+
destroy(conn: Kysely<Database>): Promise<void> {
|
|
51
|
+
return conn.destroy();
|
|
52
|
+
}
|
|
50
53
|
/**
|
|
51
54
|
* Creates a Kysely transaction with the specified isolation level.
|
|
52
55
|
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
@@ -36,6 +36,9 @@ export class VitestObjectionTransactionIsolator extends VitestPostgresTransactio
|
|
|
36
36
|
Knex,
|
|
37
37
|
Knex.Transaction
|
|
38
38
|
> {
|
|
39
|
+
destroy(conn: Knex<any, any[]>): Promise<void> {
|
|
40
|
+
return conn.destroy();
|
|
41
|
+
}
|
|
39
42
|
/**
|
|
40
43
|
* Creates a Knex transaction with the specified isolation level.
|
|
41
44
|
* Implements the abstract transact method from VitestPostgresTransactionIsolator.
|
|
@@ -56,13 +59,13 @@ export class VitestObjectionTransactionIsolator extends VitestPostgresTransactio
|
|
|
56
59
|
* ```
|
|
57
60
|
*/
|
|
58
61
|
async transact(
|
|
59
|
-
|
|
62
|
+
connection: Knex,
|
|
60
63
|
level: IsolationLevel,
|
|
61
64
|
fn: (trx: Knex.Transaction) => Promise<void>,
|
|
62
65
|
): Promise<void> {
|
|
63
66
|
const isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;
|
|
64
67
|
|
|
65
|
-
await
|
|
68
|
+
await connection.transaction(
|
|
66
69
|
async (trx) => {
|
|
67
70
|
await fn(trx);
|
|
68
71
|
},
|