@geekmidas/testkit 0.4.0 → 0.6.0
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-BFVnMMCC.mjs.map +1 -1
- package/dist/Factory-BhjUOBWN.cjs.map +1 -1
- package/dist/{Factory-c16c27Y6.d.cts → Factory-Bx0AJXZB.d.cts} +3 -2
- package/dist/Factory-Bx0AJXZB.d.cts.map +1 -0
- package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +1 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
- package/dist/{KyselyFactory-uZ45h7YU.d.cts → KyselyFactory-KLeKH43i.d.cts} +4 -3
- package/dist/KyselyFactory-KLeKH43i.d.cts.map +1 -0
- package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +2 -2
- package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
- package/dist/{ObjectionFactory-CdhzKs4f.d.cts → ObjectionFactory-aMGvAKt9.d.cts} +4 -3
- package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +2 -2
- package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
- package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
- package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
- package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
- package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.d.cts +2 -2
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
- package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
- package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
- package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
- package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
- package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
- package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
- package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
- package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
- package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
- package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
- package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
- package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +2 -2
- package/dist/PostgresObjectionMigrator.d.cts +2 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
- package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
- package/dist/VitestTransactionIsolator.d.cts +1 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +2 -0
- package/dist/aws.d.cts.map +1 -0
- package/dist/aws.d.mts +2 -0
- package/dist/aws.d.mts.map +1 -0
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +1 -0
- package/dist/benchmark.d.cts.map +1 -0
- package/dist/benchmark.d.mts +1 -0
- package/dist/benchmark.d.mts.map +1 -0
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +29 -30
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +2 -2
- package/dist/better-auth.d.cts.map +1 -0
- package/dist/better-auth.d.mts.map +1 -0
- package/dist/better-auth.mjs +29 -30
- package/dist/better-auth.mjs.map +1 -1
- package/dist/directory-B-Ozljzk.mjs.map +1 -1
- package/dist/directory-BVC8g7cX.cjs.map +1 -1
- package/dist/{directory-BXavAeJZ.d.mts → directory-CVrfTq1I.d.mts} +2 -1
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/directory-Cys9g76X.d.cts +13 -0
- package/dist/directory-Cys9g76X.d.cts.map +1 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -1
- package/dist/{faker-DvxiCtxc.d.cts → faker-BSH1EMtg.d.cts} +3 -3
- package/dist/faker-BSH1EMtg.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.d.cts +1 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +1 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/kysely.cjs +3 -3
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +8 -7
- package/dist/kysely.d.cts.map +1 -0
- package/dist/kysely.d.mts +7 -6
- package/dist/kysely.d.mts.map +1 -0
- package/dist/kysely.mjs +3 -3
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +3 -3
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +8 -7
- package/dist/objection.d.cts.map +1 -0
- package/dist/objection.d.mts +7 -6
- package/dist/objection.d.mts.map +1 -0
- package/dist/objection.mjs +3 -3
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +2 -0
- package/dist/timer.d.cts.map +1 -0
- package/dist/timer.d.mts +2 -0
- package/dist/timer.d.mts.map +1 -0
- package/dist/timer.mjs.map +1 -1
- package/package.json +5 -5
- package/src/Factory.ts +72 -72
- package/src/KyselyFactory.ts +330 -330
- package/src/ObjectionFactory.ts +354 -355
- package/src/PostgresKyselyMigrator.ts +37 -37
- package/src/PostgresMigrator.ts +107 -107
- package/src/PostgresObjectionMigrator.ts +91 -91
- package/src/VitestKyselyTransactionIsolator.ts +27 -27
- package/src/VitestObjectionTransactionIsolator.ts +39 -39
- package/src/VitestTransactionIsolator.ts +196 -195
- package/src/__tests__/Factory.spec.ts +163 -155
- package/src/__tests__/KyselyFactory.spec.ts +443 -439
- package/src/__tests__/ObjectionFactory.spec.ts +563 -557
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
- package/src/__tests__/PostgresMigrator.spec.ts +341 -341
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +15 -15
- package/src/__tests__/faker.spec.ts +226 -137
- package/src/__tests__/integration.spec.ts +597 -597
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +104 -104
- package/src/benchmark.ts +12 -12
- package/src/better-auth.ts +286 -301
- package/src/faker.ts +153 -153
- package/src/helpers.ts +6 -6
- package/src/kysely.ts +33 -33
- package/src/logger.ts +10 -10
- package/src/objection.ts +31 -31
- package/src/os/directory.ts +11 -10
- package/src/timer.ts +1 -1
- package/test/globalSetup.ts +45 -45
- package/test/helpers.ts +189 -189
- package/test/migrations/1749664623372_user.ts +13 -13
- package/tsconfig.json +9 -0
- package/vitest.config.ts +4 -4
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
- package/dist/directory-Mi7tdOuD.d.cts +0 -12
package/src/faker.ts
CHANGED
|
@@ -18,46 +18,46 @@ import { faker as baseFaker } from '@faker-js/faker';
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
class AtomicCounter {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The current counter value.
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private value: number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new atomic counter.
|
|
29
|
+
* @param initialValue - The starting value (default: 0)
|
|
30
|
+
*/
|
|
31
|
+
constructor(initialValue = 0) {
|
|
32
|
+
this.value = initialValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Increments the counter and returns the new value.
|
|
37
|
+
* @returns The incremented value
|
|
38
|
+
*/
|
|
39
|
+
increment(): number {
|
|
40
|
+
// In Node.js, JavaScript is single-threaded within the event loop,
|
|
41
|
+
// so this operation is already atomic. However, this class provides
|
|
42
|
+
// a cleaner abstraction and makes the intent explicit.
|
|
43
|
+
return ++this.value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets the current counter value without incrementing.
|
|
48
|
+
* @returns The current value
|
|
49
|
+
*/
|
|
50
|
+
get(): number {
|
|
51
|
+
return this.value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Resets the counter to a specific value.
|
|
56
|
+
* @param value - The new value (default: 0)
|
|
57
|
+
*/
|
|
58
|
+
reset(value = 0): void {
|
|
59
|
+
this.value = value;
|
|
60
|
+
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -81,16 +81,16 @@ class AtomicCounter {
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
export function timestamps(): Timestamps {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const createdAt = faker.date.past();
|
|
85
|
+
const updatedAt = faker.date.between({
|
|
86
|
+
from: createdAt,
|
|
87
|
+
to: new Date(),
|
|
88
|
+
});
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
createdAt.setMilliseconds(0);
|
|
91
|
+
updatedAt.setMilliseconds(0);
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
return { createdAt, updatedAt };
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -108,11 +108,11 @@ export function timestamps(): Timestamps {
|
|
|
108
108
|
* ```
|
|
109
109
|
*/
|
|
110
110
|
export function identifier(suffix?: string): string {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
return [
|
|
112
|
+
faker.internet.domainSuffix(),
|
|
113
|
+
faker.internet.domainWord(),
|
|
114
|
+
suffix ? suffix : faker.internet.domainWord() + sequence('identifier'),
|
|
115
|
+
].join('.');
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
@@ -143,12 +143,12 @@ const sequences = new Map<string, AtomicCounter>();
|
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
export function sequence(name = 'default'): number {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
if (!sequences.has(name)) {
|
|
147
|
+
sequences.set(name, new AtomicCounter());
|
|
148
|
+
}
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
const counter = sequences.get(name) as AtomicCounter;
|
|
151
|
+
return counter.increment();
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -170,12 +170,12 @@ export function sequence(name = 'default'): number {
|
|
|
170
170
|
* ```
|
|
171
171
|
*/
|
|
172
172
|
export function resetSequence(name = 'default', value = 0): void {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
if (sequences.has(name)) {
|
|
174
|
+
const counter = sequences.get(name) as AtomicCounter;
|
|
175
|
+
counter.reset(value);
|
|
176
|
+
} else {
|
|
177
|
+
sequences.set(name, new AtomicCounter(value));
|
|
178
|
+
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
/**
|
|
@@ -196,7 +196,7 @@ export function resetSequence(name = 'default', value = 0): void {
|
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
198
|
export function resetAllSequences(): void {
|
|
199
|
-
|
|
199
|
+
sequences.clear();
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -212,89 +212,89 @@ export function resetAllSequences(): void {
|
|
|
212
212
|
* ```
|
|
213
213
|
*/
|
|
214
214
|
function price(): number {
|
|
215
|
-
|
|
215
|
+
return +faker.commerce.price();
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
type Coordinate = {
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
lat: number;
|
|
220
|
+
lng: number;
|
|
221
221
|
};
|
|
222
222
|
|
|
223
223
|
export function coordinateInRadius(
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
center: Coordinate,
|
|
225
|
+
radius: number,
|
|
226
226
|
): Coordinate {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
227
|
+
// Earth's radius in meters
|
|
228
|
+
const earth = 6378137;
|
|
229
|
+
// Convert radius from meters to degrees
|
|
230
|
+
const d = radius / earth;
|
|
231
|
+
|
|
232
|
+
// Random bearing and distance
|
|
233
|
+
const theta = 2 * Math.PI * Math.random();
|
|
234
|
+
const r = d * Math.sqrt(Math.random());
|
|
235
|
+
|
|
236
|
+
const lat1 = (center.lat * Math.PI) / 180;
|
|
237
|
+
const lng1 = (center.lng * Math.PI) / 180;
|
|
238
|
+
|
|
239
|
+
const lat2 = Math.asin(
|
|
240
|
+
Math.sin(lat1) * Math.cos(r) +
|
|
241
|
+
Math.cos(lat1) * Math.sin(r) * Math.cos(theta),
|
|
242
|
+
);
|
|
243
|
+
const lng2 =
|
|
244
|
+
lng1 +
|
|
245
|
+
Math.atan2(
|
|
246
|
+
Math.sin(theta) * Math.sin(r) * Math.cos(lat1),
|
|
247
|
+
Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
lat: (lat2 * 180) / Math.PI,
|
|
252
|
+
lng: (lng2 * 180) / Math.PI,
|
|
253
|
+
};
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
function coordinateOutsideRadius(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
center: Coordinate,
|
|
258
|
+
minRadiusMeters: number,
|
|
259
|
+
maxRadiusMeters: number,
|
|
260
260
|
): Coordinate {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
261
|
+
// Earth's radius in meters
|
|
262
|
+
const earth = 6378137;
|
|
263
|
+
|
|
264
|
+
// Convert radii from meters to radians
|
|
265
|
+
const minD = minRadiusMeters / earth;
|
|
266
|
+
const maxD = maxRadiusMeters / earth;
|
|
267
|
+
|
|
268
|
+
// Random bearing
|
|
269
|
+
const theta = 2 * Math.PI * Math.random();
|
|
270
|
+
|
|
271
|
+
// Random distance in annular ring (uniform distribution by area)
|
|
272
|
+
// For uniform distribution in annulus: r = sqrt(r_min² + (r_max² - r_min²) * random)
|
|
273
|
+
const r = Math.sqrt(
|
|
274
|
+
minD * minD + (maxD * maxD - minD * minD) * Math.random(),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const lat1 = (center.lat * Math.PI) / 180;
|
|
278
|
+
const lng1 = (center.lng * Math.PI) / 180;
|
|
279
|
+
|
|
280
|
+
const lat2 = Math.asin(
|
|
281
|
+
Math.sin(lat1) * Math.cos(r) +
|
|
282
|
+
Math.cos(lat1) * Math.sin(r) * Math.cos(theta),
|
|
283
|
+
);
|
|
284
|
+
const lng2 =
|
|
285
|
+
lng1 +
|
|
286
|
+
Math.atan2(
|
|
287
|
+
Math.sin(theta) * Math.sin(r) * Math.cos(lat1),
|
|
288
|
+
Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
// Normalize longitude to [-180, 180]
|
|
292
|
+
const normalizedLng = (((lng2 * 180) / Math.PI + 540) % 360) - 180;
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
lat: (lat2 * 180) / Math.PI,
|
|
296
|
+
lng: normalizedLng,
|
|
297
|
+
};
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
/**
|
|
@@ -317,18 +317,18 @@ function coordinateOutsideRadius(
|
|
|
317
317
|
* ```
|
|
318
318
|
*/
|
|
319
319
|
export const faker = Object.freeze(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
320
|
+
Object.assign({}, baseFaker, {
|
|
321
|
+
timestamps,
|
|
322
|
+
identifier,
|
|
323
|
+
sequence,
|
|
324
|
+
resetSequence,
|
|
325
|
+
resetAllSequences,
|
|
326
|
+
price,
|
|
327
|
+
coordinates: {
|
|
328
|
+
within: coordinateInRadius,
|
|
329
|
+
outside: coordinateOutsideRadius,
|
|
330
|
+
},
|
|
331
|
+
}),
|
|
332
332
|
);
|
|
333
333
|
|
|
334
334
|
/**
|
|
@@ -336,10 +336,10 @@ export const faker = Object.freeze(
|
|
|
336
336
|
* Used by the timestamps() function to generate date fields.
|
|
337
337
|
*/
|
|
338
338
|
export type Timestamps = {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
339
|
+
/** The creation date */
|
|
340
|
+
createdAt: Date;
|
|
341
|
+
/** The last update date */
|
|
342
|
+
updatedAt: Date;
|
|
343
343
|
};
|
|
344
344
|
|
|
345
345
|
/**
|
package/src/helpers.ts
CHANGED
|
@@ -36,10 +36,10 @@ import pg from 'pg';
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export function createKyselyDb<Database>(config: any): Kysely<Database> {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
return new Kysely({
|
|
40
|
+
dialect: new PostgresDialect({
|
|
41
|
+
pool: new pg.Pool(config),
|
|
42
|
+
}),
|
|
43
|
+
plugins: [new CamelCasePlugin()],
|
|
44
|
+
});
|
|
45
45
|
}
|
package/src/kysely.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { Kysely, Transaction } from 'kysely';
|
|
|
2
2
|
import type { TestAPI } from 'vitest';
|
|
3
3
|
import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
extendWithFixtures as baseExtendWithFixtures,
|
|
6
|
+
type DatabaseConnection,
|
|
7
|
+
type FixtureCreators,
|
|
8
|
+
type IsolationLevel,
|
|
9
9
|
} from './VitestTransactionIsolator';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -13,38 +13,38 @@ import {
|
|
|
13
13
|
* Provides factories, migrators, and transaction isolators for Kysely ORM.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
export { KyselyFactory } from './KyselyFactory';
|
|
17
16
|
export type { ExtractSeedAttrs, FactorySeed } from './Factory';
|
|
17
|
+
export { KyselyFactory } from './KyselyFactory';
|
|
18
18
|
export { PostgresKyselyMigrator } from './PostgresKyselyMigrator';
|
|
19
19
|
export { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
|
|
20
|
-
export { IsolationLevel } from './VitestTransactionIsolator';
|
|
21
20
|
export type {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
DatabaseFixtures,
|
|
22
|
+
ExtendedDatabaseFixtures,
|
|
23
|
+
FixtureCreators,
|
|
24
|
+
TestWithExtendedFixtures,
|
|
25
|
+
TransactionWrapperOptions,
|
|
27
26
|
} from './VitestTransactionIsolator';
|
|
27
|
+
export { IsolationLevel } from './VitestTransactionIsolator';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Kysely-specific options for transaction wrapping.
|
|
31
31
|
*/
|
|
32
32
|
export interface KyselyTransactionOptions<
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
Database,
|
|
34
|
+
Extended extends Record<string, unknown> = {},
|
|
35
35
|
> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
/** Function that creates or returns a Kysely database instance */
|
|
37
|
+
connection: DatabaseConnection<Kysely<Database>>;
|
|
38
|
+
/** Optional setup function to run within the transaction before each test */
|
|
39
|
+
setup?: (trx: Transaction<Database>) => Promise<void>;
|
|
40
|
+
/** Transaction isolation level (defaults to REPEATABLE_READ) */
|
|
41
|
+
isolationLevel?: IsolationLevel;
|
|
42
|
+
/** Additional fixtures that depend on the transaction */
|
|
43
|
+
fixtures?: FixtureCreators<Transaction<Database>, Extended>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// Re-export faker and FakerFactory for type portability in declaration files
|
|
47
|
-
export {
|
|
47
|
+
export { type FakerFactory, faker } from './faker';
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
@@ -94,12 +94,12 @@ export { faker, type FakerFactory } from './faker';
|
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
96
|
export function wrapVitestKyselyTransaction<
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
Database,
|
|
98
|
+
Extended extends Record<string, unknown> = {},
|
|
99
99
|
>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {
|
|
100
|
-
|
|
100
|
+
const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
return wrapper.wrapVitestWithTransaction(options);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
@@ -155,12 +155,12 @@ export function wrapVitestKyselyTransaction<
|
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
157
|
export function extendWithFixtures<
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
Database,
|
|
159
|
+
Extended extends Record<string, unknown>,
|
|
160
|
+
T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,
|
|
161
161
|
>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
return baseExtendWithFixtures<Transaction<Database>, Extended, T>(
|
|
163
|
+
wrappedTest,
|
|
164
|
+
fixtures,
|
|
165
|
+
);
|
|
166
166
|
}
|
package/src/logger.ts
CHANGED
|
@@ -5,14 +5,14 @@ import { vi } from 'vitest';
|
|
|
5
5
|
* Creates a mock Logger for testing
|
|
6
6
|
*/
|
|
7
7
|
export function createMockLogger(): Logger {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const logger: Logger = {
|
|
9
|
+
debug: vi.fn(),
|
|
10
|
+
info: vi.fn(),
|
|
11
|
+
warn: vi.fn(),
|
|
12
|
+
error: vi.fn(),
|
|
13
|
+
fatal: vi.fn(),
|
|
14
|
+
trace: vi.fn(),
|
|
15
|
+
child: vi.fn(() => logger),
|
|
16
|
+
};
|
|
17
|
+
return logger;
|
|
18
18
|
}
|
package/src/objection.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { Knex } from 'knex';
|
|
|
2
2
|
import type { TestAPI } from 'vitest';
|
|
3
3
|
import { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
extendWithFixtures as baseExtendWithFixtures,
|
|
6
|
+
type DatabaseConnection,
|
|
7
|
+
type FixtureCreators,
|
|
8
|
+
type IsolationLevel,
|
|
9
9
|
} from './VitestTransactionIsolator';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -14,37 +14,37 @@ import {
|
|
|
14
14
|
* and transaction isolation for test suites.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
export { ObjectionFactory } from './ObjectionFactory';
|
|
18
17
|
export type { ExtractSeedAttrs, FactorySeed } from './Factory';
|
|
19
|
-
export {
|
|
20
|
-
export { IsolationLevel } from './VitestTransactionIsolator';
|
|
18
|
+
export { ObjectionFactory } from './ObjectionFactory';
|
|
21
19
|
export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
|
|
20
|
+
export { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
|
|
22
21
|
export type {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
DatabaseFixtures,
|
|
23
|
+
ExtendedDatabaseFixtures,
|
|
24
|
+
FixtureCreators,
|
|
25
|
+
TestWithExtendedFixtures,
|
|
26
|
+
TransactionWrapperOptions,
|
|
28
27
|
} from './VitestTransactionIsolator';
|
|
28
|
+
export { IsolationLevel } from './VitestTransactionIsolator';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Objection.js-specific options for transaction wrapping.
|
|
32
32
|
*/
|
|
33
33
|
export interface ObjectionTransactionOptions<
|
|
34
|
-
|
|
34
|
+
Extended extends Record<string, unknown> = {},
|
|
35
35
|
> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
/** Function that creates or returns a Knex database connection */
|
|
37
|
+
connection: DatabaseConnection<Knex>;
|
|
38
|
+
/** Optional setup function to run within the transaction before each test */
|
|
39
|
+
setup?: (trx: Knex.Transaction) => Promise<void>;
|
|
40
|
+
/** Transaction isolation level (defaults to REPEATABLE_READ) */
|
|
41
|
+
isolationLevel?: IsolationLevel;
|
|
42
|
+
/** Additional fixtures that depend on the transaction */
|
|
43
|
+
fixtures?: FixtureCreators<Knex.Transaction, Extended>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// Re-export faker and FakerFactory for type portability in declaration files
|
|
47
|
-
export {
|
|
47
|
+
export { type FakerFactory, faker } from './faker';
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
|
|
@@ -91,11 +91,11 @@ export { faker, type FakerFactory } from './faker';
|
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
93
93
|
export function wrapVitestObjectionTransaction<
|
|
94
|
-
|
|
94
|
+
Extended extends Record<string, unknown> = {},
|
|
95
95
|
>(api: TestAPI, options: ObjectionTransactionOptions<Extended>) {
|
|
96
|
-
|
|
96
|
+
const wrapper = new VitestObjectionTransactionIsolator(api);
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
return wrapper.wrapVitestWithTransaction(options);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
@@ -147,11 +147,11 @@ export function wrapVitestObjectionTransaction<
|
|
|
147
147
|
* ```
|
|
148
148
|
*/
|
|
149
149
|
export function extendWithFixtures<
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
Extended extends Record<string, unknown>,
|
|
151
|
+
T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,
|
|
152
152
|
>(wrappedTest: T, fixtures: FixtureCreators<Knex.Transaction, Extended>) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
return baseExtendWithFixtures<Knex.Transaction, Extended, T>(
|
|
154
|
+
wrappedTest,
|
|
155
|
+
fixtures,
|
|
156
|
+
);
|
|
157
157
|
}
|
package/src/os/directory.ts
CHANGED
|
@@ -5,17 +5,18 @@ import path from 'node:path';
|
|
|
5
5
|
import { it } from 'vitest';
|
|
6
6
|
|
|
7
7
|
export const itWithDir = it.extend<DirectoryFixtures>({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
// This fixture automatically provides a transaction to each test
|
|
9
|
+
// biome-ignore lint/correctness/noEmptyPattern: this has to be like this to satisfy Biome
|
|
10
|
+
dir: async ({}, use) => {
|
|
11
|
+
const tempDir = os.tmpdir();
|
|
12
|
+
const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();
|
|
13
|
+
const dir = path.join(tempDir, directoryName);
|
|
14
|
+
await fs.mkdir(dir, { recursive: true });
|
|
15
|
+
await use(dir);
|
|
16
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
17
|
+
},
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
export interface DirectoryFixtures {
|
|
20
|
-
|
|
21
|
+
dir: string;
|
|
21
22
|
}
|
package/src/timer.ts
CHANGED