@geekmidas/testkit 10.0.0-alpha.99 → 10.0.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.
Files changed (337) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +0 -74
  3. package/dist/Factory-BFVnMMCC.mjs +51 -0
  4. package/dist/Factory-BFVnMMCC.mjs.map +1 -0
  5. package/dist/Factory-BOX312yd.d.cts +147 -0
  6. package/dist/Factory-BOX312yd.d.cts.map +1 -0
  7. package/dist/Factory-BhjUOBWN.cjs +57 -0
  8. package/dist/Factory-BhjUOBWN.cjs.map +1 -0
  9. package/dist/Factory-SFupxRC2.d.mts +147 -0
  10. package/dist/Factory-SFupxRC2.d.mts.map +1 -0
  11. package/dist/Factory.cjs +2 -51
  12. package/dist/Factory.d.cts +3 -143
  13. package/dist/Factory.d.mts +3 -143
  14. package/dist/Factory.mjs +2 -50
  15. package/dist/KyselyFactory-BFqVIn_0.cjs +246 -0
  16. package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
  17. package/dist/KyselyFactory-DMswpwji.mjs +241 -0
  18. package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
  19. package/dist/KyselyFactory-Dy5zzV4B.d.cts +228 -0
  20. package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
  21. package/dist/KyselyFactory-vAxYodck.d.mts +228 -0
  22. package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
  23. package/dist/KyselyFactory.cjs +4 -237
  24. package/dist/KyselyFactory.d.cts +4 -224
  25. package/dist/KyselyFactory.d.mts +4 -224
  26. package/dist/KyselyFactory.mjs +4 -236
  27. package/dist/ObjectionFactory-BWjB49-i.d.mts +241 -0
  28. package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
  29. package/dist/ObjectionFactory-BeFBYcan.cjs +272 -0
  30. package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
  31. package/dist/ObjectionFactory-CD-WFuMJ.d.cts +241 -0
  32. package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
  33. package/dist/ObjectionFactory-QCJ7u0Ql.mjs +267 -0
  34. package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
  35. package/dist/ObjectionFactory.cjs +4 -265
  36. package/dist/ObjectionFactory.d.cts +4 -237
  37. package/dist/ObjectionFactory.d.mts +4 -237
  38. package/dist/ObjectionFactory.mjs +4 -264
  39. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +84 -0
  40. package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +1 -0
  41. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +101 -0
  42. package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +1 -0
  43. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +84 -0
  44. package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +1 -0
  45. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +95 -0
  46. package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +1 -0
  47. package/dist/PostgresKyselyMigrator.cjs +3 -94
  48. package/dist/PostgresKyselyMigrator.d.cts +3 -80
  49. package/dist/PostgresKyselyMigrator.d.mts +3 -80
  50. package/dist/PostgresKyselyMigrator.mjs +3 -93
  51. package/dist/{PostgresMigrator-CDPnnwMJ.d.cts → PostgresMigrator-C_QQ6q35.d.mts} +5 -11
  52. package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +1 -0
  53. package/dist/{PostgresMigrator-CDPnnwMJ.d.mts → PostgresMigrator-CeYy-eHF.d.cts} +5 -11
  54. package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +1 -0
  55. package/dist/PostgresMigrator-DVAY04qN.mjs +166 -0
  56. package/dist/PostgresMigrator-DVAY04qN.mjs.map +1 -0
  57. package/dist/PostgresMigrator-M9jpzOvN.cjs +172 -0
  58. package/dist/PostgresMigrator-M9jpzOvN.cjs.map +1 -0
  59. package/dist/PostgresMigrator.cjs +2 -178
  60. package/dist/PostgresMigrator.d.cts +1 -1
  61. package/dist/PostgresMigrator.d.mts +1 -1
  62. package/dist/PostgresMigrator.mjs +2 -175
  63. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +79 -0
  64. package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +1 -0
  65. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +79 -0
  66. package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +1 -0
  67. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +123 -0
  68. package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +1 -0
  69. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +118 -0
  70. package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +1 -0
  71. package/dist/PostgresObjectionMigrator.cjs +3 -118
  72. package/dist/PostgresObjectionMigrator.d.cts +3 -75
  73. package/dist/PostgresObjectionMigrator.d.mts +3 -75
  74. package/dist/PostgresObjectionMigrator.mjs +3 -117
  75. package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs +65 -0
  76. package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs.map +1 -0
  77. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts +59 -0
  78. package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
  79. package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs +60 -0
  80. package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs.map +1 -0
  81. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts +59 -0
  82. package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
  83. package/dist/VitestKyselyTransactionIsolator.cjs +3 -66
  84. package/dist/VitestKyselyTransactionIsolator.d.cts +3 -60
  85. package/dist/VitestKyselyTransactionIsolator.d.mts +3 -60
  86. package/dist/VitestKyselyTransactionIsolator.mjs +3 -65
  87. package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs +68 -0
  88. package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs.map +1 -0
  89. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts +60 -0
  90. package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
  91. package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs +63 -0
  92. package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs.map +1 -0
  93. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts +60 -0
  94. package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
  95. package/dist/VitestObjectionTransactionIsolator.cjs +3 -62
  96. package/dist/VitestObjectionTransactionIsolator.d.cts +3 -56
  97. package/dist/VitestObjectionTransactionIsolator.d.mts +3 -56
  98. package/dist/VitestObjectionTransactionIsolator.mjs +3 -61
  99. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts +207 -0
  100. package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
  101. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts +207 -0
  102. package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
  103. package/dist/VitestTransactionIsolator-CtZaOUjH.cjs +193 -0
  104. package/dist/VitestTransactionIsolator-CtZaOUjH.cjs.map +1 -0
  105. package/dist/VitestTransactionIsolator-D6ZxLWys.mjs +175 -0
  106. package/dist/VitestTransactionIsolator-D6ZxLWys.mjs.map +1 -0
  107. package/dist/VitestTransactionIsolator.cjs +4 -187
  108. package/dist/VitestTransactionIsolator.d.cts +2 -219
  109. package/dist/VitestTransactionIsolator.d.mts +2 -219
  110. package/dist/VitestTransactionIsolator.mjs +2 -184
  111. package/dist/aws.cjs +4 -3
  112. package/dist/aws.cjs.map +1 -1
  113. package/dist/aws.d.cts +8 -3
  114. package/dist/aws.d.cts.map +1 -1
  115. package/dist/aws.d.mts +8 -3
  116. package/dist/aws.d.mts.map +1 -1
  117. package/dist/aws.mjs +2 -1
  118. package/dist/aws.mjs.map +1 -1
  119. package/dist/benchmark.cjs +2 -2
  120. package/dist/benchmark.cjs.map +1 -1
  121. package/dist/benchmark.d.cts +6 -4
  122. package/dist/benchmark.d.cts.map +1 -1
  123. package/dist/benchmark.d.mts +6 -4
  124. package/dist/benchmark.d.mts.map +1 -1
  125. package/dist/benchmark.mjs +1 -1
  126. package/dist/benchmark.mjs.map +1 -1
  127. package/dist/better-auth.cjs +15 -31
  128. package/dist/better-auth.cjs.map +1 -1
  129. package/dist/better-auth.d.cts +4 -13142
  130. package/dist/better-auth.d.cts.map +1 -1
  131. package/dist/better-auth.d.mts +4 -13142
  132. package/dist/better-auth.d.mts.map +1 -1
  133. package/dist/better-auth.mjs +13 -29
  134. package/dist/better-auth.mjs.map +1 -1
  135. package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
  136. package/dist/directory-Bpz5c5pj.d.cts +13 -0
  137. package/dist/directory-Bpz5c5pj.d.cts.map +1 -0
  138. package/dist/directory-BxjqmtCT.mjs +27 -0
  139. package/dist/directory-BxjqmtCT.mjs.map +1 -0
  140. package/dist/directory-CVrfTq1I.d.mts +13 -0
  141. package/dist/directory-CVrfTq1I.d.mts.map +1 -0
  142. package/dist/directory-DD_xQoSh.cjs +33 -0
  143. package/dist/directory-DD_xQoSh.cjs.map +1 -0
  144. package/dist/faker-B14IEMIN.cjs +304 -0
  145. package/dist/faker-B14IEMIN.cjs.map +1 -0
  146. package/dist/faker-BGKYFoCT.mjs +262 -0
  147. package/dist/faker-BGKYFoCT.mjs.map +1 -0
  148. package/dist/faker-Cg76aFNO.d.cts +166 -0
  149. package/dist/faker-Cg76aFNO.d.cts.map +1 -0
  150. package/dist/faker-DHh7xs4u.d.mts +166 -0
  151. package/dist/faker-DHh7xs4u.d.mts.map +1 -0
  152. package/dist/faker.cjs +8 -313
  153. package/dist/faker.d.cts +2 -169
  154. package/dist/faker.d.mts +2 -169
  155. package/dist/faker.mjs +2 -305
  156. package/dist/helpers.cjs +5 -6
  157. package/dist/helpers.cjs.map +1 -1
  158. package/dist/helpers.d.cts +5 -1
  159. package/dist/helpers.d.cts.map +1 -1
  160. package/dist/helpers.d.mts +5 -1
  161. package/dist/helpers.d.mts.map +1 -1
  162. package/dist/helpers.mjs +2 -1
  163. package/dist/helpers.mjs.map +1 -1
  164. package/dist/initScript.cjs +15 -15
  165. package/dist/initScript.cjs.map +1 -1
  166. package/dist/initScript.d.cts +4 -2
  167. package/dist/initScript.d.cts.map +1 -1
  168. package/dist/initScript.d.mts +4 -2
  169. package/dist/initScript.d.mts.map +1 -1
  170. package/dist/initScript.mjs +12 -10
  171. package/dist/initScript.mjs.map +1 -1
  172. package/dist/kysely.cjs +13 -10
  173. package/dist/kysely.cjs.map +1 -1
  174. package/dist/kysely.d.cts +14 -10
  175. package/dist/kysely.d.cts.map +1 -1
  176. package/dist/kysely.d.mts +14 -10
  177. package/dist/kysely.d.mts.map +1 -1
  178. package/dist/kysely.mjs +14 -10
  179. package/dist/kysely.mjs.map +1 -1
  180. package/dist/logger.cjs +4 -3
  181. package/dist/logger.cjs.map +1 -1
  182. package/dist/logger.d.cts +5 -1
  183. package/dist/logger.d.cts.map +1 -1
  184. package/dist/logger.d.mts +5 -1
  185. package/dist/logger.d.mts.map +1 -1
  186. package/dist/logger.mjs +2 -1
  187. package/dist/logger.mjs.map +1 -1
  188. package/dist/objection.cjs +13 -10
  189. package/dist/objection.cjs.map +1 -1
  190. package/dist/objection.d.cts +14 -10
  191. package/dist/objection.d.cts.map +1 -1
  192. package/dist/objection.d.mts +14 -10
  193. package/dist/objection.d.mts.map +1 -1
  194. package/dist/objection.mjs +14 -10
  195. package/dist/objection.mjs.map +1 -1
  196. package/dist/os/directory.cjs +2 -31
  197. package/dist/os/directory.d.cts +2 -9
  198. package/dist/os/directory.d.mts +2 -9
  199. package/dist/os/directory.mjs +2 -25
  200. package/dist/os/index.cjs +3 -3
  201. package/dist/os/index.d.cts +1 -1
  202. package/dist/os/index.d.mts +1 -1
  203. package/dist/os/index.mjs +3 -2
  204. package/dist/requestContext.cjs +11 -10
  205. package/dist/requestContext.cjs.map +1 -1
  206. package/dist/requestContext.d.cts +9 -5
  207. package/dist/requestContext.d.cts.map +1 -1
  208. package/dist/requestContext.d.mts +9 -5
  209. package/dist/requestContext.d.mts.map +1 -1
  210. package/dist/requestContext.mjs +3 -2
  211. package/dist/requestContext.mjs.map +1 -1
  212. package/dist/timer.cjs +2 -2
  213. package/dist/timer.cjs.map +1 -1
  214. package/dist/timer.d.cts +4 -1
  215. package/dist/timer.d.cts.map +1 -1
  216. package/dist/timer.d.mts +4 -1
  217. package/dist/timer.d.mts.map +1 -1
  218. package/dist/timer.mjs +1 -1
  219. package/dist/timer.mjs.map +1 -1
  220. package/package.json +25 -65
  221. package/src/Factory.ts +174 -0
  222. package/src/KyselyFactory.ts +391 -0
  223. package/src/ObjectionFactory.ts +412 -0
  224. package/src/PostgresKyselyMigrator.ts +104 -0
  225. package/src/PostgresMigrator.ts +193 -0
  226. package/src/PostgresObjectionMigrator.ts +138 -0
  227. package/src/VitestKyselyTransactionIsolator.ts +72 -0
  228. package/src/VitestObjectionTransactionIsolator.ts +75 -0
  229. package/src/VitestTransactionIsolator.ts +348 -0
  230. package/src/__tests__/Factory.spec.ts +178 -0
  231. package/src/__tests__/KyselyFactory.spec.ts +458 -0
  232. package/src/__tests__/ObjectionFactory.spec.ts +586 -0
  233. package/src/__tests__/PostgresKyselyMigrator.spec.ts +794 -0
  234. package/src/__tests__/PostgresMigrator.spec.ts +471 -0
  235. package/src/__tests__/PostgresObjectionMigrator.spec.ts +634 -0
  236. package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +138 -0
  237. package/src/__tests__/benchmark.spec.ts +140 -0
  238. package/src/__tests__/better-auth.spec.ts +21 -0
  239. package/src/__tests__/faker.spec.ts +231 -0
  240. package/src/__tests__/initScript.spec.ts +332 -0
  241. package/src/__tests__/integration.spec.ts +610 -0
  242. package/src/__tests__/requestContext.spec.ts +113 -0
  243. package/src/__tests__/utilities.spec.ts +211 -0
  244. package/src/aws.ts +131 -0
  245. package/src/benchmark.ts +48 -0
  246. package/src/better-auth.ts +310 -0
  247. package/src/faker.ts +349 -0
  248. package/src/helpers.ts +45 -0
  249. package/src/initScript.ts +122 -0
  250. package/src/kysely.ts +166 -0
  251. package/src/logger.ts +18 -0
  252. package/src/objection.ts +157 -0
  253. package/src/os/directory.ts +26 -0
  254. package/src/os/index.ts +1 -0
  255. package/src/requestContext.ts +119 -0
  256. package/src/timer.ts +3 -0
  257. package/test/globalSetup.ts +54 -0
  258. package/test/helpers.ts +268 -0
  259. package/test/migrations/1749664623372_user.ts +22 -0
  260. package/tsconfig.json +9 -0
  261. package/vitest.config.ts +8 -0
  262. package/dist/Factory.cjs.map +0 -1
  263. package/dist/Factory.d.cts.map +0 -1
  264. package/dist/Factory.d.mts.map +0 -1
  265. package/dist/Factory.mjs.map +0 -1
  266. package/dist/KyselyFactory.cjs.map +0 -1
  267. package/dist/KyselyFactory.d.cts.map +0 -1
  268. package/dist/KyselyFactory.d.mts.map +0 -1
  269. package/dist/KyselyFactory.mjs.map +0 -1
  270. package/dist/ObjectionFactory.cjs.map +0 -1
  271. package/dist/ObjectionFactory.d.cts.map +0 -1
  272. package/dist/ObjectionFactory.d.mts.map +0 -1
  273. package/dist/ObjectionFactory.mjs.map +0 -1
  274. package/dist/PostgresKyselyMigrator.cjs.map +0 -1
  275. package/dist/PostgresKyselyMigrator.d.cts.map +0 -1
  276. package/dist/PostgresKyselyMigrator.d.mts.map +0 -1
  277. package/dist/PostgresKyselyMigrator.mjs.map +0 -1
  278. package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +0 -1
  279. package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +0 -1
  280. package/dist/PostgresMigrator.cjs.map +0 -1
  281. package/dist/PostgresMigrator.mjs.map +0 -1
  282. package/dist/PostgresObjectionMigrator.cjs.map +0 -1
  283. package/dist/PostgresObjectionMigrator.d.cts.map +0 -1
  284. package/dist/PostgresObjectionMigrator.d.mts.map +0 -1
  285. package/dist/PostgresObjectionMigrator.mjs.map +0 -1
  286. package/dist/VitestKyselyTransactionIsolator.cjs.map +0 -1
  287. package/dist/VitestKyselyTransactionIsolator.d.cts.map +0 -1
  288. package/dist/VitestKyselyTransactionIsolator.d.mts.map +0 -1
  289. package/dist/VitestKyselyTransactionIsolator.mjs.map +0 -1
  290. package/dist/VitestObjectionTransactionIsolator.cjs.map +0 -1
  291. package/dist/VitestObjectionTransactionIsolator.d.cts.map +0 -1
  292. package/dist/VitestObjectionTransactionIsolator.d.mts.map +0 -1
  293. package/dist/VitestObjectionTransactionIsolator.mjs.map +0 -1
  294. package/dist/VitestTransactionIsolator.cjs.map +0 -1
  295. package/dist/VitestTransactionIsolator.d.cts.map +0 -1
  296. package/dist/VitestTransactionIsolator.d.mts.map +0 -1
  297. package/dist/VitestTransactionIsolator.mjs.map +0 -1
  298. package/dist/browser.cjs +0 -149
  299. package/dist/browser.cjs.map +0 -1
  300. package/dist/browser.d.cts +0 -62
  301. package/dist/browser.d.cts.map +0 -1
  302. package/dist/browser.d.mts +0 -62
  303. package/dist/browser.d.mts.map +0 -1
  304. package/dist/browser.mjs +0 -147
  305. package/dist/browser.mjs.map +0 -1
  306. package/dist/context.cjs +0 -80
  307. package/dist/context.cjs.map +0 -1
  308. package/dist/context.d.cts +0 -55
  309. package/dist/context.d.cts.map +0 -1
  310. package/dist/context.d.mts +0 -55
  311. package/dist/context.d.mts.map +0 -1
  312. package/dist/context.mjs +0 -73
  313. package/dist/context.mjs.map +0 -1
  314. package/dist/faker.cjs.map +0 -1
  315. package/dist/faker.d.cts.map +0 -1
  316. package/dist/faker.d.mts.map +0 -1
  317. package/dist/faker.mjs.map +0 -1
  318. package/dist/mailbox.cjs +0 -95
  319. package/dist/mailbox.cjs.map +0 -1
  320. package/dist/mailbox.d.cts +0 -58
  321. package/dist/mailbox.d.cts.map +0 -1
  322. package/dist/mailbox.d.mts +0 -58
  323. package/dist/mailbox.d.mts.map +0 -1
  324. package/dist/mailbox.mjs +0 -92
  325. package/dist/mailbox.mjs.map +0 -1
  326. package/dist/os/directory.cjs.map +0 -1
  327. package/dist/os/directory.d.cts.map +0 -1
  328. package/dist/os/directory.d.mts.map +0 -1
  329. package/dist/os/directory.mjs.map +0 -1
  330. package/dist/transactions.cjs +0 -239
  331. package/dist/transactions.cjs.map +0 -1
  332. package/dist/transactions.d.cts +0 -44
  333. package/dist/transactions.d.cts.map +0 -1
  334. package/dist/transactions.d.mts +0 -44
  335. package/dist/transactions.d.mts.map +0 -1
  336. package/dist/transactions.mjs +0 -234
  337. package/dist/transactions.mjs.map +0 -1
