@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.
- package/dist/Factory.mjs +1 -1
- package/dist/{KyselyFactory-BGvSMLtd.cjs → KyselyFactory-BX7Kv2uP.cjs} +1 -1
- package/dist/{KyselyFactory-ionH4gvk.mjs → KyselyFactory-pOMOFQWE.mjs} +2 -2
- package/dist/KyselyFactory.cjs +2 -2
- package/dist/KyselyFactory.mjs +3 -3
- package/dist/{ObjectionFactory-CFrtXe7i.mjs → ObjectionFactory-ChuX8sZN.mjs} +1 -1
- package/dist/ObjectionFactory.mjs +2 -2
- package/dist/{PostgresKyselyMigrator-CbtiZgfI.mjs → PostgresKyselyMigrator-D8fm35-s.mjs} +1 -1
- package/dist/{PostgresKyselyMigrator-Cxf2Dp9y.cjs → PostgresKyselyMigrator-JTY2LfwD.cjs} +2 -2
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-eqyAFSf-.cjs → PostgresMigrator-Bz-tnjB6.cjs} +1 -1
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{VitestKyselyTransactionIsolator-DXjWQtDN.mjs → VitestKyselyTransactionIsolator-D-qpeVKO.mjs} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-Dh2AgJDd.cjs → VitestKyselyTransactionIsolator-jF6Ohyu_.cjs} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -3
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -3
- package/dist/{VitestTransactionIsolator-zK5NJ7DQ.cjs → VitestTransactionIsolator-BK9UsrKt.cjs} +4 -2
- package/dist/{VitestTransactionIsolator-pLwsDo_A.mjs → VitestTransactionIsolator-e-R3p_X8.mjs} +4 -3
- package/dist/VitestTransactionIsolator.cjs +1 -2
- package/dist/VitestTransactionIsolator.mjs +1 -2
- package/dist/__tests__/Factory.spec.cjs +42 -42
- package/dist/__tests__/Factory.spec.mjs +23 -24
- package/dist/__tests__/KyselyFactory.spec.cjs +80 -80
- package/dist/__tests__/KyselyFactory.spec.mjs +74 -74
- package/dist/__tests__/ObjectionFactory.spec.cjs +80 -81
- package/dist/__tests__/ObjectionFactory.spec.mjs +52 -53
- package/dist/__tests__/PostgresMigrator.spec.cjs +59 -60
- package/dist/__tests__/PostgresMigrator.spec.mjs +31 -32
- package/dist/__tests__/faker.spec.cjs +60 -60
- package/dist/__tests__/faker.spec.mjs +35 -36
- package/dist/__tests__/integration.spec.cjs +44 -41
- package/dist/__tests__/integration.spec.mjs +45 -43
- package/dist/{chunk-DWy1uDak.cjs → chunk-CUT6urMc.cjs} +0 -9
- package/dist/example.cjs +2 -2
- package/dist/example.mjs +3 -3
- package/dist/{faker-h6CkRloU.cjs → faker-caz-8zt8.cjs} +1 -1
- package/dist/faker.cjs +1 -1
- package/dist/faker.mjs +1 -1
- package/dist/{helpers-C2NH7xcz.cjs → helpers-B2CfbaTC.cjs} +1 -1
- package/dist/helpers-DN4sJO4i.mjs +13 -0
- package/dist/helpers-DOtYCEvZ.cjs +19 -0
- package/dist/helpers.cjs +2 -6
- package/dist/helpers.mjs +2 -5
- package/dist/kysely-C1-aHdnU.mjs +11 -0
- package/dist/kysely-DL3C2eM4.cjs +16 -0
- package/dist/kysely.cjs +8 -15
- package/dist/kysely.mjs +8 -15
- package/dist/objection.mjs +2 -2
- package/package.json +2 -1
- package/src/VitestTransactionIsolator.ts +4 -2
- package/src/__tests__/KyselyFactory.spec.ts +4 -6
- package/src/__tests__/integration.spec.ts +8 -3
- package/src/helpers.ts +1 -18
- package/src/kysely.ts +3 -1
- package/dist/dist-BM2KvLG1.mjs +0 -5618
- package/dist/dist-DE3gAxQI.cjs +0 -5736
- package/dist/helpers-BnARb5Ap.mjs +0 -19
- package/dist/helpers-C_RZk04R.cjs +0 -31
- package/dist/magic-string.es-C6yzoryu.mjs +0 -1014
- package/dist/magic-string.es-jdtJrR0A.cjs +0 -1015
- package/dist/vi.bdSIJ99Y-BgRxGeO2.mjs +0 -9382
- package/dist/vi.bdSIJ99Y-CFuzUeY6.cjs +0 -9393
- /package/dist/{Factory-D52Lsc6Z.mjs → Factory-DlzMkMzb.mjs} +0 -0
- /package/dist/{PostgresMigrator-DqeuPy-e.mjs → PostgresMigrator-CEoRKTdq.mjs} +0 -0
- /package/dist/{faker-cGCFcrj2.mjs → faker-BwaXA_RF.mjs} +0 -0
- /package/dist/{helpers-CukcFAU9.mjs → helpers-Rf5F71r9.mjs} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { globalExpect } from "../vi.bdSIJ99Y-BgRxGeO2.mjs";
|
|
1
|
+
import { faker } from "../faker-BwaXA_RF.mjs";
|
|
2
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
4
3
|
|
|
5
4
|
//#region src/__tests__/faker.spec.ts
|
|
6
5
|
describe("faker", () => {
|
|
@@ -9,26 +8,26 @@ describe("faker", () => {
|
|
|
9
8
|
faker.resetAllSequences();
|
|
10
9
|
});
|
|
11
10
|
it("should start from 1 for a new sequence", () => {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
expect(faker.sequence()).toBe(1);
|
|
12
|
+
expect(faker.sequence("custom")).toBe(1);
|
|
14
13
|
});
|
|
15
14
|
it("should increment on each call", () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
expect(faker.sequence()).toBe(1);
|
|
16
|
+
expect(faker.sequence()).toBe(2);
|
|
17
|
+
expect(faker.sequence()).toBe(3);
|
|
19
18
|
});
|
|
20
19
|
it("should maintain separate counters for different names", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
expect(faker.sequence("users")).toBe(1);
|
|
21
|
+
expect(faker.sequence("posts")).toBe(1);
|
|
22
|
+
expect(faker.sequence("users")).toBe(2);
|
|
23
|
+
expect(faker.sequence("posts")).toBe(2);
|
|
24
|
+
expect(faker.sequence("users")).toBe(3);
|
|
25
|
+
expect(faker.sequence("posts")).toBe(3);
|
|
27
26
|
});
|
|
28
27
|
it("should handle concurrent-like sequential calls", () => {
|
|
29
28
|
const results = [];
|
|
30
29
|
for (let i = 0; i < 100; i++) results.push(faker.sequence("concurrent"));
|
|
31
|
-
|
|
30
|
+
expect(results).toEqual(Array.from({ length: 100 }, (_, i) => i + 1));
|
|
32
31
|
});
|
|
33
32
|
});
|
|
34
33
|
describe("resetSequence", () => {
|
|
@@ -38,26 +37,26 @@ describe("faker", () => {
|
|
|
38
37
|
it("should reset a specific sequence to 0", () => {
|
|
39
38
|
faker.sequence("test");
|
|
40
39
|
faker.sequence("test");
|
|
41
|
-
|
|
40
|
+
expect(faker.sequence("test")).toBe(3);
|
|
42
41
|
faker.resetSequence("test");
|
|
43
|
-
|
|
42
|
+
expect(faker.sequence("test")).toBe(1);
|
|
44
43
|
});
|
|
45
44
|
it("should reset a specific sequence to a custom value", () => {
|
|
46
45
|
faker.sequence("test");
|
|
47
46
|
faker.resetSequence("test", 10);
|
|
48
|
-
|
|
47
|
+
expect(faker.sequence("test")).toBe(11);
|
|
49
48
|
});
|
|
50
49
|
it("should create a new sequence if it does not exist", () => {
|
|
51
50
|
faker.resetSequence("new", 5);
|
|
52
|
-
|
|
51
|
+
expect(faker.sequence("new")).toBe(6);
|
|
53
52
|
});
|
|
54
53
|
it("should not affect other sequences", () => {
|
|
55
54
|
faker.sequence("test1");
|
|
56
55
|
faker.sequence("test1");
|
|
57
56
|
faker.sequence("test2");
|
|
58
57
|
faker.resetSequence("test1");
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
expect(faker.sequence("test1")).toBe(1);
|
|
59
|
+
expect(faker.sequence("test2")).toBe(2);
|
|
61
60
|
});
|
|
62
61
|
});
|
|
63
62
|
describe("resetAllSequences", () => {
|
|
@@ -68,9 +67,9 @@ describe("faker", () => {
|
|
|
68
67
|
faker.sequence("test2");
|
|
69
68
|
faker.sequence("test2");
|
|
70
69
|
faker.resetAllSequences();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
expect(faker.sequence("test1")).toBe(1);
|
|
71
|
+
expect(faker.sequence("test2")).toBe(1);
|
|
72
|
+
expect(faker.sequence()).toBe(1);
|
|
74
73
|
});
|
|
75
74
|
});
|
|
76
75
|
describe("identifier", () => {
|
|
@@ -80,34 +79,34 @@ describe("faker", () => {
|
|
|
80
79
|
it("should include sequence number in identifier", () => {
|
|
81
80
|
const id1 = faker.identifier();
|
|
82
81
|
const id2 = faker.identifier();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
expect(id1).not.toBe(id2);
|
|
83
|
+
expect(id1).toMatch(/1$/);
|
|
84
|
+
expect(id2).toMatch(/2$/);
|
|
86
85
|
});
|
|
87
86
|
it("should use custom suffix when provided", () => {
|
|
88
87
|
const id = faker.identifier("customSuffix");
|
|
89
|
-
|
|
88
|
+
expect(id).toMatch(/\.customSuffix$/);
|
|
90
89
|
});
|
|
91
90
|
});
|
|
92
91
|
describe("timestamps", () => {
|
|
93
92
|
it("should return createdAt and updatedAt dates", () => {
|
|
94
93
|
const { createdAt, updatedAt } = faker.timestamps();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
expect(createdAt).toBeInstanceOf(Date);
|
|
95
|
+
expect(updatedAt).toBeInstanceOf(Date);
|
|
96
|
+
expect(createdAt.getTime()).toBeLessThanOrEqual(updatedAt.getTime());
|
|
97
|
+
expect(updatedAt.getTime()).toBeLessThanOrEqual((/* @__PURE__ */ new Date()).getTime());
|
|
99
98
|
});
|
|
100
99
|
it("should have milliseconds set to 0", () => {
|
|
101
100
|
const { createdAt, updatedAt } = faker.timestamps();
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
expect(createdAt.getMilliseconds()).toBe(0);
|
|
102
|
+
expect(updatedAt.getMilliseconds()).toBe(0);
|
|
104
103
|
});
|
|
105
104
|
});
|
|
106
105
|
describe("price", () => {
|
|
107
106
|
it("should return a number", () => {
|
|
108
107
|
const result = faker.price();
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
expect(typeof result).toBe("number");
|
|
109
|
+
expect(result).toBeGreaterThan(0);
|
|
111
110
|
});
|
|
112
111
|
});
|
|
113
112
|
});
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
1
2
|
require('../Factory-DREHoms3.cjs');
|
|
2
|
-
require('../faker-
|
|
3
|
-
const require_KyselyFactory = require('../KyselyFactory-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require('../VitestTransactionIsolator-
|
|
7
|
-
require('../VitestKyselyTransactionIsolator-
|
|
8
|
-
const require_helpers = require('../helpers-
|
|
9
|
-
const
|
|
3
|
+
require('../faker-caz-8zt8.cjs');
|
|
4
|
+
const require_KyselyFactory = require('../KyselyFactory-BX7Kv2uP.cjs');
|
|
5
|
+
require('../PostgresMigrator-Bz-tnjB6.cjs');
|
|
6
|
+
require('../PostgresKyselyMigrator-JTY2LfwD.cjs');
|
|
7
|
+
require('../VitestTransactionIsolator-BK9UsrKt.cjs');
|
|
8
|
+
require('../VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
|
|
9
|
+
const require_helpers = require('../helpers-DOtYCEvZ.cjs');
|
|
10
|
+
const require_kysely = require('../kysely-DL3C2eM4.cjs');
|
|
11
|
+
const require_helpers$1 = require('../helpers-B2CfbaTC.cjs');
|
|
12
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
10
13
|
|
|
11
14
|
//#region src/__tests__/integration.spec.ts
|
|
12
15
|
const db = require_helpers.createKyselyDb(require_helpers$1.TEST_DATABASE_CONFIG);
|
|
13
|
-
const it =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const it = require_kysely.wrapVitestKyselyTransaction(vitest.it, db, require_helpers$1.createTestTables);
|
|
17
|
+
(0, vitest.describe)("Testkit Integration Tests", () => {
|
|
18
|
+
(0, vitest.beforeAll)(async () => {});
|
|
19
|
+
(0, vitest.describe)("Complex Factory Scenarios", () => {
|
|
17
20
|
it("should handle complex multi-table data creation", async ({ trx }) => {
|
|
18
21
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
19
22
|
name: "John Doe",
|
|
@@ -81,21 +84,21 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
81
84
|
content: `Comment ${idx + 1} on first post`,
|
|
82
85
|
postId: posts[0].id
|
|
83
86
|
}));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
(0, vitest.expect)(author.name).toBe("Jane Author");
|
|
88
|
+
(0, vitest.expect)(author.role).toBe("admin");
|
|
89
|
+
(0, vitest.expect)(posts).toHaveLength(3);
|
|
90
|
+
(0, vitest.expect)(posts[0].title).toBe("Post 1");
|
|
91
|
+
(0, vitest.expect)(posts[0].published).toBe(true);
|
|
92
|
+
(0, vitest.expect)(posts[2].published).toBe(false);
|
|
93
|
+
(0, vitest.expect)(comments).toHaveLength(5);
|
|
91
94
|
comments.forEach((comment, idx) => {
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
(0, vitest.expect)(comment.content).toBe(`Comment ${idx + 1} on first post`);
|
|
96
|
+
(0, vitest.expect)(comment.postId).toBe(posts[0].id);
|
|
94
97
|
});
|
|
95
98
|
const authorPosts = await trx.selectFrom("posts").selectAll().where("userId", "=", author.id).execute();
|
|
96
|
-
|
|
99
|
+
(0, vitest.expect)(authorPosts).toHaveLength(3);
|
|
97
100
|
const firstPostComments = await trx.selectFrom("comments").selectAll().where("postId", "=", posts[0].id).execute();
|
|
98
|
-
|
|
101
|
+
(0, vitest.expect)(firstPostComments).toHaveLength(5);
|
|
99
102
|
});
|
|
100
103
|
it("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
101
104
|
const c = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
@@ -179,19 +182,19 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
179
182
|
};
|
|
180
183
|
const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx);
|
|
181
184
|
const blogData = await factory.seed("blogWithAdminAndPosts", { postCount: 5 });
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
(0, vitest.expect)(blogData.admin.name).toBe("Blog Admin");
|
|
186
|
+
(0, vitest.expect)(blogData.admin.role).toBe("admin");
|
|
187
|
+
(0, vitest.expect)(blogData.posts).toHaveLength(5);
|
|
188
|
+
(0, vitest.expect)(blogData.summary.totalPosts).toBe(5);
|
|
186
189
|
const userData = await factory.seed("usersWithPosts", {
|
|
187
190
|
userCount: 3,
|
|
188
191
|
postsPerUser: 4
|
|
189
192
|
});
|
|
190
|
-
|
|
193
|
+
(0, vitest.expect)(userData).toHaveLength(3);
|
|
191
194
|
const totalUsers = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
192
195
|
const totalPosts = await trx.selectFrom("posts").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
(0, vitest.expect)(Number(totalUsers?.count)).toBe(4);
|
|
197
|
+
(0, vitest.expect)(Number(totalPosts?.count)).toBe(17);
|
|
195
198
|
});
|
|
196
199
|
it("should handle transaction isolation properly", async ({ trx }) => {
|
|
197
200
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs, factory, db$1, faker) => ({
|
|
@@ -208,11 +211,11 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
208
211
|
email: "transaction@test.com"
|
|
209
212
|
});
|
|
210
213
|
const userInTrx = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
211
|
-
|
|
212
|
-
|
|
214
|
+
(0, vitest.expect)(userInTrx).toBeDefined();
|
|
215
|
+
(0, vitest.expect)(userInTrx?.name).toBe("Transaction User");
|
|
213
216
|
});
|
|
214
217
|
});
|
|
215
|
-
|
|
218
|
+
(0, vitest.describe)("Performance and Edge Cases", () => {
|
|
216
219
|
it("should handle creating many records efficiently", async ({ trx }) => {
|
|
217
220
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => ({
|
|
218
221
|
name: `User ${Math.random()}`,
|
|
@@ -227,11 +230,11 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
227
230
|
const users = await factory.insertMany(100, "user");
|
|
228
231
|
const endTime = Date.now();
|
|
229
232
|
const duration = endTime - startTime;
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
(0, vitest.expect)(users).toHaveLength(100);
|
|
234
|
+
(0, vitest.expect)(duration).toBeLessThan(5e3);
|
|
232
235
|
const emails = users.map((u) => u.email);
|
|
233
236
|
const uniqueEmails = new Set(emails);
|
|
234
|
-
|
|
237
|
+
(0, vitest.expect)(uniqueEmails.size).toBe(100);
|
|
235
238
|
});
|
|
236
239
|
it("should handle complex attribute generation", async ({ trx }) => {
|
|
237
240
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => {
|
|
@@ -262,16 +265,16 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
262
265
|
};
|
|
263
266
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
264
267
|
const posts = await factory.insertMany(10, "post", (i) => ({ published: i % 2 === 0 }));
|
|
265
|
-
|
|
268
|
+
(0, vitest.expect)(posts).toHaveLength(10);
|
|
266
269
|
const users = await trx.selectFrom("users").selectAll().execute();
|
|
267
270
|
users.forEach((user) => {
|
|
268
|
-
|
|
269
|
-
|
|
271
|
+
(0, vitest.expect)(user.email).toBe(user.email.toLowerCase());
|
|
272
|
+
(0, vitest.expect)(user.name).not.toMatch(/^\s|\s$/);
|
|
270
273
|
});
|
|
271
274
|
const publishedPosts = posts.filter((p) => p.published);
|
|
272
275
|
const unpublishedPosts = posts.filter((p) => !p.published);
|
|
273
|
-
|
|
274
|
-
|
|
276
|
+
(0, vitest.expect)(publishedPosts).toHaveLength(5);
|
|
277
|
+
(0, vitest.expect)(unpublishedPosts).toHaveLength(5);
|
|
275
278
|
});
|
|
276
279
|
});
|
|
277
280
|
});
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import "../VitestTransactionIsolator-
|
|
7
|
-
import "../VitestKyselyTransactionIsolator-
|
|
8
|
-
import { createKyselyDb
|
|
9
|
-
import {
|
|
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-D8fm35-s.mjs";
|
|
6
|
+
import "../VitestTransactionIsolator-e-R3p_X8.mjs";
|
|
7
|
+
import "../VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
|
|
8
|
+
import { createKyselyDb } from "../helpers-DN4sJO4i.mjs";
|
|
9
|
+
import { wrapVitestKyselyTransaction } from "../kysely-C1-aHdnU.mjs";
|
|
10
|
+
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-Rf5F71r9.mjs";
|
|
11
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
|
10
12
|
|
|
11
13
|
//#region src/__tests__/integration.spec.ts
|
|
12
14
|
const db = createKyselyDb(TEST_DATABASE_CONFIG);
|
|
13
|
-
const it = wrapVitestKyselyTransaction(db, createTestTables);
|
|
15
|
+
const it$1 = wrapVitestKyselyTransaction(it, db, createTestTables);
|
|
14
16
|
describe("Testkit Integration Tests", () => {
|
|
15
17
|
beforeAll(async () => {});
|
|
16
18
|
describe("Complex Factory Scenarios", () => {
|
|
17
|
-
it("should handle complex multi-table data creation", async ({ trx }) => {
|
|
19
|
+
it$1("should handle complex multi-table data creation", async ({ trx }) => {
|
|
18
20
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
19
21
|
name: "John Doe",
|
|
20
22
|
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
@@ -81,23 +83,23 @@ describe("Testkit Integration Tests", () => {
|
|
|
81
83
|
content: `Comment ${idx + 1} on first post`,
|
|
82
84
|
postId: posts[0].id
|
|
83
85
|
}));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
expect(author.name).toBe("Jane Author");
|
|
87
|
+
expect(author.role).toBe("admin");
|
|
88
|
+
expect(posts).toHaveLength(3);
|
|
89
|
+
expect(posts[0].title).toBe("Post 1");
|
|
90
|
+
expect(posts[0].published).toBe(true);
|
|
91
|
+
expect(posts[2].published).toBe(false);
|
|
92
|
+
expect(comments).toHaveLength(5);
|
|
91
93
|
comments.forEach((comment, idx) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
expect(comment.content).toBe(`Comment ${idx + 1} on first post`);
|
|
95
|
+
expect(comment.postId).toBe(posts[0].id);
|
|
94
96
|
});
|
|
95
97
|
const authorPosts = await trx.selectFrom("posts").selectAll().where("userId", "=", author.id).execute();
|
|
96
|
-
|
|
98
|
+
expect(authorPosts).toHaveLength(3);
|
|
97
99
|
const firstPostComments = await trx.selectFrom("comments").selectAll().where("postId", "=", posts[0].id).execute();
|
|
98
|
-
|
|
100
|
+
expect(firstPostComments).toHaveLength(5);
|
|
99
101
|
});
|
|
100
|
-
it("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
102
|
+
it$1("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
101
103
|
const c = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
102
104
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
103
105
|
name: "Default User",
|
|
@@ -179,21 +181,21 @@ describe("Testkit Integration Tests", () => {
|
|
|
179
181
|
};
|
|
180
182
|
const factory = new KyselyFactory(builders, seeds, trx);
|
|
181
183
|
const blogData = await factory.seed("blogWithAdminAndPosts", { postCount: 5 });
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
expect(blogData.admin.name).toBe("Blog Admin");
|
|
185
|
+
expect(blogData.admin.role).toBe("admin");
|
|
186
|
+
expect(blogData.posts).toHaveLength(5);
|
|
187
|
+
expect(blogData.summary.totalPosts).toBe(5);
|
|
186
188
|
const userData = await factory.seed("usersWithPosts", {
|
|
187
189
|
userCount: 3,
|
|
188
190
|
postsPerUser: 4
|
|
189
191
|
});
|
|
190
|
-
|
|
192
|
+
expect(userData).toHaveLength(3);
|
|
191
193
|
const totalUsers = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
192
194
|
const totalPosts = await trx.selectFrom("posts").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
expect(Number(totalUsers?.count)).toBe(4);
|
|
196
|
+
expect(Number(totalPosts?.count)).toBe(17);
|
|
195
197
|
});
|
|
196
|
-
it("should handle transaction isolation properly", async ({ trx }) => {
|
|
198
|
+
it$1("should handle transaction isolation properly", async ({ trx }) => {
|
|
197
199
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory, db$1, faker) => ({
|
|
198
200
|
name: "Test User",
|
|
199
201
|
email: faker.internet.email(),
|
|
@@ -208,12 +210,12 @@ describe("Testkit Integration Tests", () => {
|
|
|
208
210
|
email: "transaction@test.com"
|
|
209
211
|
});
|
|
210
212
|
const userInTrx = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
expect(userInTrx).toBeDefined();
|
|
214
|
+
expect(userInTrx?.name).toBe("Transaction User");
|
|
213
215
|
});
|
|
214
216
|
});
|
|
215
217
|
describe("Performance and Edge Cases", () => {
|
|
216
|
-
it("should handle creating many records efficiently", async ({ trx }) => {
|
|
218
|
+
it$1("should handle creating many records efficiently", async ({ trx }) => {
|
|
217
219
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => ({
|
|
218
220
|
name: `User ${Math.random()}`,
|
|
219
221
|
email: faker.internet.email().toLowerCase(),
|
|
@@ -227,13 +229,13 @@ describe("Testkit Integration Tests", () => {
|
|
|
227
229
|
const users = await factory.insertMany(100, "user");
|
|
228
230
|
const endTime = Date.now();
|
|
229
231
|
const duration = endTime - startTime;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
expect(users).toHaveLength(100);
|
|
233
|
+
expect(duration).toBeLessThan(5e3);
|
|
232
234
|
const emails = users.map((u) => u.email);
|
|
233
235
|
const uniqueEmails = new Set(emails);
|
|
234
|
-
|
|
236
|
+
expect(uniqueEmails.size).toBe(100);
|
|
235
237
|
});
|
|
236
|
-
it("should handle complex attribute generation", async ({ trx }) => {
|
|
238
|
+
it$1("should handle complex attribute generation", async ({ trx }) => {
|
|
237
239
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => {
|
|
238
240
|
return {
|
|
239
241
|
name: `Generated User ${attrs.id}`,
|
|
@@ -262,16 +264,16 @@ describe("Testkit Integration Tests", () => {
|
|
|
262
264
|
};
|
|
263
265
|
const factory = new KyselyFactory(builders, {}, trx);
|
|
264
266
|
const posts = await factory.insertMany(10, "post", (i) => ({ published: i % 2 === 0 }));
|
|
265
|
-
|
|
267
|
+
expect(posts).toHaveLength(10);
|
|
266
268
|
const users = await trx.selectFrom("users").selectAll().execute();
|
|
267
269
|
users.forEach((user) => {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
+
expect(user.email).toBe(user.email.toLowerCase());
|
|
271
|
+
expect(user.name).not.toMatch(/^\s|\s$/);
|
|
270
272
|
});
|
|
271
273
|
const publishedPosts = posts.filter((p) => p.published);
|
|
272
274
|
const unpublishedPosts = posts.filter((p) => !p.published);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
+
expect(publishedPosts).toHaveLength(5);
|
|
276
|
+
expect(unpublishedPosts).toHaveLength(5);
|
|
275
277
|
});
|
|
276
278
|
});
|
|
277
279
|
});
|
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
8
|
var __copyProps = (to, from, except, desc) => {
|
|
12
9
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
10
|
key = keys[i];
|
|
@@ -25,12 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
22
|
|
|
26
23
|
//#endregion
|
|
27
24
|
|
|
28
|
-
Object.defineProperty(exports, '__commonJS', {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function () {
|
|
31
|
-
return __commonJS;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
25
|
Object.defineProperty(exports, '__toESM', {
|
|
35
26
|
enumerable: true,
|
|
36
27
|
get: function () {
|
package/dist/example.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require('./Factory-DREHoms3.cjs');
|
|
2
|
-
require('./faker-
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
2
|
+
require('./faker-caz-8zt8.cjs');
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-BX7Kv2uP.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/example.ts
|
|
6
6
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder({
|
package/dist/example.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./Factory-
|
|
2
|
-
import "./faker-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./Factory-DlzMkMzb.mjs";
|
|
2
|
+
import "./faker-BwaXA_RF.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-pOMOFQWE.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/example.ts
|
|
6
6
|
const userBuilder = KyselyFactory.createBuilder({
|
package/dist/faker.cjs
CHANGED
package/dist/faker.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
1
|
+
import { faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-BwaXA_RF.mjs";
|
|
2
2
|
|
|
3
3
|
export { faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
2
|
const kysely = require_chunk.__toESM(require("kysely"));
|
|
3
3
|
const pg = require_chunk.__toESM(require("pg"));
|
|
4
4
|
const knex = require_chunk.__toESM(require("knex"));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
|
|
2
|
+
import pg from "pg";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers.ts
|
|
5
|
+
function createKyselyDb(config) {
|
|
6
|
+
return new Kysely({
|
|
7
|
+
dialect: new PostgresDialect({ pool: new pg.Pool(config) }),
|
|
8
|
+
plugins: [new CamelCasePlugin()]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createKyselyDb };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const kysely = require_chunk.__toESM(require("kysely"));
|
|
3
|
+
const pg = require_chunk.__toESM(require("pg"));
|
|
4
|
+
|
|
5
|
+
//#region src/helpers.ts
|
|
6
|
+
function createKyselyDb(config) {
|
|
7
|
+
return new kysely.Kysely({
|
|
8
|
+
dialect: new kysely.PostgresDialect({ pool: new pg.default.Pool(config) }),
|
|
9
|
+
plugins: [new kysely.CamelCasePlugin()]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
Object.defineProperty(exports, 'createKyselyDb', {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return createKyselyDb;
|
|
18
|
+
}
|
|
19
|
+
});
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
require('./
|
|
2
|
-
require('./VitestTransactionIsolator-zK5NJ7DQ.cjs');
|
|
3
|
-
require('./VitestKyselyTransactionIsolator-Dh2AgJDd.cjs');
|
|
4
|
-
const require_helpers = require('./helpers-C_RZk04R.cjs');
|
|
1
|
+
const require_helpers = require('./helpers-DOtYCEvZ.cjs');
|
|
5
2
|
|
|
6
|
-
exports.createKyselyDb = require_helpers.createKyselyDb;
|
|
7
|
-
exports.wrapVitestKyselyTransaction = require_helpers.wrapVitestKyselyTransaction;
|
|
3
|
+
exports.createKyselyDb = require_helpers.createKyselyDb;
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./VitestTransactionIsolator-pLwsDo_A.mjs";
|
|
3
|
-
import "./VitestKyselyTransactionIsolator-DXjWQtDN.mjs";
|
|
4
|
-
import { createKyselyDb, wrapVitestKyselyTransaction } from "./helpers-BnARb5Ap.mjs";
|
|
1
|
+
import { createKyselyDb } from "./helpers-DN4sJO4i.mjs";
|
|
5
2
|
|
|
6
|
-
export { createKyselyDb
|
|
3
|
+
export { createKyselyDb };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IsolationLevel } from "./VitestTransactionIsolator-e-R3p_X8.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-D-qpeVKO.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/kysely.ts
|
|
5
|
+
function wrapVitestKyselyTransaction(api, db, setup, level = IsolationLevel.REPEATABLE_READ) {
|
|
6
|
+
const wrapper = new VitestKyselyTransactionIsolator(api);
|
|
7
|
+
return wrapper.wrapVitestWithTransaction(db, setup, level);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { wrapVitestKyselyTransaction };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BK9UsrKt.cjs');
|
|
2
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/kysely.ts
|
|
5
|
+
function wrapVitestKyselyTransaction(api, db, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
6
|
+
const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
|
|
7
|
+
return wrapper.wrapVitestWithTransaction(db, setup, level);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
Object.defineProperty(exports, 'wrapVitestKyselyTransaction', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return wrapVitestKyselyTransaction;
|
|
15
|
+
}
|
|
16
|
+
});
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
require('./Factory-DREHoms3.cjs');
|
|
2
|
-
require('./faker-
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
4
|
-
require('./PostgresMigrator-
|
|
5
|
-
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-
|
|
6
|
-
require('./
|
|
7
|
-
|
|
8
|
-
const
|
|
2
|
+
require('./faker-caz-8zt8.cjs');
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-BX7Kv2uP.cjs');
|
|
4
|
+
require('./PostgresMigrator-Bz-tnjB6.cjs');
|
|
5
|
+
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-JTY2LfwD.cjs');
|
|
6
|
+
require('./VitestTransactionIsolator-BK9UsrKt.cjs');
|
|
7
|
+
require('./VitestKyselyTransactionIsolator-jF6Ohyu_.cjs');
|
|
8
|
+
const require_kysely = require('./kysely-DL3C2eM4.cjs');
|
|
9
9
|
|
|
10
|
-
//#region src/kysely.ts
|
|
11
|
-
function wrapVitestKyselyTransaction(db, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
12
|
-
const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator();
|
|
13
|
-
return wrapper.wrapVitestWithTransaction(db, setup, level);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
10
|
exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
|
|
18
11
|
exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
|
|
19
|
-
exports.wrapVitestKyselyTransaction = wrapVitestKyselyTransaction;
|
|
12
|
+
exports.wrapVitestKyselyTransaction = require_kysely.wrapVitestKyselyTransaction;
|