ddd-ts-kit 0.23.0 → 0.24.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 (311) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.fr.md +42 -7
  3. package/README.md +38 -6
  4. package/dist/check/canonical/stray-entry.d.ts +8 -0
  5. package/dist/check/canonical/stray-entry.d.ts.map +1 -0
  6. package/dist/check/canonical/stray-entry.js +75 -0
  7. package/dist/check/canonical/stray-entry.js.map +1 -0
  8. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  9. package/dist/check/catalogue/architecture-rules.js +2 -0
  10. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  11. package/dist/check/catalogue/default-severities.d.ts.map +1 -1
  12. package/dist/check/catalogue/default-severities.js +1 -0
  13. package/dist/check/catalogue/default-severities.js.map +1 -1
  14. package/dist/check/explain/clean-docs.js +1 -1
  15. package/dist/check/explain/clean-docs.js.map +1 -1
  16. package/dist/check/explain/persistence-docs.js +1 -1
  17. package/dist/check/explain/persistence-docs.js.map +1 -1
  18. package/dist/check/explain/tree-docs.d.ts.map +1 -1
  19. package/dist/check/explain/tree-docs.js +5 -0
  20. package/dist/check/explain/tree-docs.js.map +1 -1
  21. package/dist/check/fixtures/clean-fixtures.d.ts.map +1 -1
  22. package/dist/check/fixtures/clean-fixtures.js +16 -0
  23. package/dist/check/fixtures/clean-fixtures.js.map +1 -1
  24. package/dist/check/fixtures/tree-fixtures.d.ts.map +1 -1
  25. package/dist/check/fixtures/tree-fixtures.js +17 -0
  26. package/dist/check/fixtures/tree-fixtures.js.map +1 -1
  27. package/dist/check/migrations/drizzle-history-findings.js +1 -1
  28. package/dist/check/migrations/drizzle-history-findings.js.map +1 -1
  29. package/dist/check/rules/clean-function-size.js +10 -2
  30. package/dist/check/rules/clean-function-size.js.map +1 -1
  31. package/dist/check/rules/tree-closed.d.ts.map +1 -1
  32. package/dist/check/rules/tree-closed.js +4 -68
  33. package/dist/check/rules/tree-closed.js.map +1 -1
  34. package/dist/check/rules/tree-documented-paths.d.ts +3 -0
  35. package/dist/check/rules/tree-documented-paths.d.ts.map +1 -0
  36. package/dist/check/rules/tree-documented-paths.js +54 -0
  37. package/dist/check/rules/tree-documented-paths.js.map +1 -0
  38. package/dist/commands/doctor.d.ts +4 -0
  39. package/dist/commands/doctor.d.ts.map +1 -0
  40. package/dist/commands/doctor.js +15 -0
  41. package/dist/commands/doctor.js.map +1 -0
  42. package/dist/commands/drizzle-generate.d.ts +6 -1
  43. package/dist/commands/drizzle-generate.d.ts.map +1 -1
  44. package/dist/commands/drizzle-generate.js +39 -6
  45. package/dist/commands/drizzle-generate.js.map +1 -1
  46. package/dist/commands/plan-waves.d.ts +9 -0
  47. package/dist/commands/plan-waves.d.ts.map +1 -0
  48. package/dist/commands/plan-waves.js +36 -0
  49. package/dist/commands/plan-waves.js.map +1 -0
  50. package/dist/commands/status.d.ts +1 -0
  51. package/dist/commands/status.d.ts.map +1 -1
  52. package/dist/commands/status.js +4 -2
  53. package/dist/commands/status.js.map +1 -1
  54. package/dist/doctor/diagnose.d.ts +9 -0
  55. package/dist/doctor/diagnose.d.ts.map +1 -0
  56. package/dist/doctor/diagnose.js +34 -0
  57. package/dist/doctor/diagnose.js.map +1 -0
  58. package/dist/doctor/doctor-finding.d.ts +11 -0
  59. package/dist/doctor/doctor-finding.d.ts.map +1 -0
  60. package/dist/doctor/doctor-finding.js +2 -0
  61. package/dist/doctor/doctor-finding.js.map +1 -0
  62. package/dist/doctor/format-diagnosis.d.ts +4 -0
  63. package/dist/doctor/format-diagnosis.d.ts.map +1 -0
  64. package/dist/doctor/format-diagnosis.js +25 -0
  65. package/dist/doctor/format-diagnosis.js.map +1 -0
  66. package/dist/doctor/package-findings.d.ts +8 -0
  67. package/dist/doctor/package-findings.d.ts.map +1 -0
  68. package/dist/doctor/package-findings.js +21 -0
  69. package/dist/doctor/package-findings.js.map +1 -0
  70. package/dist/doctor/permission-findings.d.ts +5 -0
  71. package/dist/doctor/permission-findings.d.ts.map +1 -0
  72. package/dist/doctor/permission-findings.js +16 -0
  73. package/dist/doctor/permission-findings.js.map +1 -0
  74. package/dist/doctor/script-findings.d.ts +5 -0
  75. package/dist/doctor/script-findings.d.ts.map +1 -0
  76. package/dist/doctor/script-findings.js +12 -0
  77. package/dist/doctor/script-findings.js.map +1 -0
  78. package/dist/help/notes.d.ts +1 -1
  79. package/dist/help/notes.d.ts.map +1 -1
  80. package/dist/help/notes.js +25 -4
  81. package/dist/help/notes.js.map +1 -1
  82. package/dist/help/usage.d.ts +1 -1
  83. package/dist/help/usage.d.ts.map +1 -1
  84. package/dist/help/usage.js +3 -0
  85. package/dist/help/usage.js.map +1 -1
  86. package/dist/init/agent-permissions.d.ts +8 -0
  87. package/dist/init/agent-permissions.d.ts.map +1 -0
  88. package/dist/init/agent-permissions.js +55 -0
  89. package/dist/init/agent-permissions.js.map +1 -0
  90. package/dist/init/files/persistence-files.d.ts.map +1 -1
  91. package/dist/init/files/persistence-files.js +7 -1
  92. package/dist/init/files/persistence-files.js.map +1 -1
  93. package/dist/init/manifest/versions.js +24 -24
  94. package/dist/init/write-agent-settings.d.ts.map +1 -1
  95. package/dist/init/write-agent-settings.js +1 -54
  96. package/dist/init/write-agent-settings.js.map +1 -1
  97. package/dist/migration/branch-migration.d.ts +9 -0
  98. package/dist/migration/branch-migration.d.ts.map +1 -0
  99. package/dist/migration/branch-migration.js +2 -0
  100. package/dist/migration/branch-migration.js.map +1 -0
  101. package/dist/migration/branch-migrations.d.ts +16 -0
  102. package/dist/migration/branch-migrations.d.ts.map +1 -0
  103. package/dist/migration/branch-migrations.js +48 -0
  104. package/dist/migration/branch-migrations.js.map +1 -0
  105. package/dist/migration/delete-branch-migrations.d.ts +9 -0
  106. package/dist/migration/delete-branch-migrations.d.ts.map +1 -0
  107. package/dist/migration/delete-branch-migrations.js +23 -0
  108. package/dist/migration/delete-branch-migrations.js.map +1 -0
  109. package/dist/migration/drizzle-run.d.ts +7 -0
  110. package/dist/migration/drizzle-run.d.ts.map +1 -0
  111. package/dist/migration/drizzle-run.js +2 -0
  112. package/dist/migration/drizzle-run.js.map +1 -0
  113. package/dist/migration/drizzle-silent-failures.js +1 -1
  114. package/dist/migration/drizzle-silent-failures.js.map +1 -1
  115. package/dist/migration/find-project-formatter.d.ts +8 -0
  116. package/dist/migration/find-project-formatter.d.ts.map +1 -0
  117. package/dist/migration/find-project-formatter.js +52 -0
  118. package/dist/migration/find-project-formatter.js.map +1 -0
  119. package/dist/migration/format-written-files.d.ts +9 -0
  120. package/dist/migration/format-written-files.d.ts.map +1 -0
  121. package/dist/migration/format-written-files.js +32 -0
  122. package/dist/migration/format-written-files.js.map +1 -0
  123. package/dist/migration/generate-and-read.d.ts +6 -0
  124. package/dist/migration/generate-and-read.d.ts.map +1 -0
  125. package/dist/migration/generate-and-read.js +14 -0
  126. package/dist/migration/generate-and-read.js.map +1 -0
  127. package/dist/migration/index.d.ts +4 -0
  128. package/dist/migration/index.d.ts.map +1 -1
  129. package/dist/migration/index.js +4 -0
  130. package/dist/migration/index.js.map +1 -1
  131. package/dist/migration/known-primary-keys.d.ts +3 -0
  132. package/dist/migration/known-primary-keys.d.ts.map +1 -0
  133. package/dist/migration/known-primary-keys.js +2 -0
  134. package/dist/migration/known-primary-keys.js.map +1 -0
  135. package/dist/migration/migration-files.d.ts +7 -0
  136. package/dist/migration/migration-files.d.ts.map +1 -0
  137. package/dist/migration/migration-files.js +29 -0
  138. package/dist/migration/migration-files.js.map +1 -0
  139. package/dist/migration/plan-replay.d.ts +9 -0
  140. package/dist/migration/plan-replay.d.ts.map +1 -0
  141. package/dist/migration/plan-replay.js +68 -0
  142. package/dist/migration/plan-replay.js.map +1 -0
  143. package/dist/migration/previous-primary-keys.d.ts +9 -0
  144. package/dist/migration/previous-primary-keys.d.ts.map +1 -0
  145. package/dist/migration/previous-primary-keys.js +55 -0
  146. package/dist/migration/previous-primary-keys.js.map +1 -0
  147. package/dist/migration/primary-key-order-finding.d.ts +12 -0
  148. package/dist/migration/primary-key-order-finding.d.ts.map +1 -0
  149. package/dist/migration/primary-key-order-finding.js +2 -0
  150. package/dist/migration/primary-key-order-finding.js.map +1 -0
  151. package/dist/migration/primary-key-order-findings.d.ts +12 -0
  152. package/dist/migration/primary-key-order-findings.d.ts.map +1 -0
  153. package/dist/migration/primary-key-order-findings.js +55 -0
  154. package/dist/migration/primary-key-order-findings.js.map +1 -0
  155. package/dist/migration/project-formatter.d.ts +9 -0
  156. package/dist/migration/project-formatter.d.ts.map +1 -0
  157. package/dist/migration/project-formatter.js +2 -0
  158. package/dist/migration/project-formatter.js.map +1 -0
  159. package/dist/migration/replay-drizzle-migrations.d.ts +15 -0
  160. package/dist/migration/replay-drizzle-migrations.d.ts.map +1 -0
  161. package/dist/migration/replay-drizzle-migrations.js +63 -0
  162. package/dist/migration/replay-drizzle-migrations.js.map +1 -0
  163. package/dist/migration/replay-plan.d.ts +11 -0
  164. package/dist/migration/replay-plan.d.ts.map +1 -0
  165. package/dist/migration/replay-plan.js +2 -0
  166. package/dist/migration/replay-plan.js.map +1 -0
  167. package/dist/migration/replayed-name.d.ts +7 -0
  168. package/dist/migration/replayed-name.d.ts.map +1 -0
  169. package/dist/migration/replayed-name.js +12 -0
  170. package/dist/migration/replayed-name.js.map +1 -0
  171. package/dist/migration/sql-statement.d.ts +6 -0
  172. package/dist/migration/sql-statement.d.ts.map +1 -0
  173. package/dist/migration/sql-statement.js +2 -0
  174. package/dist/migration/sql-statement.js.map +1 -0
  175. package/dist/migration/sql-statements.d.ts +4 -0
  176. package/dist/migration/sql-statements.d.ts.map +1 -0
  177. package/dist/migration/sql-statements.js +36 -0
  178. package/dist/migration/sql-statements.js.map +1 -0
  179. package/dist/migration/table-change.d.ts +12 -0
  180. package/dist/migration/table-change.d.ts.map +1 -0
  181. package/dist/migration/table-change.js +2 -0
  182. package/dist/migration/table-change.js.map +1 -0
  183. package/dist/migration/table-changes.d.ts +9 -0
  184. package/dist/migration/table-changes.d.ts.map +1 -0
  185. package/dist/migration/table-changes.js +55 -0
  186. package/dist/migration/table-changes.js.map +1 -0
  187. package/dist/migration/tidy-written-migration.d.ts +5 -0
  188. package/dist/migration/tidy-written-migration.d.ts.map +1 -0
  189. package/dist/migration/tidy-written-migration.js +8 -0
  190. package/dist/migration/tidy-written-migration.js.map +1 -0
  191. package/dist/migration/wait-for-next-second.d.ts +6 -0
  192. package/dist/migration/wait-for-next-second.d.ts.map +1 -0
  193. package/dist/migration/wait-for-next-second.js +11 -0
  194. package/dist/migration/wait-for-next-second.js.map +1 -0
  195. package/dist/migration/warn-primary-key-order.d.ts +5 -0
  196. package/dist/migration/warn-primary-key-order.d.ts.map +1 -0
  197. package/dist/migration/warn-primary-key-order.js +16 -0
  198. package/dist/migration/warn-primary-key-order.js.map +1 -0
  199. package/dist/migration/written-migration.d.ts +9 -0
  200. package/dist/migration/written-migration.d.ts.map +1 -0
  201. package/dist/migration/written-migration.js +2 -0
  202. package/dist/migration/written-migration.js.map +1 -0
  203. package/dist/migration/written-paths.d.ts +3 -0
  204. package/dist/migration/written-paths.d.ts.map +1 -0
  205. package/dist/migration/written-paths.js +5 -0
  206. package/dist/migration/written-paths.js.map +1 -0
  207. package/dist/plan/aggregates-of.d.ts +6 -0
  208. package/dist/plan/aggregates-of.d.ts.map +1 -0
  209. package/dist/plan/aggregates-of.js +13 -0
  210. package/dist/plan/aggregates-of.js.map +1 -0
  211. package/dist/plan/batched-waves.d.ts +18 -0
  212. package/dist/plan/batched-waves.d.ts.map +1 -0
  213. package/dist/plan/batched-waves.js +73 -0
  214. package/dist/plan/batched-waves.js.map +1 -0
  215. package/dist/plan/cycles-of.d.ts +8 -0
  216. package/dist/plan/cycles-of.d.ts.map +1 -0
  217. package/dist/plan/cycles-of.js +30 -0
  218. package/dist/plan/cycles-of.js.map +1 -0
  219. package/dist/plan/format-plan.d.ts +4 -0
  220. package/dist/plan/format-plan.d.ts.map +1 -0
  221. package/dist/plan/format-plan.js +53 -0
  222. package/dist/plan/format-plan.js.map +1 -0
  223. package/dist/plan/merge-order.d.ts +8 -0
  224. package/dist/plan/merge-order.d.ts.map +1 -0
  225. package/dist/plan/merge-order.js +32 -0
  226. package/dist/plan/merge-order.js.map +1 -0
  227. package/dist/plan/plan-problems.d.ts +8 -0
  228. package/dist/plan/plan-problems.d.ts.map +1 -0
  229. package/dist/plan/plan-problems.js +57 -0
  230. package/dist/plan/plan-problems.js.map +1 -0
  231. package/dist/plan/plan-waves.d.ts +16 -0
  232. package/dist/plan/plan-waves.d.ts.map +1 -0
  233. package/dist/plan/plan-waves.js +23 -0
  234. package/dist/plan/plan-waves.js.map +1 -0
  235. package/dist/plan/rows-to-plan.d.ts +7 -0
  236. package/dist/plan/rows-to-plan.d.ts.map +1 -0
  237. package/dist/plan/rows-to-plan.js +19 -0
  238. package/dist/plan/rows-to-plan.js.map +1 -0
  239. package/dist/plan/wave-numbers.d.ts +8 -0
  240. package/dist/plan/wave-numbers.d.ts.map +1 -0
  241. package/dist/plan/wave-numbers.js +27 -0
  242. package/dist/plan/wave-numbers.js.map +1 -0
  243. package/dist/plan/wave-plan.d.ts +48 -0
  244. package/dist/plan/wave-plan.d.ts.map +1 -0
  245. package/dist/plan/wave-plan.js +2 -0
  246. package/dist/plan/wave-plan.js.map +1 -0
  247. package/dist/progress/format-progress.d.ts.map +1 -1
  248. package/dist/progress/format-progress.js +16 -1
  249. package/dist/progress/format-progress.js.map +1 -1
  250. package/dist/progress/progress.d.ts +11 -1
  251. package/dist/progress/progress.d.ts.map +1 -1
  252. package/dist/progress/read-progress.d.ts +6 -2
  253. package/dist/progress/read-progress.d.ts.map +1 -1
  254. package/dist/progress/read-progress.js +10 -5
  255. package/dist/progress/read-progress.js.map +1 -1
  256. package/dist/progress/status-row-of.d.ts +16 -0
  257. package/dist/progress/status-row-of.d.ts.map +1 -0
  258. package/dist/progress/status-row-of.js +23 -0
  259. package/dist/progress/status-row-of.js.map +1 -0
  260. package/dist/run.d.ts.map +1 -1
  261. package/dist/run.js +4 -0
  262. package/dist/run.js.map +1 -1
  263. package/dist/slice/changed-entries.d.ts +7 -0
  264. package/dist/slice/changed-entries.d.ts.map +1 -0
  265. package/dist/slice/changed-entries.js +20 -0
  266. package/dist/slice/changed-entries.js.map +1 -0
  267. package/dist/slice/changed-entry.d.ts +6 -0
  268. package/dist/slice/changed-entry.d.ts.map +1 -0
  269. package/dist/slice/changed-entry.js +2 -0
  270. package/dist/slice/changed-entry.js.map +1 -0
  271. package/dist/slice/format-slice-verification.d.ts.map +1 -1
  272. package/dist/slice/format-slice-verification.js +10 -0
  273. package/dist/slice/format-slice-verification.js.map +1 -1
  274. package/dist/slice/plan-staging.d.ts +13 -0
  275. package/dist/slice/plan-staging.d.ts.map +1 -0
  276. package/dist/slice/plan-staging.js +52 -0
  277. package/dist/slice/plan-staging.js.map +1 -0
  278. package/dist/slice/slice-verification.d.ts +3 -0
  279. package/dist/slice/slice-verification.d.ts.map +1 -1
  280. package/dist/slice/staging-plan.d.ts +6 -0
  281. package/dist/slice/staging-plan.d.ts.map +1 -0
  282. package/dist/slice/staging-plan.js +2 -0
  283. package/dist/slice/staging-plan.js.map +1 -0
  284. package/dist/slice/verify-slice.d.ts.map +1 -1
  285. package/dist/slice/verify-slice.js +3 -2
  286. package/dist/slice/verify-slice.js.map +1 -1
  287. package/dist/version.d.ts +1 -1
  288. package/dist/version.js +1 -1
  289. package/dist/worker/briefing-of.js +1 -1
  290. package/dist/worker/briefing-of.js.map +1 -1
  291. package/dist/worker/rows-on-branches.d.ts +8 -0
  292. package/dist/worker/rows-on-branches.d.ts.map +1 -0
  293. package/dist/worker/rows-on-branches.js +9 -0
  294. package/dist/worker/rows-on-branches.js.map +1 -0
  295. package/package.json +2 -2
  296. package/templates/e2e/e2e.spec.ts.tpl +2 -2
  297. package/templates/init/e2e/start-application.database.ts.tpl +30 -1
  298. package/templates/init/e2e/start-application.memory.ts.tpl +30 -1
  299. package/templates/init/e2e/vitest.e2e.config.ts.tpl +4 -0
  300. package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +18 -1
  301. package/templates/init/platform/database/open-test-database.knex.ts.tpl +18 -1
  302. package/templates/init/platform/database/open-test-database.prisma.ts.tpl +18 -1
  303. package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +18 -1
  304. package/templates/init/platform/database/test-database-template.ts.tpl +23 -0
  305. package/templates/init/rules/tests.md.tpl +1 -1
  306. package/templates/pipeline/package-scripts.json +1 -1
  307. package/templates/pipeline/vitest.config.ts.tpl +6 -0
  308. package/dist/slice/paths-to-stage.d.ts +0 -6
  309. package/dist/slice/paths-to-stage.d.ts.map +0 -1
  310. package/dist/slice/paths-to-stage.js +0 -13
  311. package/dist/slice/paths-to-stage.js.map +0 -1