@@ -0,0 +1,138 @@
1
+ import { Model } from 'objection';
2
+ import { it as base, describe, expect } from 'vitest';
3
+
4
+ import { createKnexDb, createTestTablesKnex } from '../../test/helpers';
5
+ import { wrapVitestObjectionTransaction } from '../objection';
6
+
7
+ // Define Objection models for testing
8
+ class User extends Model {
9
+ static get tableName() {
10
+ return 'users';
11
+ }
12
+
13
+ id!: number;
14
+ name!: string;
15
+ createdAt!: Date;
16
+ updatedAt?: Date;
17
+
18
+ static get relationMappings() {
19
+ return {
20
+ posts: {
21
+ relation: Model.HasManyRelation,
22
+ modelClass: Post,
23
+ join: {
24
+ from: 'users.id',
25
+ to: 'posts.user_id',
26
+ },
27
+ },
28
+ comments: {
29
+ relation: Model.HasManyRelation,
30
+ modelClass: Comment,
31
+ join: {
32
+ from: 'users.id',
33
+ to: 'comments.user_id',
34
+ },
35
+ },
36
+ };
37
+ }
38
+ }
39
+
40
+ class Post extends Model {
41
+ static get tableName() {
42
+ return 'posts';
43
+ }
44
+
45
+ id!: number;
46
+ title!: string;
47
+ content!: string;
48
+ userId!: number;
49
+ published?: boolean;
50
+ createdAt!: Date;
51
+ updatedAt?: Date;
52
+
53
+ static get relationMappings() {
54
+ return {
55
+ user: {
56
+ relation: Model.BelongsToOneRelation,
57
+ modelClass: User,
58
+ join: {
59
+ from: 'posts.user_id',
60
+ to: 'users.id',
61
+ },
62
+ },
63
+ comments: {
64
+ relation: Model.HasManyRelation,
65
+ modelClass: Comment,
66
+ join: {
67
+ from: 'posts.id',
68
+ to: 'comments.post_id',
69
+ },
70
+ },
71
+ };
72
+ }
73
+ }
74
+
75
+ class Comment extends Model {
76
+ static get tableName() {
77
+ return 'comments';
78
+ }
79
+
80
+ id!: number;
81
+ content!: string;
82
+ postId!: number;
83
+ userId!: number;
84
+ createdAt!: Date;
85
+
86
+ static get relationMappings() {
87
+ return {
88
+ post: {
89
+ relation: Model.BelongsToOneRelation,
90
+ modelClass: Post,
91
+ join: {
92
+ from: 'comments.post_id',
93
+ to: 'posts.id',
94
+ },
95
+ },
96
+ user: {
97
+ relation: Model.BelongsToOneRelation,
98
+ modelClass: User,
99
+ join: {
100
+ from: 'comments.user_id',
101
+ to: 'users.id',
102
+ },
103
+ },
104
+ };
105
+ }
106
+ }
107
+
108
+ // Create database connection
109
+
110
+ // Create wrapped test with transaction isolation
111
+ const it = wrapVitestObjectionTransaction(base, {
112
+ connection: createKnexDb,
113
+ setup: async (trx) => {
114
+ // Create tables in the transaction
115
+ await createTestTablesKnex(trx);
116
+ },
117
+ });
118
+
119
+ describe('VitestObjectionTransactionIsolator', () => {
120
+ describe('Transaction Isolation', () => {
121
+ it('should rollback data after test completes', async ({ trx }) => {
122
+ // Create a user within the transaction
123
+ const user = await User.query(trx).insert({
124
+ name: 'Test User',
125
+ });
126
+
127
+ expect(user).toBeDefined();
128
+ expect(user.id).toBeDefined();
129
+ expect(user.name).toBe('Test User');
130
+
131
+ // Verify user exists in transaction
132
+ const foundUser = await User.query(trx).findById(user.id);
133
+ expect(foundUser).toBeDefined();
134
+
135
+ // Data will be rolled back after this test
136
+ });
137
+ });
138
+ });
@@ -0,0 +1,140 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ generateCacheKeys,
4
+ generateIpAddresses,
5
+ generateTestData,
6
+ randomIpAddress,
7
+ } from '../benchmark';
8
+
9
+ describe('generateTestData', () => {
10
+ it('should generate the specified number of records', () => {
11
+ const data = generateTestData(5);
12
+ expect(data).toHaveLength(5);
13
+ });
14
+
15
+ it('should generate records with expected structure', () => {
16
+ const data = generateTestData(3);
17
+
18
+ for (const record of data) {
19
+ expect(record).toHaveProperty('id');
20
+ expect(record).toHaveProperty('name');
21
+ expect(record).toHaveProperty('value');
22
+ expect(typeof record.id).toBe('string');
23
+ expect(typeof record.name).toBe('string');
24
+ expect(typeof record.value).toBe('number');
25
+ }
26
+ });
27
+
28
+ it('should generate sequential IDs', () => {
29
+ const data = generateTestData(3);
30
+ expect(data[0].id).toBe('id-0');
31
+ expect(data[1].id).toBe('id-1');
32
+ expect(data[2].id).toBe('id-2');
33
+ });
34
+
35
+ it('should generate sequential names', () => {
36
+ const data = generateTestData(3);
37
+ expect(data[0].name).toBe('Item 0');
38
+ expect(data[1].name).toBe('Item 1');
39
+ expect(data[2].name).toBe('Item 2');
40
+ });
41
+
42
+ it('should generate random values between 0 and 1000', () => {
43
+ const data = generateTestData(100);
44
+
45
+ for (const record of data) {
46
+ expect(record.value).toBeGreaterThanOrEqual(0);
47
+ expect(record.value).toBeLessThan(1000);
48
+ }
49
+ });
50
+
51
+ it('should return empty array for count 0', () => {
52
+ const data = generateTestData(0);
53
+ expect(data).toEqual([]);
54
+ });
55
+ });
56
+
57
+ describe('generateCacheKeys', () => {
58
+ it('should generate the specified number of keys', () => {
59
+ const keys = generateCacheKeys('test', 5);
60
+ expect(keys).toHaveLength(5);
61
+ });
62
+
63
+ it('should use the provided prefix', () => {
64
+ const keys = generateCacheKeys('user', 3);
65
+ expect(keys[0]).toBe('user:0');
66
+ expect(keys[1]).toBe('user:1');
67
+ expect(keys[2]).toBe('user:2');
68
+ });
69
+
70
+ it('should return empty array for count 0', () => {
71
+ const keys = generateCacheKeys('test', 0);
72
+ expect(keys).toEqual([]);
73
+ });
74
+
75
+ it('should handle empty prefix', () => {
76
+ const keys = generateCacheKeys('', 2);
77
+ expect(keys[0]).toBe(':0');
78
+ expect(keys[1]).toBe(':1');
79
+ });
80
+ });
81
+
82
+ describe('generateIpAddresses', () => {
83
+ it('should generate the specified number of IPs', () => {
84
+ const ips = generateIpAddresses(5);
85
+ expect(ips).toHaveLength(5);
86
+ });
87
+
88
+ it('should use default subnet 192.168.1', () => {
89
+ const ips = generateIpAddresses(3);
90
+ expect(ips[0]).toBe('192.168.1.0');
91
+ expect(ips[1]).toBe('192.168.1.1');
92
+ expect(ips[2]).toBe('192.168.1.2');
93
+ });
94
+
95
+ it('should use custom subnet', () => {
96
+ const ips = generateIpAddresses(2, '10.0.0');
97
+ expect(ips[0]).toBe('10.0.0.0');
98
+ expect(ips[1]).toBe('10.0.0.1');
99
+ });
100
+
101
+ it('should wrap last octet at 256', () => {
102
+ const ips = generateIpAddresses(260);
103
+ expect(ips[0]).toBe('192.168.1.0');
104
+ expect(ips[255]).toBe('192.168.1.255');
105
+ expect(ips[256]).toBe('192.168.1.0'); // Wraps around
106
+ expect(ips[257]).toBe('192.168.1.1');
107
+ });
108
+
109
+ it('should return empty array for count 0', () => {
110
+ const ips = generateIpAddresses(0);
111
+ expect(ips).toEqual([]);
112
+ });
113
+ });
114
+
115
+ describe('randomIpAddress', () => {
116
+ it('should generate valid IP address format', () => {
117
+ const ip = randomIpAddress();
118
+ const parts = ip.split('.');
119
+
120
+ expect(parts).toHaveLength(4);
121
+
122
+ for (const part of parts) {
123
+ const num = Number.parseInt(part, 10);
124
+ expect(num).toBeGreaterThanOrEqual(0);
125
+ expect(num).toBeLessThanOrEqual(255);
126
+ }
127
+ });
128
+
129
+ it('should generate different IPs on multiple calls', () => {
130
+ const ips = new Set<string>();
131
+
132
+ // Generate 10 IPs and check we get at least some variation
133
+ for (let i = 0; i < 10; i++) {
134
+ ips.add(randomIpAddress());
135
+ }
136
+
137
+ // With random generation, we should get at least 2 unique IPs
138
+ expect(ips.size).toBeGreaterThan(1);
139
+ });
140
+ });
@@ -0,0 +1,21 @@
1
+ import { runAdapterTest } from 'better-auth/adapters/test';
2
+ import { afterAll, describe } from 'vitest';
3
+ import { memoryAdapter } from '../better-auth';
4
+
5
+ describe('Memory Adapter Tests', async () => {
6
+ afterAll(async () => {
7
+ // Run DB cleanup here...
8
+ });
9
+ const adapter = memoryAdapter({
10
+ debugLogs: {
11
+ // If your adapter config allows passing in debug logs, then pass this here.
12
+ isRunningAdapterTests: true, // This is our super secret flag to let us know to only log debug logs if a test fails.
13
+ },
14
+ });
15
+
16
+ await runAdapterTest({
17
+ getAdapter: async (betterAuthOptions = {}) => {
18
+ return adapter(betterAuthOptions);
19
+ },
20
+ });
21
+ });
@@ -0,0 +1,231 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest';
2
+ import { faker } from '../faker';
3
+
4
+ describe('faker', () => {
5
+ describe('sequence', () => {
6
+ beforeEach(() => {
7
+ faker.resetAllSequences();
8
+ });
9
+
10
+ it('should start from 1 for a new sequence', () => {
11
+ expect(faker.sequence()).toBe(1);
12
+ expect(faker.sequence('custom')).toBe(1);
13
+ });
14
+
15
+ it('should increment on each call', () => {
16
+ expect(faker.sequence()).toBe(1);
17
+ expect(faker.sequence()).toBe(2);
18
+ expect(faker.sequence()).toBe(3);
19
+ });
20
+
21
+ it('should maintain separate counters for different names', () => {
22
+ expect(faker.sequence('users')).toBe(1);
23
+ expect(faker.sequence('posts')).toBe(1);
24
+ expect(faker.sequence('users')).toBe(2);
25
+ expect(faker.sequence('posts')).toBe(2);
26
+ expect(faker.sequence('users')).toBe(3);
27
+ expect(faker.sequence('posts')).toBe(3);
28
+ });
29
+
30
+ it('should handle concurrent-like sequential calls', () => {
31
+ const results: number[] = [];
32
+ for (let i = 0; i < 100; i++) {
33
+ results.push(faker.sequence('concurrent'));
34
+ }
35
+
36
+ // Check that all values are unique and sequential
37
+ expect(results).toEqual(Array.from({ length: 100 }, (_, i) => i + 1));
38
+ });
39
+ });
40
+
41
+ describe('resetSequence', () => {
42
+ beforeEach(() => {
43
+ faker.resetAllSequences();
44
+ });
45
+
46
+ it('should reset a specific sequence to 0', () => {
47
+ faker.sequence('test');
48
+ faker.sequence('test');
49
+ expect(faker.sequence('test')).toBe(3);
50
+
51
+ faker.resetSequence('test');
52
+ expect(faker.sequence('test')).toBe(1);
53
+ });
54
+
55
+ it('should reset a specific sequence to a custom value', () => {
56
+ faker.sequence('test');
57
+ faker.resetSequence('test', 10);
58
+ expect(faker.sequence('test')).toBe(11);
59
+ });
60
+
61
+ it('should create a new sequence if it does not exist', () => {
62
+ faker.resetSequence('new', 5);
63
+ expect(faker.sequence('new')).toBe(6);
64
+ });
65
+
66
+ it('should not affect other sequences', () => {
67
+ faker.sequence('test1');
68
+ faker.sequence('test1');
69
+ faker.sequence('test2');
70
+
71
+ faker.resetSequence('test1');
72
+
73
+ expect(faker.sequence('test1')).toBe(1);
74
+ expect(faker.sequence('test2')).toBe(2);
75
+ });
76
+ });
77
+
78
+ describe('resetAllSequences', () => {
79
+ it('should reset all sequences', () => {
80
+ faker.sequence('test1');
81
+ faker.sequence('test1');
82
+ faker.sequence('test2');
83
+ faker.sequence('test2');
84
+ faker.sequence('test2');
85
+
86
+ faker.resetAllSequences();
87
+
88
+ expect(faker.sequence('test1')).toBe(1);
89
+ expect(faker.sequence('test2')).toBe(1);
90
+ expect(faker.sequence()).toBe(1);
91
+ });
92
+ });
93
+
94
+ describe('identifier', () => {
95
+ beforeEach(() => {
96
+ faker.resetAllSequences();
97
+ });
98
+
99
+ it('should include sequence number in identifier', () => {
100
+ const id1 = faker.identifier();
101
+ const id2 = faker.identifier();
102
+
103
+ // Both should be different because of the sequence
104
+ expect(id1).not.toBe(id2);
105
+
106
+ // Should end with sequence numbers
107
+ expect(id1).toMatch(/1$/);
108
+ expect(id2).toMatch(/2$/);
109
+ });
110
+
111
+ it('should use custom suffix when provided', () => {
112
+ const id = faker.identifier('customSuffix');
113
+ expect(id).toMatch(/\.customSuffix$/);
114
+ });
115
+ });
116
+
117
+ describe('timestamps', () => {
118
+ it('should return createdAt and updatedAt dates', () => {
119
+ const { createdAt, updatedAt } = faker.timestamps();
120
+
121
+ expect(createdAt).toBeInstanceOf(Date);
122
+ expect(updatedAt).toBeInstanceOf(Date);
123
+ expect(createdAt.getTime()).toBeLessThanOrEqual(updatedAt.getTime());
124
+ expect(updatedAt.getTime()).toBeLessThanOrEqual(Date.now());
125
+ });
126
+
127
+ it('should have milliseconds set to 0', () => {
128
+ const { createdAt, updatedAt } = faker.timestamps();
129
+
130
+ expect(createdAt.getMilliseconds()).toBe(0);
131
+ expect(updatedAt.getMilliseconds()).toBe(0);
132
+ });
133
+ });
134
+
135
+ describe('price', () => {
136
+ it('should return a number', () => {
137
+ const result = faker.price();
138
+ expect(typeof result).toBe('number');
139
+ expect(result).toBeGreaterThan(0);
140
+ });
141
+ });
142
+
143
+ describe('coordinates', () => {
144
+ const center = { lat: 40.7128, lng: -74.006 }; // New York City
145
+
146
+ describe('within', () => {
147
+ it('should generate a coordinate within the given radius', () => {
148
+ const radius = 1000; // 1km
149
+ const result = faker.coordinates.within(center, radius);
150
+
151
+ expect(result).toHaveProperty('lat');
152
+ expect(result).toHaveProperty('lng');
153
+ expect(typeof result.lat).toBe('number');
154
+ expect(typeof result.lng).toBe('number');
155
+
156
+ // Calculate distance using Haversine formula
157
+ const R = 6378137; // Earth's radius in meters
158
+ const dLat = ((result.lat - center.lat) * Math.PI) / 180;
159
+ const dLng = ((result.lng - center.lng) * Math.PI) / 180;
160
+ const a =
161
+ Math.sin(dLat / 2) * Math.sin(dLat / 2) +
162
+ Math.cos((center.lat * Math.PI) / 180) *
163
+ Math.cos((result.lat * Math.PI) / 180) *
164
+ Math.sin(dLng / 2) *
165
+ Math.sin(dLng / 2);
166
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
167
+ const distance = R * c;
168
+
169
+ expect(distance).toBeLessThanOrEqual(radius);
170
+ });
171
+
172
+ it('should generate different coordinates on multiple calls', () => {
173
+ const radius = 1000;
174
+ const results = Array.from({ length: 10 }, () =>
175
+ faker.coordinates.within(center, radius),
176
+ );
177
+
178
+ // Not all results should be identical
179
+ const uniqueLats = new Set(results.map((r) => r.lat));
180
+ expect(uniqueLats.size).toBeGreaterThan(1);
181
+ });
182
+ });
183
+
184
+ describe('outside', () => {
185
+ it('should generate a coordinate outside the minimum radius', () => {
186
+ const minRadius = 1000; // 1km
187
+ const maxRadius = 5000; // 5km
188
+ const result = faker.coordinates.outside(center, minRadius, maxRadius);
189
+
190
+ expect(result).toHaveProperty('lat');
191
+ expect(result).toHaveProperty('lng');
192
+ expect(typeof result.lat).toBe('number');
193
+ expect(typeof result.lng).toBe('number');
194
+
195
+ // Calculate distance using Haversine formula
196
+ const R = 6378137;
197
+ const dLat = ((result.lat - center.lat) * Math.PI) / 180;
198
+ const dLng = ((result.lng - center.lng) * Math.PI) / 180;
199
+ const a =
200
+ Math.sin(dLat / 2) * Math.sin(dLat / 2) +
201
+ Math.cos((center.lat * Math.PI) / 180) *
202
+ Math.cos((result.lat * Math.PI) / 180) *
203
+ Math.sin(dLng / 2) *
204
+ Math.sin(dLng / 2);
205
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
206
+ const distance = R * c;
207
+
208
+ expect(distance).toBeGreaterThanOrEqual(minRadius);
209
+ expect(distance).toBeLessThanOrEqual(maxRadius);
210
+ });
211
+
212
+ it('should generate different coordinates on multiple calls', () => {
213
+ const results = Array.from({ length: 10 }, () =>
214
+ faker.coordinates.outside(center, 1000, 5000),
215
+ );
216
+
217
+ const uniqueLats = new Set(results.map((r) => r.lat));
218
+ expect(uniqueLats.size).toBeGreaterThan(1);
219
+ });
220
+
221
+ it('should normalize longitude to valid range', () => {
222
+ // Use a center near the antimeridian
223
+ const pacificCenter = { lat: 0, lng: 179 };
224
+ const result = faker.coordinates.outside(pacificCenter, 100000, 500000);
225
+
226
+ expect(result.lng).toBeGreaterThanOrEqual(-180);
227
+ expect(result.lng).toBeLessThanOrEqual(180);
228
+ });
229
+ });
230
+ });
231
+ });