@geekmidas/testkit 0.0.4 → 0.0.5
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-BS3R-V0I.mjs} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-Dh2AgJDd.cjs → VitestKyselyTransactionIsolator-DWSTKIe3.cjs} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -3
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -3
- package/dist/{VitestTransactionIsolator-pLwsDo_A.mjs → VitestTransactionIsolator-BjVXqFs6.mjs} +1 -1
- package/dist/{VitestTransactionIsolator-zK5NJ7DQ.cjs → VitestTransactionIsolator-Bx2c4OzK.cjs} +3 -2
- 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 +46 -47
- package/dist/__tests__/KyselyFactory.spec.mjs +40 -41
- 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 +40 -40
- package/dist/__tests__/integration.spec.mjs +42 -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-C_RZk04R.cjs → helpers-B9Jdk_C7.cjs} +3 -3
- package/dist/{helpers-C2NH7xcz.cjs → helpers-DKEBHABj.cjs} +1 -1
- package/dist/{helpers-BnARb5Ap.mjs → helpers-DOiGIkaU.mjs} +2 -2
- package/dist/helpers.cjs +3 -4
- package/dist/helpers.mjs +3 -4
- package/dist/kysely.cjs +6 -7
- package/dist/kysely.mjs +7 -8
- package/dist/objection.mjs +2 -2
- package/package.json +2 -1
- package/dist/dist-BM2KvLG1.mjs +0 -5618
- package/dist/dist-DE3gAxQI.cjs +0 -5736
- 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-BfuX-cjN.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,19 @@
|
|
|
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('../
|
|
7
|
-
require('../
|
|
8
|
-
const
|
|
9
|
-
const require_helpers$1 = require('../helpers-C2NH7xcz.cjs');
|
|
3
|
+
require('../faker-caz-8zt8.cjs');
|
|
4
|
+
const require_KyselyFactory = require('../KyselyFactory-BX7Kv2uP.cjs');
|
|
5
|
+
require('../VitestTransactionIsolator-Bx2c4OzK.cjs');
|
|
6
|
+
require('../VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
|
|
7
|
+
const require_helpers = require('../helpers-B9Jdk_C7.cjs');
|
|
8
|
+
const require_helpers$1 = require('../helpers-DKEBHABj.cjs');
|
|
9
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
10
10
|
|
|
11
11
|
//#region src/__tests__/integration.spec.ts
|
|
12
12
|
const db = require_helpers.createKyselyDb(require_helpers$1.TEST_DATABASE_CONFIG);
|
|
13
13
|
const it = require_helpers.wrapVitestKyselyTransaction(db, require_helpers$1.createTestTables);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
(0, vitest.describe)("Testkit Integration Tests", () => {
|
|
15
|
+
(0, vitest.beforeAll)(async () => {});
|
|
16
|
+
(0, vitest.describe)("Complex Factory Scenarios", () => {
|
|
17
17
|
it("should handle complex multi-table data creation", async ({ trx }) => {
|
|
18
18
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
19
19
|
name: "John Doe",
|
|
@@ -81,21 +81,21 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
81
81
|
content: `Comment ${idx + 1} on first post`,
|
|
82
82
|
postId: posts[0].id
|
|
83
83
|
}));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
(0, vitest.expect)(author.name).toBe("Jane Author");
|
|
85
|
+
(0, vitest.expect)(author.role).toBe("admin");
|
|
86
|
+
(0, vitest.expect)(posts).toHaveLength(3);
|
|
87
|
+
(0, vitest.expect)(posts[0].title).toBe("Post 1");
|
|
88
|
+
(0, vitest.expect)(posts[0].published).toBe(true);
|
|
89
|
+
(0, vitest.expect)(posts[2].published).toBe(false);
|
|
90
|
+
(0, vitest.expect)(comments).toHaveLength(5);
|
|
91
91
|
comments.forEach((comment, idx) => {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
(0, vitest.expect)(comment.content).toBe(`Comment ${idx + 1} on first post`);
|
|
93
|
+
(0, vitest.expect)(comment.postId).toBe(posts[0].id);
|
|
94
94
|
});
|
|
95
95
|
const authorPosts = await trx.selectFrom("posts").selectAll().where("userId", "=", author.id).execute();
|
|
96
|
-
|
|
96
|
+
(0, vitest.expect)(authorPosts).toHaveLength(3);
|
|
97
97
|
const firstPostComments = await trx.selectFrom("comments").selectAll().where("postId", "=", posts[0].id).execute();
|
|
98
|
-
|
|
98
|
+
(0, vitest.expect)(firstPostComments).toHaveLength(5);
|
|
99
99
|
});
|
|
100
100
|
it("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
101
101
|
const c = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
@@ -179,19 +179,19 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
179
179
|
};
|
|
180
180
|
const factory = new require_KyselyFactory.KyselyFactory(builders, seeds, trx);
|
|
181
181
|
const blogData = await factory.seed("blogWithAdminAndPosts", { postCount: 5 });
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
(0, vitest.expect)(blogData.admin.name).toBe("Blog Admin");
|
|
183
|
+
(0, vitest.expect)(blogData.admin.role).toBe("admin");
|
|
184
|
+
(0, vitest.expect)(blogData.posts).toHaveLength(5);
|
|
185
|
+
(0, vitest.expect)(blogData.summary.totalPosts).toBe(5);
|
|
186
186
|
const userData = await factory.seed("usersWithPosts", {
|
|
187
187
|
userCount: 3,
|
|
188
188
|
postsPerUser: 4
|
|
189
189
|
});
|
|
190
|
-
|
|
190
|
+
(0, vitest.expect)(userData).toHaveLength(3);
|
|
191
191
|
const totalUsers = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
192
192
|
const totalPosts = await trx.selectFrom("posts").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
(0, vitest.expect)(Number(totalUsers?.count)).toBe(4);
|
|
194
|
+
(0, vitest.expect)(Number(totalPosts?.count)).toBe(17);
|
|
195
195
|
});
|
|
196
196
|
it("should handle transaction isolation properly", async ({ trx }) => {
|
|
197
197
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs, factory, db$1, faker) => ({
|
|
@@ -208,11 +208,11 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
208
208
|
email: "transaction@test.com"
|
|
209
209
|
});
|
|
210
210
|
const userInTrx = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
(0, vitest.expect)(userInTrx).toBeDefined();
|
|
212
|
+
(0, vitest.expect)(userInTrx?.name).toBe("Transaction User");
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
|
-
|
|
215
|
+
(0, vitest.describe)("Performance and Edge Cases", () => {
|
|
216
216
|
it("should handle creating many records efficiently", async ({ trx }) => {
|
|
217
217
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => ({
|
|
218
218
|
name: `User ${Math.random()}`,
|
|
@@ -227,11 +227,11 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
227
227
|
const users = await factory.insertMany(100, "user");
|
|
228
228
|
const endTime = Date.now();
|
|
229
229
|
const duration = endTime - startTime;
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
(0, vitest.expect)(users).toHaveLength(100);
|
|
231
|
+
(0, vitest.expect)(duration).toBeLessThan(5e3);
|
|
232
232
|
const emails = users.map((u) => u.email);
|
|
233
233
|
const uniqueEmails = new Set(emails);
|
|
234
|
-
|
|
234
|
+
(0, vitest.expect)(uniqueEmails.size).toBe(100);
|
|
235
235
|
});
|
|
236
236
|
it("should handle complex attribute generation", async ({ trx }) => {
|
|
237
237
|
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => {
|
|
@@ -262,16 +262,16 @@ require_dist.describe("Testkit Integration Tests", () => {
|
|
|
262
262
|
};
|
|
263
263
|
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, trx);
|
|
264
264
|
const posts = await factory.insertMany(10, "post", (i) => ({ published: i % 2 === 0 }));
|
|
265
|
-
|
|
265
|
+
(0, vitest.expect)(posts).toHaveLength(10);
|
|
266
266
|
const users = await trx.selectFrom("users").selectAll().execute();
|
|
267
267
|
users.forEach((user) => {
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
(0, vitest.expect)(user.email).toBe(user.email.toLowerCase());
|
|
269
|
+
(0, vitest.expect)(user.name).not.toMatch(/^\s|\s$/);
|
|
270
270
|
});
|
|
271
271
|
const publishedPosts = posts.filter((p) => p.published);
|
|
272
272
|
const unpublishedPosts = posts.filter((p) => !p.published);
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
(0, vitest.expect)(publishedPosts).toHaveLength(5);
|
|
274
|
+
(0, vitest.expect)(unpublishedPosts).toHaveLength(5);
|
|
275
275
|
});
|
|
276
276
|
});
|
|
277
277
|
});
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../
|
|
3
|
-
import "../
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import {
|
|
9
|
-
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-CukcFAU9.mjs";
|
|
1
|
+
import "../Factory-DlzMkMzb.mjs";
|
|
2
|
+
import "../faker-BwaXA_RF.mjs";
|
|
3
|
+
import { KyselyFactory } from "../KyselyFactory-pOMOFQWE.mjs";
|
|
4
|
+
import "../VitestTransactionIsolator-BjVXqFs6.mjs";
|
|
5
|
+
import "../VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
|
|
6
|
+
import { createKyselyDb, wrapVitestKyselyTransaction } from "../helpers-DOiGIkaU.mjs";
|
|
7
|
+
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-BfuX-cjN.mjs";
|
|
8
|
+
import { beforeAll, describe, expect } from "vitest";
|
|
10
9
|
|
|
11
10
|
//#region src/__tests__/integration.spec.ts
|
|
12
11
|
const db = createKyselyDb(TEST_DATABASE_CONFIG);
|
|
13
|
-
const it = wrapVitestKyselyTransaction(db, createTestTables);
|
|
12
|
+
const it$1 = wrapVitestKyselyTransaction(db, createTestTables);
|
|
14
13
|
describe("Testkit Integration Tests", () => {
|
|
15
14
|
beforeAll(async () => {});
|
|
16
15
|
describe("Complex Factory Scenarios", () => {
|
|
17
|
-
it("should handle complex multi-table data creation", async ({ trx }) => {
|
|
16
|
+
it$1("should handle complex multi-table data creation", async ({ trx }) => {
|
|
18
17
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
19
18
|
name: "John Doe",
|
|
20
19
|
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
@@ -81,23 +80,23 @@ describe("Testkit Integration Tests", () => {
|
|
|
81
80
|
content: `Comment ${idx + 1} on first post`,
|
|
82
81
|
postId: posts[0].id
|
|
83
82
|
}));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
expect(author.name).toBe("Jane Author");
|
|
84
|
+
expect(author.role).toBe("admin");
|
|
85
|
+
expect(posts).toHaveLength(3);
|
|
86
|
+
expect(posts[0].title).toBe("Post 1");
|
|
87
|
+
expect(posts[0].published).toBe(true);
|
|
88
|
+
expect(posts[2].published).toBe(false);
|
|
89
|
+
expect(comments).toHaveLength(5);
|
|
91
90
|
comments.forEach((comment, idx) => {
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
expect(comment.content).toBe(`Comment ${idx + 1} on first post`);
|
|
92
|
+
expect(comment.postId).toBe(posts[0].id);
|
|
94
93
|
});
|
|
95
94
|
const authorPosts = await trx.selectFrom("posts").selectAll().where("userId", "=", author.id).execute();
|
|
96
|
-
|
|
95
|
+
expect(authorPosts).toHaveLength(3);
|
|
97
96
|
const firstPostComments = await trx.selectFrom("comments").selectAll().where("postId", "=", posts[0].id).execute();
|
|
98
|
-
|
|
97
|
+
expect(firstPostComments).toHaveLength(5);
|
|
99
98
|
});
|
|
100
|
-
it("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
99
|
+
it$1("should handle seeds for complex scenarios", async ({ trx }) => {
|
|
101
100
|
const c = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
102
101
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
103
102
|
name: "Default User",
|
|
@@ -179,21 +178,21 @@ describe("Testkit Integration Tests", () => {
|
|
|
179
178
|
};
|
|
180
179
|
const factory = new KyselyFactory(builders, seeds, trx);
|
|
181
180
|
const blogData = await factory.seed("blogWithAdminAndPosts", { postCount: 5 });
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
expect(blogData.admin.name).toBe("Blog Admin");
|
|
182
|
+
expect(blogData.admin.role).toBe("admin");
|
|
183
|
+
expect(blogData.posts).toHaveLength(5);
|
|
184
|
+
expect(blogData.summary.totalPosts).toBe(5);
|
|
186
185
|
const userData = await factory.seed("usersWithPosts", {
|
|
187
186
|
userCount: 3,
|
|
188
187
|
postsPerUser: 4
|
|
189
188
|
});
|
|
190
|
-
|
|
189
|
+
expect(userData).toHaveLength(3);
|
|
191
190
|
const totalUsers = await trx.selectFrom("users").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
192
191
|
const totalPosts = await trx.selectFrom("posts").select(trx.fn.count("id").as("count")).executeTakeFirst();
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
expect(Number(totalUsers?.count)).toBe(4);
|
|
193
|
+
expect(Number(totalPosts?.count)).toBe(17);
|
|
195
194
|
});
|
|
196
|
-
it("should handle transaction isolation properly", async ({ trx }) => {
|
|
195
|
+
it$1("should handle transaction isolation properly", async ({ trx }) => {
|
|
197
196
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory, db$1, faker) => ({
|
|
198
197
|
name: "Test User",
|
|
199
198
|
email: faker.internet.email(),
|
|
@@ -208,12 +207,12 @@ describe("Testkit Integration Tests", () => {
|
|
|
208
207
|
email: "transaction@test.com"
|
|
209
208
|
});
|
|
210
209
|
const userInTrx = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
expect(userInTrx).toBeDefined();
|
|
211
|
+
expect(userInTrx?.name).toBe("Transaction User");
|
|
213
212
|
});
|
|
214
213
|
});
|
|
215
214
|
describe("Performance and Edge Cases", () => {
|
|
216
|
-
it("should handle creating many records efficiently", async ({ trx }) => {
|
|
215
|
+
it$1("should handle creating many records efficiently", async ({ trx }) => {
|
|
217
216
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => ({
|
|
218
217
|
name: `User ${Math.random()}`,
|
|
219
218
|
email: faker.internet.email().toLowerCase(),
|
|
@@ -227,13 +226,13 @@ describe("Testkit Integration Tests", () => {
|
|
|
227
226
|
const users = await factory.insertMany(100, "user");
|
|
228
227
|
const endTime = Date.now();
|
|
229
228
|
const duration = endTime - startTime;
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
expect(users).toHaveLength(100);
|
|
230
|
+
expect(duration).toBeLessThan(5e3);
|
|
232
231
|
const emails = users.map((u) => u.email);
|
|
233
232
|
const uniqueEmails = new Set(emails);
|
|
234
|
-
|
|
233
|
+
expect(uniqueEmails.size).toBe(100);
|
|
235
234
|
});
|
|
236
|
-
it("should handle complex attribute generation", async ({ trx }) => {
|
|
235
|
+
it$1("should handle complex attribute generation", async ({ trx }) => {
|
|
237
236
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs, factory$1, db$1, faker) => {
|
|
238
237
|
return {
|
|
239
238
|
name: `Generated User ${attrs.id}`,
|
|
@@ -262,16 +261,16 @@ describe("Testkit Integration Tests", () => {
|
|
|
262
261
|
};
|
|
263
262
|
const factory = new KyselyFactory(builders, {}, trx);
|
|
264
263
|
const posts = await factory.insertMany(10, "post", (i) => ({ published: i % 2 === 0 }));
|
|
265
|
-
|
|
264
|
+
expect(posts).toHaveLength(10);
|
|
266
265
|
const users = await trx.selectFrom("users").selectAll().execute();
|
|
267
266
|
users.forEach((user) => {
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
expect(user.email).toBe(user.email.toLowerCase());
|
|
268
|
+
expect(user.name).not.toMatch(/^\s|\s$/);
|
|
270
269
|
});
|
|
271
270
|
const publishedPosts = posts.filter((p) => p.published);
|
|
272
271
|
const unpublishedPosts = posts.filter((p) => !p.published);
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
expect(publishedPosts).toHaveLength(5);
|
|
273
|
+
expect(unpublishedPosts).toHaveLength(5);
|
|
275
274
|
});
|
|
276
275
|
});
|
|
277
276
|
});
|
|
@@ -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,6 +1,6 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
2
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
3
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
|
|
3
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
|
|
4
4
|
const kysely = require_chunk.__toESM(require("kysely"));
|
|
5
5
|
const pg = require_chunk.__toESM(require("pg"));
|
|
6
6
|
|
|
@@ -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"));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import { IsolationLevel } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
|
|
3
3
|
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
|
|
4
4
|
import pg from "pg";
|
|
5
5
|
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require('./
|
|
2
|
-
require('./
|
|
3
|
-
require('./
|
|
4
|
-
const require_helpers = require('./helpers-C_RZk04R.cjs');
|
|
1
|
+
require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
|
|
2
|
+
require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
|
|
3
|
+
const require_helpers = require('./helpers-B9Jdk_C7.cjs');
|
|
5
4
|
|
|
6
5
|
exports.createKyselyDb = require_helpers.createKyselyDb;
|
|
7
6
|
exports.wrapVitestKyselyTransaction = require_helpers.wrapVitestKyselyTransaction;
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import { createKyselyDb, wrapVitestKyselyTransaction } from "./helpers-BnARb5Ap.mjs";
|
|
1
|
+
import "./VitestTransactionIsolator-BjVXqFs6.mjs";
|
|
2
|
+
import "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
|
|
3
|
+
import { createKyselyDb, wrapVitestKyselyTransaction } from "./helpers-DOiGIkaU.mjs";
|
|
5
4
|
|
|
6
5
|
export { createKyselyDb, wrapVitestKyselyTransaction };
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
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
|
-
const
|
|
8
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Dh2AgJDd.cjs');
|
|
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
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-Bx2c4OzK.cjs');
|
|
7
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DWSTKIe3.cjs');
|
|
9
8
|
|
|
10
9
|
//#region src/kysely.ts
|
|
11
10
|
function wrapVitestKyselyTransaction(db, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import
|
|
5
|
-
import "./
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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 { IsolationLevel } from "./VitestTransactionIsolator-BjVXqFs6.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-BS3R-V0I.mjs";
|
|
9
8
|
|
|
10
9
|
//#region src/kysely.ts
|
|
11
10
|
function wrapVitestKyselyTransaction(db, setup, level = IsolationLevel.REPEATABLE_READ) {
|
package/dist/objection.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/testkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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
|
}
|