@geekmidas/testkit 0.0.5 → 0.0.7
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-WMhTNZ9S.cjs +56 -0
- package/dist/Factory-z2m01hMj.mjs +50 -0
- package/dist/Factory.cjs +1 -1
- package/dist/Factory.mjs +1 -1
- package/dist/KyselyFactory-Bdq1s1Go.cjs +215 -0
- package/dist/KyselyFactory-ELiHgHVv.mjs +210 -0
- package/dist/KyselyFactory.cjs +3 -3
- package/dist/KyselyFactory.mjs +3 -3
- package/dist/ObjectionFactory-89p-FFEw.mjs +178 -0
- package/dist/ObjectionFactory-C47B03Ot.cjs +183 -0
- package/dist/ObjectionFactory.cjs +2 -2
- package/dist/ObjectionFactory.mjs +2 -2
- package/dist/PostgresKyselyMigrator-Bs31emFd.cjs +87 -0
- package/dist/PostgresKyselyMigrator-ChIpZFYB.mjs +81 -0
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/PostgresMigrator-BtAWdLss.cjs +151 -0
- package/dist/PostgresMigrator-BzqksJcW.mjs +145 -0
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/VitestKyselyTransactionIsolator-AfxPJEwR.mjs +58 -0
- package/dist/VitestKyselyTransactionIsolator-YWnSJiIH.cjs +63 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
- package/dist/VitestObjectionTransactionIsolator-0uX6DW5G.cjs +66 -0
- package/dist/VitestObjectionTransactionIsolator-BZRYy8iW.mjs +61 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +4 -0
- package/dist/VitestObjectionTransactionIsolator.mjs +4 -0
- package/dist/VitestTransactionIsolator-DcOz0LZF.cjs +129 -0
- package/dist/VitestTransactionIsolator-kFL36T8x.mjs +117 -0
- package/dist/VitestTransactionIsolator.cjs +1 -1
- package/dist/VitestTransactionIsolator.mjs +1 -1
- package/dist/__tests__/Factory.spec.cjs +1 -1
- package/dist/__tests__/Factory.spec.mjs +1 -1
- package/dist/__tests__/KyselyFactory.spec.cjs +41 -40
- package/dist/__tests__/KyselyFactory.spec.mjs +42 -41
- package/dist/__tests__/ObjectionFactory.spec.cjs +3 -3
- package/dist/__tests__/ObjectionFactory.spec.mjs +3 -3
- package/dist/__tests__/PostgresMigrator.spec.cjs +2 -2
- package/dist/__tests__/PostgresMigrator.spec.mjs +2 -2
- package/dist/__tests__/faker.spec.cjs +1 -1
- package/dist/__tests__/faker.spec.mjs +1 -1
- package/dist/__tests__/integration.spec.cjs +11 -8
- package/dist/__tests__/integration.spec.mjs +12 -9
- package/dist/example.cjs +3 -3
- package/dist/example.mjs +3 -3
- package/dist/faker-CxKkEeYi.mjs +227 -0
- package/dist/faker-SMN4ira4.cjs +263 -0
- package/dist/faker.cjs +1 -1
- package/dist/faker.mjs +1 -1
- package/dist/helpers-CKMlwSYT.mjs +47 -0
- package/dist/helpers-H4hO5SZR.cjs +53 -0
- package/dist/helpers.cjs +2 -5
- package/dist/helpers.mjs +2 -4
- package/dist/kysely-B-GOhABm.cjs +72 -0
- package/dist/kysely-CqfoKVXs.mjs +67 -0
- package/dist/kysely.cjs +11 -15
- package/dist/kysely.mjs +9 -15
- package/dist/objection.cjs +86 -3
- package/dist/objection.mjs +83 -3
- package/package.json +2 -2
- package/src/Factory.ts +97 -0
- package/src/KyselyFactory.ts +180 -0
- package/src/ObjectionFactory.ts +145 -3
- package/src/PostgresKyselyMigrator.ts +54 -0
- package/src/PostgresMigrator.ts +90 -0
- package/src/VitestKyselyTransactionIsolator.ts +46 -0
- package/src/VitestObjectionTransactionIsolator.ts +73 -0
- package/src/VitestTransactionIsolator.ts +99 -2
- package/src/__tests__/KyselyFactory.spec.ts +4 -6
- package/src/__tests__/integration.spec.ts +8 -3
- package/src/faker.ts +158 -7
- package/src/helpers.ts +35 -18
- package/src/kysely.ts +66 -1
- package/src/objection.ts +95 -0
- package/dist/Factory-DREHoms3.cjs +0 -15
- package/dist/Factory-DlzMkMzb.mjs +0 -9
- package/dist/KyselyFactory-BX7Kv2uP.cjs +0 -65
- package/dist/KyselyFactory-pOMOFQWE.mjs +0 -60
- package/dist/ObjectionFactory-BlkzSEqo.cjs +0 -41
- package/dist/ObjectionFactory-ChuX8sZN.mjs +0 -36
- package/dist/PostgresKyselyMigrator-D8fm35-s.mjs +0 -27
- package/dist/PostgresKyselyMigrator-JTY2LfwD.cjs +0 -33
- package/dist/PostgresMigrator-Bz-tnjB6.cjs +0 -67
- package/dist/PostgresMigrator-CEoRKTdq.mjs +0 -61
- package/dist/VitestKyselyTransactionIsolator-BS3R-V0I.mjs +0 -12
- package/dist/VitestKyselyTransactionIsolator-DWSTKIe3.cjs +0 -17
- package/dist/VitestTransactionIsolator-BjVXqFs6.mjs +0 -40
- package/dist/VitestTransactionIsolator-Bx2c4OzK.cjs +0 -52
- package/dist/faker-BwaXA_RF.mjs +0 -85
- package/dist/faker-caz-8zt8.cjs +0 -121
- package/dist/helpers-B9Jdk_C7.cjs +0 -31
- package/dist/helpers-DOiGIkaU.mjs +0 -19
- /package/dist/{helpers-DKEBHABj.cjs → helpers-Bnm3Jy9X.cjs} +0 -0
- /package/dist/{helpers-BfuX-cjN.mjs → helpers-CukcFAU9.mjs} +0 -0
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import "../Factory-
|
|
2
|
-
import "../faker-
|
|
3
|
-
import { KyselyFactory } from "../KyselyFactory-
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import "../Factory-z2m01hMj.mjs";
|
|
2
|
+
import "../faker-CxKkEeYi.mjs";
|
|
3
|
+
import { KyselyFactory } from "../KyselyFactory-ELiHgHVv.mjs";
|
|
4
|
+
import "../PostgresMigrator-BzqksJcW.mjs";
|
|
5
|
+
import "../PostgresKyselyMigrator-ChIpZFYB.mjs";
|
|
6
|
+
import "../VitestTransactionIsolator-kFL36T8x.mjs";
|
|
7
|
+
import "../VitestKyselyTransactionIsolator-AfxPJEwR.mjs";
|
|
8
|
+
import { createKyselyDb } from "../helpers-CKMlwSYT.mjs";
|
|
9
|
+
import { wrapVitestKyselyTransaction } from "../kysely-CqfoKVXs.mjs";
|
|
10
|
+
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-CukcFAU9.mjs";
|
|
8
11
|
import pg from "pg";
|
|
9
|
-
import { describe, expect } from "vitest";
|
|
12
|
+
import { describe, expect, it } from "vitest";
|
|
10
13
|
|
|
11
14
|
//#region src/__tests__/KyselyFactory.spec.ts
|
|
12
15
|
const db = createKyselyDb(TEST_DATABASE_CONFIG);
|
|
13
|
-
const itWithTransaction = wrapVitestKyselyTransaction(db, createTestTables);
|
|
16
|
+
const itWithTransaction = wrapVitestKyselyTransaction(it, db, createTestTables);
|
|
14
17
|
const int8TypeId = 20;
|
|
15
18
|
pg.types.setTypeParser(int8TypeId, (val) => {
|
|
16
19
|
return parseInt(val, 10);
|
|
17
20
|
});
|
|
18
21
|
describe("KyselyFactory", () => {
|
|
19
|
-
let db$1;
|
|
20
|
-
let trx;
|
|
21
22
|
describe("KyselyFactory.insert", () => {
|
|
22
|
-
itWithTransaction("should insert a record with defaults", async ({ trx
|
|
23
|
+
itWithTransaction("should insert a record with defaults", async ({ trx }) => {
|
|
23
24
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
24
25
|
name: "John Doe",
|
|
25
26
|
email: `user${Date.now()}@example.com`,
|
|
26
27
|
createdAt: /* @__PURE__ */ new Date()
|
|
27
28
|
}));
|
|
28
29
|
const builders = { user: userBuilder };
|
|
29
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
30
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
30
31
|
const user = await factory.insert("user");
|
|
31
32
|
expect(user).toBeDefined();
|
|
32
33
|
expect(user.id).toBeDefined();
|
|
@@ -35,14 +36,14 @@ describe("KyselyFactory", () => {
|
|
|
35
36
|
expect(user.email).toContain("@example.com");
|
|
36
37
|
expect(user.createdAt).toBeInstanceOf(Date);
|
|
37
38
|
});
|
|
38
|
-
itWithTransaction("should override defaults with provided attributes", async ({ trx
|
|
39
|
+
itWithTransaction("should override defaults with provided attributes", async ({ trx }) => {
|
|
39
40
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
40
41
|
name: "John Doe",
|
|
41
42
|
email: `user${Date.now()}@example.com`,
|
|
42
43
|
createdAt: /* @__PURE__ */ new Date()
|
|
43
44
|
}));
|
|
44
45
|
const builders = { user: userBuilder };
|
|
45
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
46
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
46
47
|
const customEmail = "custom@test.com";
|
|
47
48
|
const customName = "Jane Smith";
|
|
48
49
|
const user = await factory.insert("user", {
|
|
@@ -52,7 +53,7 @@ describe("KyselyFactory", () => {
|
|
|
52
53
|
expect(user.name).toBe(customName);
|
|
53
54
|
expect(user.email).toBe(customEmail);
|
|
54
55
|
});
|
|
55
|
-
itWithTransaction("should handle relations", async ({ trx
|
|
56
|
+
itWithTransaction("should handle relations", async ({ trx }) => {
|
|
56
57
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
57
58
|
name: "John Doe",
|
|
58
59
|
email: `user${Date.now()}@example.com`,
|
|
@@ -78,27 +79,27 @@ describe("KyselyFactory", () => {
|
|
|
78
79
|
user: userBuilder,
|
|
79
80
|
post: postBuilder
|
|
80
81
|
};
|
|
81
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
82
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
82
83
|
const post = await factory.insert("post", { title: "Test Post" });
|
|
83
84
|
expect(post).toBeDefined();
|
|
84
85
|
expect(post.title).toBe("Test Post");
|
|
85
86
|
expect(post.userId).toBeDefined();
|
|
86
87
|
expect(typeof post.userId).toBe("number");
|
|
87
88
|
});
|
|
88
|
-
itWithTransaction("should throw error for non-existent builder", async ({ trx
|
|
89
|
-
const factory = new KyselyFactory({}, {}, trx
|
|
89
|
+
itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
|
|
90
|
+
const factory = new KyselyFactory({}, {}, trx);
|
|
90
91
|
await expect(factory.insert("nonExistent")).rejects.toThrow("Factory \"nonExistent\" does not exist");
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
describe("KyselyFactory.insertMany", () => {
|
|
94
|
-
itWithTransaction("should insert multiple records with same attributes", async ({ trx
|
|
95
|
+
itWithTransaction("should insert multiple records with same attributes", async ({ trx }) => {
|
|
95
96
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
96
97
|
name: "John Doe",
|
|
97
98
|
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
98
99
|
createdAt: /* @__PURE__ */ new Date()
|
|
99
100
|
}));
|
|
100
101
|
const builders = { user: userBuilder };
|
|
101
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
102
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
102
103
|
const users = await factory.insertMany(3, "user");
|
|
103
104
|
expect(users).toHaveLength(3);
|
|
104
105
|
users.forEach((user, index) => {
|
|
@@ -107,26 +108,26 @@ describe("KyselyFactory", () => {
|
|
|
107
108
|
expect(user.email).toContain("@example.com");
|
|
108
109
|
});
|
|
109
110
|
});
|
|
110
|
-
itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx
|
|
111
|
+
itWithTransaction("should insert multiple records with dynamic attributes", async ({ trx }) => {
|
|
111
112
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
112
113
|
email: `user${Date.now()}-${Math.random()}@example.com`,
|
|
113
114
|
createdAt: /* @__PURE__ */ new Date()
|
|
114
115
|
}));
|
|
115
116
|
const builders = { user: userBuilder };
|
|
116
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
117
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
117
118
|
const users = await factory.insertMany(3, "user", (idx) => ({ name: `User ${idx}` }));
|
|
118
119
|
expect(users).toHaveLength(3);
|
|
119
120
|
users.forEach((user, index) => {
|
|
120
121
|
expect(user.name).toBe(`User ${index}`);
|
|
121
122
|
});
|
|
122
123
|
});
|
|
123
|
-
itWithTransaction("should throw error for non-existent builder", async ({ trx
|
|
124
|
-
const factory = new KyselyFactory({}, {}, trx
|
|
124
|
+
itWithTransaction("should throw error for non-existent builder", async ({ trx }) => {
|
|
125
|
+
const factory = new KyselyFactory({}, {}, trx);
|
|
125
126
|
await expect(factory.insertMany(2, "nonExistent")).rejects.toThrow("Builder \"nonExistent\" is not registered");
|
|
126
127
|
});
|
|
127
128
|
});
|
|
128
129
|
describe("KyselyFactory.createBuilder", () => {
|
|
129
|
-
itWithTransaction("should work with async defaults", async ({ trx
|
|
130
|
+
itWithTransaction("should work with async defaults", async ({ trx }) => {
|
|
130
131
|
let counter = 0;
|
|
131
132
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => {
|
|
132
133
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -138,7 +139,7 @@ describe("KyselyFactory", () => {
|
|
|
138
139
|
};
|
|
139
140
|
});
|
|
140
141
|
const builders = { user: userBuilder };
|
|
141
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
142
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
142
143
|
const user1 = await factory.insert("user");
|
|
143
144
|
const user2 = await factory.insert("user");
|
|
144
145
|
expect(user1.name).toBe("Async User 1");
|
|
@@ -146,36 +147,36 @@ describe("KyselyFactory", () => {
|
|
|
146
147
|
});
|
|
147
148
|
});
|
|
148
149
|
describe("KyselyFactory.seed", () => {
|
|
149
|
-
itWithTransaction("should execute seed functions", async ({ trx
|
|
150
|
+
itWithTransaction("should execute seed functions", async ({ trx }) => {
|
|
150
151
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
151
152
|
name: "John Doe",
|
|
152
153
|
email: `user${Date.now()}@example.com`,
|
|
153
154
|
createdAt: /* @__PURE__ */ new Date()
|
|
154
155
|
}));
|
|
155
156
|
const builders = { user: userBuilder };
|
|
156
|
-
const seeds = { createAdminUser: KyselyFactory.createSeed(async (attrs, factory$1, db$
|
|
157
|
+
const seeds = { createAdminUser: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
157
158
|
return await factory$1.insert("user", {
|
|
158
159
|
name: attrs.name || "Admin User",
|
|
159
160
|
email: "admin@example.com"
|
|
160
161
|
});
|
|
161
162
|
}) };
|
|
162
|
-
const factory = new KyselyFactory(builders, seeds, trx
|
|
163
|
+
const factory = new KyselyFactory(builders, seeds, trx);
|
|
163
164
|
const adminUser = await factory.seed("createAdminUser");
|
|
164
165
|
expect(adminUser).toBeDefined();
|
|
165
166
|
expect(adminUser.name).toBe("Admin User");
|
|
166
167
|
expect(adminUser.email).toBe("admin@example.com");
|
|
167
168
|
});
|
|
168
|
-
itWithTransaction("should pass attributes to seed functions", async ({ trx
|
|
169
|
+
itWithTransaction("should pass attributes to seed functions", async ({ trx }) => {
|
|
169
170
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
170
171
|
name: "John Doe",
|
|
171
172
|
email: `user${Date.now()}@example.com`,
|
|
172
173
|
createdAt: /* @__PURE__ */ new Date()
|
|
173
174
|
}));
|
|
174
175
|
const builders = { user: userBuilder };
|
|
175
|
-
const seeds = { createCustomUser: KyselyFactory.createSeed(async (attrs, factory$1, db$
|
|
176
|
+
const seeds = { createCustomUser: KyselyFactory.createSeed(async (attrs, factory$1, db$1) => {
|
|
176
177
|
return await factory$1.insert("user", attrs);
|
|
177
178
|
}) };
|
|
178
|
-
const factory = new KyselyFactory(builders, seeds, trx
|
|
179
|
+
const factory = new KyselyFactory(builders, seeds, trx);
|
|
179
180
|
const customUser = await factory.seed("createCustomUser", {
|
|
180
181
|
name: "Custom User",
|
|
181
182
|
email: "custom@test.com"
|
|
@@ -183,26 +184,26 @@ describe("KyselyFactory", () => {
|
|
|
183
184
|
expect(customUser.name).toBe("Custom User");
|
|
184
185
|
expect(customUser.email).toBe("custom@test.com");
|
|
185
186
|
});
|
|
186
|
-
itWithTransaction("should throw error for non-existent seed", async ({ trx
|
|
187
|
-
const factory = new KyselyFactory({}, {}, trx
|
|
187
|
+
itWithTransaction("should throw error for non-existent seed", async ({ trx }) => {
|
|
188
|
+
const factory = new KyselyFactory({}, {}, trx);
|
|
188
189
|
expect(() => factory.seed("nonExistent")).toThrow("Seed \"nonExistent\" is not registered");
|
|
189
190
|
});
|
|
190
191
|
});
|
|
191
192
|
describe("Factory integration", () => {
|
|
192
|
-
itWithTransaction("should work with controlled transactions", async ({ trx
|
|
193
|
+
itWithTransaction("should work with controlled transactions", async ({ trx }) => {
|
|
193
194
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
194
195
|
name: "John Doe",
|
|
195
196
|
email: `user${Date.now()}@example.com`,
|
|
196
197
|
createdAt: /* @__PURE__ */ new Date()
|
|
197
198
|
}));
|
|
198
199
|
const builders = { user: userBuilder };
|
|
199
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
200
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
200
201
|
const user = await factory.insert("user");
|
|
201
|
-
const foundUser = await trx
|
|
202
|
+
const foundUser = await trx.selectFrom("users").selectAll().where("id", "=", user.id).executeTakeFirst();
|
|
202
203
|
expect(foundUser).toBeDefined();
|
|
203
204
|
expect(foundUser?.id).toBe(user.id);
|
|
204
205
|
});
|
|
205
|
-
itWithTransaction("should work with factory passed to defaults", async ({ trx
|
|
206
|
+
itWithTransaction("should work with factory passed to defaults", async ({ trx }) => {
|
|
206
207
|
const userBuilder = KyselyFactory.createBuilder("users", async (attrs) => ({
|
|
207
208
|
name: "John Doe",
|
|
208
209
|
email: `user${Date.now()}@example.com`,
|
|
@@ -221,10 +222,10 @@ describe("KyselyFactory", () => {
|
|
|
221
222
|
user: userBuilder,
|
|
222
223
|
post: postBuilder
|
|
223
224
|
};
|
|
224
|
-
const factory = new KyselyFactory(builders, {}, trx
|
|
225
|
+
const factory = new KyselyFactory(builders, {}, trx);
|
|
225
226
|
const post = await factory.insert("post");
|
|
226
227
|
expect(post.userId).toBeDefined();
|
|
227
|
-
const relatedUser = await trx
|
|
228
|
+
const relatedUser = await trx.selectFrom("users").selectAll().where("id", "=", post.userId).executeTakeFirst();
|
|
228
229
|
expect(relatedUser).toBeDefined();
|
|
229
230
|
});
|
|
230
231
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
require('../Factory-
|
|
3
|
-
const require_ObjectionFactory = require('../ObjectionFactory-
|
|
4
|
-
const require_helpers = require('../helpers-
|
|
2
|
+
require('../Factory-WMhTNZ9S.cjs');
|
|
3
|
+
const require_ObjectionFactory = require('../ObjectionFactory-C47B03Ot.cjs');
|
|
4
|
+
const require_helpers = require('../helpers-Bnm3Jy9X.cjs');
|
|
5
5
|
const vitest = require_chunk.__toESM(require("vitest"));
|
|
6
6
|
const objection = require_chunk.__toESM(require("objection"));
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../Factory-
|
|
2
|
-
import { ObjectionFactory } from "../ObjectionFactory-
|
|
3
|
-
import { setupKnexTest } from "../helpers-
|
|
1
|
+
import "../Factory-z2m01hMj.mjs";
|
|
2
|
+
import { ObjectionFactory } from "../ObjectionFactory-89p-FFEw.mjs";
|
|
3
|
+
import { setupKnexTest } from "../helpers-CukcFAU9.mjs";
|
|
4
4
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
5
5
|
import { Model } from "objection";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_PostgresMigrator = require('../PostgresMigrator-
|
|
3
|
-
const require_helpers = require('../helpers-
|
|
2
|
+
const require_PostgresMigrator = require('../PostgresMigrator-BtAWdLss.cjs');
|
|
3
|
+
const require_helpers = require('../helpers-Bnm3Jy9X.cjs');
|
|
4
4
|
const pg = require_chunk.__toESM(require("pg"));
|
|
5
5
|
const vitest = require_chunk.__toESM(require("vitest"));
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PostgresMigrator } from "../PostgresMigrator-
|
|
2
|
-
import { createTestDatabase } from "../helpers-
|
|
1
|
+
import { PostgresMigrator } from "../PostgresMigrator-BzqksJcW.mjs";
|
|
2
|
+
import { createTestDatabase } from "../helpers-CukcFAU9.mjs";
|
|
3
3
|
import { Client } from "pg";
|
|
4
4
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_faker = require('../faker-
|
|
2
|
+
const require_faker = require('../faker-SMN4ira4.cjs');
|
|
3
3
|
const vitest = require_chunk.__toESM(require("vitest"));
|
|
4
4
|
|
|
5
5
|
//#region src/__tests__/faker.spec.ts
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
require('../Factory-
|
|
3
|
-
require('../faker-
|
|
4
|
-
const require_KyselyFactory = require('../KyselyFactory-
|
|
5
|
-
require('../
|
|
6
|
-
require('../
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
require('../Factory-WMhTNZ9S.cjs');
|
|
3
|
+
require('../faker-SMN4ira4.cjs');
|
|
4
|
+
const require_KyselyFactory = require('../KyselyFactory-Bdq1s1Go.cjs');
|
|
5
|
+
require('../PostgresMigrator-BtAWdLss.cjs');
|
|
6
|
+
require('../PostgresKyselyMigrator-Bs31emFd.cjs');
|
|
7
|
+
require('../VitestTransactionIsolator-DcOz0LZF.cjs');
|
|
8
|
+
require('../VitestKyselyTransactionIsolator-YWnSJiIH.cjs');
|
|
9
|
+
const require_helpers = require('../helpers-H4hO5SZR.cjs');
|
|
10
|
+
const require_kysely = require('../kysely-B-GOhABm.cjs');
|
|
11
|
+
const require_helpers$1 = require('../helpers-Bnm3Jy9X.cjs');
|
|
9
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 =
|
|
16
|
+
const it = require_kysely.wrapVitestKyselyTransaction(vitest.it, db, require_helpers$1.createTestTables);
|
|
14
17
|
(0, vitest.describe)("Testkit Integration Tests", () => {
|
|
15
18
|
(0, vitest.beforeAll)(async () => {});
|
|
16
19
|
(0, vitest.describe)("Complex Factory Scenarios", () => {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import "../Factory-
|
|
2
|
-
import "../faker-
|
|
3
|
-
import { KyselyFactory } from "../KyselyFactory-
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
1
|
+
import "../Factory-z2m01hMj.mjs";
|
|
2
|
+
import "../faker-CxKkEeYi.mjs";
|
|
3
|
+
import { KyselyFactory } from "../KyselyFactory-ELiHgHVv.mjs";
|
|
4
|
+
import "../PostgresMigrator-BzqksJcW.mjs";
|
|
5
|
+
import "../PostgresKyselyMigrator-ChIpZFYB.mjs";
|
|
6
|
+
import "../VitestTransactionIsolator-kFL36T8x.mjs";
|
|
7
|
+
import "../VitestKyselyTransactionIsolator-AfxPJEwR.mjs";
|
|
8
|
+
import { createKyselyDb } from "../helpers-CKMlwSYT.mjs";
|
|
9
|
+
import { wrapVitestKyselyTransaction } from "../kysely-CqfoKVXs.mjs";
|
|
10
|
+
import { TEST_DATABASE_CONFIG, createTestTables } from "../helpers-CukcFAU9.mjs";
|
|
11
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
|
9
12
|
|
|
10
13
|
//#region src/__tests__/integration.spec.ts
|
|
11
14
|
const db = createKyselyDb(TEST_DATABASE_CONFIG);
|
|
12
|
-
const it$1 = wrapVitestKyselyTransaction(db, createTestTables);
|
|
15
|
+
const it$1 = wrapVitestKyselyTransaction(it, db, createTestTables);
|
|
13
16
|
describe("Testkit Integration Tests", () => {
|
|
14
17
|
beforeAll(async () => {});
|
|
15
18
|
describe("Complex Factory Scenarios", () => {
|
package/dist/example.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require('./Factory-
|
|
2
|
-
require('./faker-
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
1
|
+
require('./Factory-WMhTNZ9S.cjs');
|
|
2
|
+
require('./faker-SMN4ira4.cjs');
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-Bdq1s1Go.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-z2m01hMj.mjs";
|
|
2
|
+
import "./faker-CxKkEeYi.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-ELiHgHVv.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/example.ts
|
|
6
6
|
const userBuilder = KyselyFactory.createBuilder({
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { faker } from "@faker-js/faker";
|
|
2
|
+
|
|
3
|
+
//#region src/faker.ts
|
|
4
|
+
/**
|
|
5
|
+
* Atomic counter implementation for thread-safe sequence generation.
|
|
6
|
+
* Provides a clean abstraction for generating sequential numbers in tests.
|
|
7
|
+
* While JavaScript is single-threaded, this class makes the intent explicit.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const counter = new AtomicCounter(100);
|
|
12
|
+
* console.log(counter.increment()); // 101
|
|
13
|
+
* console.log(counter.increment()); // 102
|
|
14
|
+
* console.log(counter.get()); // 102
|
|
15
|
+
* counter.reset(200);
|
|
16
|
+
* console.log(counter.increment()); // 201
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
var AtomicCounter = class {
|
|
20
|
+
/**
|
|
21
|
+
* The current counter value.
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
value;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new atomic counter.
|
|
27
|
+
* @param initialValue - The starting value (default: 0)
|
|
28
|
+
*/
|
|
29
|
+
constructor(initialValue = 0) {
|
|
30
|
+
this.value = initialValue;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Increments the counter and returns the new value.
|
|
34
|
+
* @returns The incremented value
|
|
35
|
+
*/
|
|
36
|
+
increment() {
|
|
37
|
+
return ++this.value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the current counter value without incrementing.
|
|
41
|
+
* @returns The current value
|
|
42
|
+
*/
|
|
43
|
+
get() {
|
|
44
|
+
return this.value;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resets the counter to a specific value.
|
|
48
|
+
* @param value - The new value (default: 0)
|
|
49
|
+
*/
|
|
50
|
+
reset(value = 0) {
|
|
51
|
+
this.value = value;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Generates random timestamp fields for database records.
|
|
56
|
+
* Creates a createdAt date in the past and an updatedAt date between creation and now.
|
|
57
|
+
* Milliseconds are set to 0 for cleaner database storage.
|
|
58
|
+
*
|
|
59
|
+
* @returns Object with createdAt and updatedAt Date fields
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const { createdAt, updatedAt } = timestamps();
|
|
64
|
+
* console.log(createdAt); // 2023-05-15T10:30:00.000Z
|
|
65
|
+
* console.log(updatedAt); // 2023-11-20T14:45:00.000Z
|
|
66
|
+
*
|
|
67
|
+
* // Use in factory
|
|
68
|
+
* const user = {
|
|
69
|
+
* name: 'John Doe',
|
|
70
|
+
* ...timestamps()
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function timestamps() {
|
|
75
|
+
const createdAt = faker$1.date.past();
|
|
76
|
+
const updatedAt = faker$1.date.between({
|
|
77
|
+
from: createdAt,
|
|
78
|
+
to: /* @__PURE__ */ new Date()
|
|
79
|
+
});
|
|
80
|
+
createdAt.setMilliseconds(0);
|
|
81
|
+
updatedAt.setMilliseconds(0);
|
|
82
|
+
return {
|
|
83
|
+
createdAt,
|
|
84
|
+
updatedAt
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Generates a reverse domain name identifier.
|
|
89
|
+
* Useful for creating unique identifiers that follow domain naming conventions.
|
|
90
|
+
*
|
|
91
|
+
* @param suffix - Optional suffix to append to the identifier
|
|
92
|
+
* @returns A reverse domain name string (e.g., "com.example.feature123")
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* console.log(identifier()); // "com.example.widget1"
|
|
97
|
+
* console.log(identifier('user')); // "org.acme.user"
|
|
98
|
+
* console.log(identifier('api')); // "net.demo.api"
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
function identifier(suffix) {
|
|
102
|
+
return [
|
|
103
|
+
faker$1.internet.domainSuffix(),
|
|
104
|
+
faker$1.internet.domainWord(),
|
|
105
|
+
suffix ? suffix : faker$1.internet.domainWord() + sequence("identifier")
|
|
106
|
+
].join(".");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Storage for named sequence counters.
|
|
110
|
+
* Each sequence maintains its own independent counter.
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
114
|
+
/**
|
|
115
|
+
* Generates sequential numbers for a named sequence.
|
|
116
|
+
* Useful for creating unique IDs or numbered test data.
|
|
117
|
+
* Each named sequence maintains its own counter.
|
|
118
|
+
*
|
|
119
|
+
* @param name - The sequence name (default: 'default')
|
|
120
|
+
* @returns The next number in the sequence
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* console.log(sequence()); // 1
|
|
125
|
+
* console.log(sequence()); // 2
|
|
126
|
+
* console.log(sequence('user')); // 1
|
|
127
|
+
* console.log(sequence('user')); // 2
|
|
128
|
+
* console.log(sequence()); // 3
|
|
129
|
+
*
|
|
130
|
+
* // Use in factories
|
|
131
|
+
* const email = `user${sequence('email')}@example.com`;
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
function sequence(name = "default") {
|
|
135
|
+
if (!sequences.has(name)) sequences.set(name, new AtomicCounter());
|
|
136
|
+
const counter = sequences.get(name);
|
|
137
|
+
return counter.increment();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Resets a named sequence counter to a specific value.
|
|
141
|
+
* Useful for resetting sequences between test suites.
|
|
142
|
+
*
|
|
143
|
+
* @param name - The sequence name to reset (default: 'default')
|
|
144
|
+
* @param value - The new starting value (default: 0)
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* sequence('user'); // 1
|
|
149
|
+
* sequence('user'); // 2
|
|
150
|
+
* resetSequence('user');
|
|
151
|
+
* sequence('user'); // 1
|
|
152
|
+
*
|
|
153
|
+
* resetSequence('order', 1000);
|
|
154
|
+
* sequence('order'); // 1001
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
function resetSequence(name = "default", value = 0) {
|
|
158
|
+
if (sequences.has(name)) {
|
|
159
|
+
const counter = sequences.get(name);
|
|
160
|
+
counter.reset(value);
|
|
161
|
+
} else sequences.set(name, new AtomicCounter(value));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Resets all sequence counters.
|
|
165
|
+
* Useful for cleaning up between test suites to ensure predictable sequences.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // In test setup
|
|
170
|
+
* beforeEach(() => {
|
|
171
|
+
* resetAllSequences();
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* it('starts sequences from 1', () => {
|
|
175
|
+
* expect(sequence()).toBe(1);
|
|
176
|
+
* expect(sequence('user')).toBe(1);
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
function resetAllSequences() {
|
|
181
|
+
sequences.clear();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Generates a random price as a number.
|
|
185
|
+
* Converts faker's string price to a numeric value.
|
|
186
|
+
*
|
|
187
|
+
* @returns A random price number
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const productPrice = price(); // 29.99
|
|
192
|
+
* const total = price() * quantity; // Numeric calculation
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
function price() {
|
|
196
|
+
return +faker$1.commerce.price();
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Enhanced faker instance with additional utility methods for testing.
|
|
200
|
+
* Extends @faker-js/faker with custom methods for common test data generation patterns.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* import { faker } from '@geekmidas/testkit';
|
|
205
|
+
*
|
|
206
|
+
* // Use standard faker methods
|
|
207
|
+
* const name = faker.person.fullName();
|
|
208
|
+
* const email = faker.internet.email();
|
|
209
|
+
*
|
|
210
|
+
* // Use custom extensions
|
|
211
|
+
* const { createdAt, updatedAt } = faker.timestamps();
|
|
212
|
+
* const id = faker.identifier('user');
|
|
213
|
+
* const orderNumber = faker.sequence('order');
|
|
214
|
+
* const productPrice = faker.price();
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
const faker$1 = Object.freeze(Object.assign({}, faker, {
|
|
218
|
+
timestamps,
|
|
219
|
+
identifier,
|
|
220
|
+
sequence,
|
|
221
|
+
resetSequence,
|
|
222
|
+
resetAllSequences,
|
|
223
|
+
price
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
//#endregion
|
|
227
|
+
export { faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|