@@ -7,7 +7,7 @@ import { InMemoryCachePurger, PurgingPublisher, type IntegrationEventSubscriber
7
7
  {{#unless httpCache.varnish}}
8
8
  import type { IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
9
9
  {{/unless}}
10
- import { createHttpClient, type HttpClient } from '@ddd-ts-kit/testing/e2e';
10
+ import { createHttpClient, settled, type HttpClient, type SettledOptions } from '@ddd-ts-kit/testing/e2e';
11
11
  {{#if authz.rebac}}
12
12
  import { relationTuples } from '{{alias.platform}}/auth/relation-tuples{{alias.ext}}';
13
13
  {{/if}}
@@ -60,6 +60,25 @@ export interface RunningApplication {
60
60
 
61
61
  /** A client presenting the credential of `actor`; `client` itself presents none. */
62
62
  as(actor: TestActor): Promise<HttpClient>;
63
+
64
+ /**
65
+ {{#if events.outbox}}
66
+ * Resolves once the work the requests so far started has settled: every event stored in the
67
+ * outbox relayed, and the handlers it reached run, with what they stored in turn. Await it
68
+ * before asserting what happens after the answer, instead of waiting a fixed time; it fails
69
+ * after `timeoutMs` (2 seconds by default) naming what is still pending, and how much of it
70
+ * failed and waits for a retry (a handler that throws, an adapter that cannot be reached).
71
+ {{#if broker.provided}}
72
+ * With a broker server (its URL in the environment), relayed means handed to the broker: what
73
+ * its consumers do next is awaited with `collectEvents(application.events, [...]).waitFor(...)`.
74
+ {{/if}}
75
+ {{/if}}
76
+ {{#unless events.outbox}}
77
+ * Resolves once the work the requests so far started has settled. Without an outbox, events go
78
+ * out with the commit and their handlers are awaited before the answer: nothing is left then.
79
+ {{/unless}}
80
+ */
81
+ settled(options?: SettledOptions): Promise<void>;
63
82
  {{#if authz.rebac}}
64
83
 
65
84
  /** Stores a relationship, as the application does when an element is created or shared. */
@@ -93,6 +112,7 @@ export async function startApplication(): Promise<RunningApplication> {
93
112
  {{#if authz.rebac}}
94
113
  relate: (tuple) => relationTuples.write([tuple]),
95
114
  {{/if}}
115
+ settled: (options) => current.settled(options),
96
116
  reset: async () => {
97
117
  await current.close();
98
118
  current = await start(credentials);
@@ -108,6 +128,8 @@ interface Started {
108
128
  readonly purges: InMemoryCachePurger;
109
129
  {{/if}}
110
130
 
131
+ settled(options?: SettledOptions): Promise<void>;
132
+
111
133
  close(): Promise<void>;
112
134
  }
113
135
 
@@ -155,6 +177,13 @@ async function start(credentials: Credentials): Promise<Started> {
155
177
  {{#if httpCache.varnish}}
156
178
  purges,
157
179
  {{/if}}
180
+ {{#if events.outbox}}
181
+ settled: (options) => settled({ outbox: () => persistence.outbox.stats() }, options),
182
+ {{/if}}
183
+ {{#unless events.outbox}}
184
+ // Without an outbox nothing runs after the answer: the events went out with the commit.
185
+ settled: (options) => settled({}, options),
186
+ {{/unless}}
158
187
  close: async () => {
159
188
  await server.close();
160
189
  {{#if events.outbox}}
@@ -19,6 +19,10 @@ export default defineConfig({
19
19
  // Each file starts its own application; on a shared server (DATABASE_URL) they would
20
20
  // empty each other's tables, so they run one after the other there.
21
21
  fileParallelism: (process.env['DATABASE_URL'] ?? '') === '',
22
+ {{#if persistence.hasDatabase}}
23
+ // Initialises PostgreSQL in process once: each application starts on a copy of that cluster, and creates its tables there.
24
+ globalSetup: ['test/support/test-database-template.ts'],
25
+ {{/if}}
22
26
  testTimeout: 20_000,
23
27
  hookTimeout: 30_000,
24
28
  },
@@ -1,3 +1,6 @@
1
+ {{#if tests.vitest}}
2
+ import { openAsBlob } from 'node:fs';
3
+ {{/if}}
1
4
  import { PGlite } from '@electric-sql/pglite';
2
5
  import { is, sql, SQL } from 'drizzle-orm';
3
6
  import { getTableConfig, PgDialect, PgTable } from 'drizzle-orm/pg-core';
@@ -30,7 +33,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
33
  }
31
34
 
32
35
  async function openInProcess(): Promise<TestDatabase> {
33
- const client = new PGlite();
36
+ const client = await {{#if tests.vitest}}startedPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
34
37
 
35
38
  {{#if audit.on}}
36
39
  for (const statement of [...tables().flatMap(createStatements), ...auditGuardStatements(schema.AUDIT_SCHEMA)]) {
@@ -52,6 +55,20 @@ async function openInProcess(): Promise<TestDatabase> {
52
55
  };
53
56
  }
54
57
 
58
+ {{#if tests.vitest}}
59
+ /**
60
+ * PostgreSQL in process: a copy of the cluster the global setup of the run initialised once
61
+ * (test/support/test-database-template.ts), which spares each spec the initdb of its own; without
62
+ * one (a run that names no global setup), a cluster initialised here. The tables are created on it
63
+ * by the caller, every time, as the first migration creates them.
64
+ */
65
+ async function startedPostgres(): Promise<PGlite> {
66
+ const template = process.env['TEST_DATABASE_TEMPLATE'];
67
+
68
+ return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
69
+ }
70
+
71
+ {{/if}}
55
72
  async function openServer(url: string): Promise<TestDatabase> {
56
73
  const connection = connectToDatabase(url);
57
74
 
@@ -1,3 +1,6 @@
1
+ {{#if tests.vitest}}
2
+ import { openAsBlob } from 'node:fs';
3
+ {{/if}}
1
4
  import { PGlite } from '@electric-sql/pglite';
2
5
  import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
3
6
  import type { Knex } from 'knex';
@@ -30,7 +33,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
30
33
  }
31
34
 
32
35
  async function openInProcess(): Promise<TestDatabase> {
33
- const engine = await PGlite.create();
36
+ const engine = await {{#if tests.vitest}}startedPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
34
37
  const server = new PGLiteSocketServer({ db: engine, host: '127.0.0.1', port: 0, maxConnections: 10 });
35
38
 
36
39
  await server.start();
@@ -51,6 +54,20 @@ async function openInProcess(): Promise<TestDatabase> {
51
54
  return { persistence: persistenceOver(connection.db, close), reset: () => truncateAll(connection.db), close };
52
55
  }
53
56
 
57
+ {{#if tests.vitest}}
58
+ /**
59
+ * PostgreSQL in process: a copy of the cluster the global setup of the run initialised once
60
+ * (test/support/test-database-template.ts), which spares each spec the initdb of its own; without
61
+ * one (a run that names no global setup), a cluster initialised here. The tables are created on it
62
+ * by the caller, every time, as the first migration creates them.
63
+ */
64
+ async function startedPostgres(): Promise<PGlite> {
65
+ const template = process.env['TEST_DATABASE_TEMPLATE'];
66
+
67
+ return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
68
+ }
69
+
70
+ {{/if}}
54
71
  async function openServer(url: string): Promise<TestDatabase> {
55
72
  const connection = connectToDatabase(url);
56
73
 
@@ -1,3 +1,6 @@
1
+ {{#if tests.vitest}}
2
+ import { openAsBlob } from 'node:fs';
3
+ {{/if}}
1
4
  import { readFile } from 'node:fs/promises';
2
5
  import { PGlite } from '@electric-sql/pglite';
3
6
  import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
@@ -27,7 +30,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
27
30
  }
28
31
 
29
32
  async function openInProcess(): Promise<TestDatabase> {
30
- const engine = await PGlite.create();
33
+ const engine = await {{#if tests.vitest}}startedPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
31
34
  const server = new PGLiteSocketServer({ db: engine, host: '127.0.0.1', port: 0, maxConnections: 10 });
32
35
 
33
36
  await server.start();
@@ -48,6 +51,20 @@ async function openInProcess(): Promise<TestDatabase> {
48
51
  return { persistence: persistenceOver(client), reset: () => truncateAll(client), close };
49
52
  }
50
53
 
54
+ {{#if tests.vitest}}
55
+ /**
56
+ * PostgreSQL in process: a copy of the cluster the global setup of the run initialised once
57
+ * (test/support/test-database-template.ts), which spares each spec the initdb of its own; without
58
+ * one (a run that names no global setup), a cluster initialised here. The tables are created on it
59
+ * by the caller, every time, as the first migration creates them.
60
+ */
61
+ async function startedPostgres(): Promise<PGlite> {
62
+ const template = process.env['TEST_DATABASE_TEMPLATE'];
63
+
64
+ return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
65
+ }
66
+
67
+ {{/if}}
51
68
  async function openServer(url: string): Promise<TestDatabase> {
52
69
  const client = createClient(url);
53
70
 
@@ -1,3 +1,6 @@
1
+ {{#if tests.vitest}}
2
+ import { openAsBlob } from 'node:fs';
3
+ {{/if}}
1
4
  import { PGlite } from '@electric-sql/pglite';
2
5
  import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
3
6
  import type { DataSource } from 'typeorm';
@@ -24,7 +27,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
24
27
  }
25
28
 
26
29
  async function openInProcess(): Promise<TestDatabase> {
27
- const engine = await PGlite.create();
30
+ const engine = await {{#if tests.vitest}}startedPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
28
31
  const server = new PGLiteSocketServer({ db: engine, host: '127.0.0.1', port: 0, maxConnections: 10 });
29
32
 
30
33
  await server.start();
@@ -48,6 +51,20 @@ async function openInProcess(): Promise<TestDatabase> {
48
51
  return { persistence, reset: () => truncateAll(dataSource), close };
49
52
  }
50
53
 
54
+ {{#if tests.vitest}}
55
+ /**
56
+ * PostgreSQL in process: a copy of the cluster the global setup of the run initialised once
57
+ * (test/support/test-database-template.ts), which spares each spec the initdb of its own; without
58
+ * one (a run that names no global setup), a cluster initialised here. The tables are created on it
59
+ * by the caller, every time, as the first migration creates them.
60
+ */
61
+ async function startedPostgres(): Promise<PGlite> {
62
+ const template = process.env['TEST_DATABASE_TEMPLATE'];
63
+
64
+ return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
65
+ }
66
+
67
+ {{/if}}
51
68
  async function openServer(url: string): Promise<TestDatabase> {
52
69
  const dataSource = createDataSource(url);
53
70
 
@@ -0,0 +1,23 @@
1
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import path from 'node:path';
4
+ import { PGlite } from '@electric-sql/pglite';
5
+
6
+ /**
7
+ * The global setup of the test runs (vitest.config.ts, vitest.e2e.config.ts): starts PostgreSQL in
8
+ * process once and saves its initialised cluster to a file. Each spec of the run opens a copy of it
9
+ * (open-test-database.ts) instead of running an initdb of its own, the slow part of starting, then
10
+ * creates its tables there, so that what creates them stays run and measured in every spec. What it
11
+ * resolves is the teardown, which deletes the file.
12
+ */
13
+ export async function setup(): Promise<() => Promise<void>> {
14
+ const directory = await mkdtemp(path.join(tmpdir(), 'test-database-'));
15
+ const file = path.join(directory, 'cluster.tar');
16
+ const engine = await PGlite.create();
17
+
18
+ await writeFile(file, new Uint8Array(await (await engine.dumpDataDir('none')).arrayBuffer()));
19
+ await engine.close();
20
+ process.env['TEST_DATABASE_TEMPLATE'] = file;
21
+
22
+ return () => rm(directory, { recursive: true, force: true });
23
+ }
@@ -23,5 +23,5 @@ paths:
23
23
  - Coverage is a floor per context and layer, read from `coverage` in `ddd-ts-kit.config.json` and held by `npm run verify` (`npm run test:coverage`): a layer under its threshold gets the test that is missing. No `exclude` in the runner config, no `v8 ignore` or `istanbul ignore` comment without `-- ADR-NNNN: <reason>` (`test/coverage-governed`); a rate proves that code ran, never that a test asserts anything.
24
24
  - An `it.todo` left by the generator names a behaviour still to prove: replace it by a real test, do not delete it. `npx ddd-ts-kit todo <context>` lists what remains.
25
25
  - A test never asserts on a private field; it observes results, recorded events and what the fakes received.
26
- - `test/e2e/` (project root) drives the whole application through HTTP with generated, seeded data, never reads the database, and asserts the trace of a request with `expectSpanTree(storyOf(trace), [...])`.
26
+ - `test/e2e/` (project root) drives the whole application through HTTP with generated, seeded data, never reads the database, and asserts the trace of a request with `expectSpanTree(storyOf(trace), [...])`. What happens after the answer (the outbox relayed, the handlers it reaches) is asserted once `await application.settled()` has resolved, never after a fixed delay.
27
27
  - Write tests with `/ddd-ts-kit:testing`; scaffold with `npx ddd-ts-kit generate builder|e2e`.
@@ -23,7 +23,7 @@
23
23
  "@biomejs/biome": "2.5.15",
24
24
  "@commitlint/cli": "^21.2.3",
25
25
  "@commitlint/config-conventional": "^21.2.3",
26
- "@ddd-ts-kit/eslint-plugin": "^0.23.0",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.24.0",
27
27
  "@eslint/js": "^10.0.1",
28
28
  "@typescript/native": "npm:typescript@~7.0.2",
29
29
  "@vitest/coverage-v8": "5.0.3",
@@ -45,7 +45,13 @@ export default defineConfig(({ mode }) => ({
45
45
  name: INTEGRATION_MODE,
46
46
  include: [INTEGRATION_SPECS],
47
47
  exclude: NOT_AFFECTED,
48
+ {{#if persistence.hasDatabase}}
49
+ globalSetup: ['test/support/test-database-template.ts'],
50
+ // A hook opens a copy of the PostgreSQL cluster the global setup initialised once per run and creates its tables, or reaches a server: under coverage on a busy machine it can outlast the default 10 seconds.
51
+ {{/if}}
52
+ {{#unless persistence.hasDatabase}}
48
53
  // A hook opens the test database (PGlite started and its tables created, or a server reached): under coverage on a busy machine it outlasts the default 10 seconds.
54
+ {{/unless}}
49
55
  hookTimeout: 60_000,
50
56
  },
51
57
  },
@@ -1,6 +0,0 @@
1
- /**
2
- * The paths a slice leaves to commit, modified or new, as `git add <path>` takes them one by one;
3
- * the kit's own working files (`.ddd-ts-kit/`) are left out.
4
- */
5
- export declare function pathsToStage(root: string): string[];
6
- //# sourceMappingURL=paths-to-stage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"paths-to-stage.d.ts","sourceRoot":"","sources":["../../src/slice/paths-to-stage.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMnD"}
@@ -1,13 +0,0 @@
1
- import { runGit } from '../commit/run-git.js';
2
- /**
3
- * The paths a slice leaves to commit, modified or new, as `git add <path>` takes them one by one;
4
- * the kit's own working files (`.ddd-ts-kit/`) are left out.
5
- */
6
- export function pathsToStage(root) {
7
- return (runGit(root, ['status', '--porcelain', '--untracked-files=all']) ?? '')
8
- .split('\n')
9
- .filter((line) => line.length > 3)
10
- .map((line) => line.slice(3).replace(/^.* -> /, ''))
11
- .filter((file) => !file.startsWith('.ddd-ts-kit/'));
12
- }
13
- //# sourceMappingURL=paths-to-stage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"paths-to-stage.js","sourceRoot":"","sources":["../../src/slice/paths-to-stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,uBAAuB,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5E,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;SACjC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;SACnD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;AACxD,CAAC"}