ddd-ts-kit 0.96.0 → 0.98.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 (266) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.fr.md +9 -7
  3. package/README.md +8 -6
  4. package/dist/check/authz/operator-tuples.d.ts +16 -0
  5. package/dist/check/authz/operator-tuples.d.ts.map +1 -0
  6. package/dist/check/authz/operator-tuples.js +29 -0
  7. package/dist/check/authz/operator-tuples.js.map +1 -0
  8. package/dist/check/authz/own-authorizer.d.ts +9 -0
  9. package/dist/check/authz/own-authorizer.d.ts.map +1 -0
  10. package/dist/check/authz/own-authorizer.js +15 -0
  11. package/dist/check/authz/own-authorizer.js.map +1 -0
  12. package/dist/check/canonical/stray-entry.d.ts.map +1 -1
  13. package/dist/check/canonical/stray-entry.js +14 -2
  14. package/dist/check/canonical/stray-entry.js.map +1 -1
  15. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  16. package/dist/check/catalogue/architecture-rules.js +4 -0
  17. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  18. package/dist/check/domain-events/event-handlers-of.d.ts.map +1 -1
  19. package/dist/check/domain-events/event-handlers-of.js +21 -8
  20. package/dist/check/domain-events/event-handlers-of.js.map +1 -1
  21. package/dist/check/events/consumer-registrations.d.ts +2 -0
  22. package/dist/check/events/consumer-registrations.d.ts.map +1 -1
  23. package/dist/check/events/consumer-registrations.js +44 -2
  24. package/dist/check/events/consumer-registrations.js.map +1 -1
  25. package/dist/check/explain/authz-docs.d.ts.map +1 -1
  26. package/dist/check/explain/authz-docs.js +12 -1
  27. package/dist/check/explain/authz-docs.js.map +1 -1
  28. package/dist/check/explain/events-docs.js +1 -1
  29. package/dist/check/explain/events-docs.js.map +1 -1
  30. package/dist/check/explain/scheduling-docs.d.ts.map +1 -1
  31. package/dist/check/explain/scheduling-docs.js +22 -0
  32. package/dist/check/explain/scheduling-docs.js.map +1 -1
  33. package/dist/check/explain/tree-docs.d.ts.map +1 -1
  34. package/dist/check/explain/tree-docs.js +7 -4
  35. package/dist/check/explain/tree-docs.js.map +1 -1
  36. package/dist/check/explain/wiring-docs.js +1 -1
  37. package/dist/check/explain/wiring-docs.js.map +1 -1
  38. package/dist/check/fixtures/authz-granted-fixtures.d.ts.map +1 -1
  39. package/dist/check/fixtures/authz-granted-fixtures.js +69 -0
  40. package/dist/check/fixtures/authz-granted-fixtures.js.map +1 -1
  41. package/dist/check/fixtures/authz-resource-modelled-fixtures.d.ts.map +1 -1
  42. package/dist/check/fixtures/authz-resource-modelled-fixtures.js +5 -0
  43. package/dist/check/fixtures/authz-resource-modelled-fixtures.js.map +1 -1
  44. package/dist/check/fixtures/authz-system-actor-granted-fixtures.d.ts +3 -0
  45. package/dist/check/fixtures/authz-system-actor-granted-fixtures.d.ts.map +1 -0
  46. package/dist/check/fixtures/authz-system-actor-granted-fixtures.js +89 -0
  47. package/dist/check/fixtures/authz-system-actor-granted-fixtures.js.map +1 -0
  48. package/dist/check/fixtures/consumer-fixtures.d.ts.map +1 -1
  49. package/dist/check/fixtures/consumer-fixtures.js +33 -0
  50. package/dist/check/fixtures/consumer-fixtures.js.map +1 -1
  51. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  52. package/dist/check/fixtures/fixtures.js +2 -0
  53. package/dist/check/fixtures/fixtures.js.map +1 -1
  54. package/dist/check/fixtures/scheduling-fixtures.d.ts.map +1 -1
  55. package/dist/check/fixtures/scheduling-fixtures.js +47 -1
  56. package/dist/check/fixtures/scheduling-fixtures.js.map +1 -1
  57. package/dist/check/project/locate.js +9 -3
  58. package/dist/check/project/locate.js.map +1 -1
  59. package/dist/check/rules/authz-granted.d.ts +19 -6
  60. package/dist/check/rules/authz-granted.d.ts.map +1 -1
  61. package/dist/check/rules/authz-granted.js +59 -7
  62. package/dist/check/rules/authz-granted.js.map +1 -1
  63. package/dist/check/rules/authz-system-actor-granted.d.ts +15 -0
  64. package/dist/check/rules/authz-system-actor-granted.d.ts.map +1 -0
  65. package/dist/check/rules/authz-system-actor-granted.js +91 -0
  66. package/dist/check/rules/authz-system-actor-granted.js.map +1 -0
  67. package/dist/check/rules/composition-only-in-module.js +2 -2
  68. package/dist/check/rules/composition-only-in-module.js.map +1 -1
  69. package/dist/check/rules/declarations-port-adapter-wired.js +1 -1
  70. package/dist/check/rules/declarations-port-adapter-wired.js.map +1 -1
  71. package/dist/check/rules/events-consumer-idempotent.d.ts.map +1 -1
  72. package/dist/check/rules/events-consumer-idempotent.js +6 -3
  73. package/dist/check/rules/events-consumer-idempotent.js.map +1 -1
  74. package/dist/check/rules/scheduling-job-registered.d.ts +12 -0
  75. package/dist/check/rules/scheduling-job-registered.d.ts.map +1 -0
  76. package/dist/check/rules/scheduling-job-registered.js +40 -0
  77. package/dist/check/rules/scheduling-job-registered.js.map +1 -0
  78. package/dist/check/rules/tree-closed.js +1 -1
  79. package/dist/check/rules/tree-closed.js.map +1 -1
  80. package/dist/check/scheduling/job-classes.d.ts +13 -0
  81. package/dist/check/scheduling/job-classes.d.ts.map +1 -0
  82. package/dist/check/scheduling/job-classes.js +32 -0
  83. package/dist/check/scheduling/job-classes.js.map +1 -0
  84. package/dist/commands/generate.js +3 -1
  85. package/dist/commands/generate.js.map +1 -1
  86. package/dist/commands/prisma-generate.d.ts.map +1 -1
  87. package/dist/commands/prisma-generate.js +2 -1
  88. package/dist/commands/prisma-generate.js.map +1 -1
  89. package/dist/commands/typeorm-generate.d.ts.map +1 -1
  90. package/dist/commands/typeorm-generate.js +2 -1
  91. package/dist/commands/typeorm-generate.js.map +1 -1
  92. package/dist/describe/context-sources.d.ts +1 -1
  93. package/dist/describe/context-sources.d.ts.map +1 -1
  94. package/dist/describe/describe-context.js +2 -2
  95. package/dist/describe/describe-context.js.map +1 -1
  96. package/dist/docs/personal-declarations-in.js +6 -1
  97. package/dist/docs/personal-declarations-in.js.map +1 -1
  98. package/dist/docs/personal-table-cells.js +7 -1
  99. package/dist/docs/personal-table-cells.js.map +1 -1
  100. package/dist/docs/personal-table-facts.d.ts +1 -1
  101. package/dist/docs/personal-table-facts.d.ts.map +1 -1
  102. package/dist/docs/read-jobs.d.ts +1 -1
  103. package/dist/docs/read-jobs.d.ts.map +1 -1
  104. package/dist/docs/read-jobs.js +3 -3
  105. package/dist/docs/read-jobs.js.map +1 -1
  106. package/dist/generate/apply-wiring.js +1 -1
  107. package/dist/generate/apply-wiring.js.map +1 -1
  108. package/dist/generate/kind.d.ts +2 -0
  109. package/dist/generate/kind.d.ts.map +1 -1
  110. package/dist/generate/kinds/adapter-kind.js +2 -2
  111. package/dist/generate/kinds/adapter-kind.js.map +1 -1
  112. package/dist/generate/kinds/ask-policy-in-generated-use-case.d.ts.map +1 -1
  113. package/dist/generate/kinds/ask-policy-in-generated-use-case.js +10 -4
  114. package/dist/generate/kinds/ask-policy-in-generated-use-case.js.map +1 -1
  115. package/dist/generate/kinds/command-context.d.ts +5 -2
  116. package/dist/generate/kinds/command-context.d.ts.map +1 -1
  117. package/dist/generate/kinds/command-context.js +11 -3
  118. package/dist/generate/kinds/command-context.js.map +1 -1
  119. package/dist/generate/kinds/command-kind.d.ts.map +1 -1
  120. package/dist/generate/kinds/command-kind.js +9 -4
  121. package/dist/generate/kinds/command-kind.js.map +1 -1
  122. package/dist/generate/kinds/e2e/jobs-sending.d.ts +5 -0
  123. package/dist/generate/kinds/e2e/jobs-sending.d.ts.map +1 -0
  124. package/dist/generate/kinds/e2e/jobs-sending.js +11 -0
  125. package/dist/generate/kinds/e2e/jobs-sending.js.map +1 -0
  126. package/dist/generate/kinds/e2e/reaction-of.d.ts +9 -2
  127. package/dist/generate/kinds/e2e/reaction-of.d.ts.map +1 -1
  128. package/dist/generate/kinds/e2e/reaction-of.js +16 -7
  129. package/dist/generate/kinds/e2e/reaction-of.js.map +1 -1
  130. package/dist/generate/kinds/e2e-kind.d.ts.map +1 -1
  131. package/dist/generate/kinds/e2e-kind.js +20 -5
  132. package/dist/generate/kinds/e2e-kind.js.map +1 -1
  133. package/dist/generate/kinds/erasure-handler-kind.js +7 -0
  134. package/dist/generate/kinds/erasure-handler-kind.js.map +1 -1
  135. package/dist/generate/kinds/extend-event-sourced-aggregate.js +2 -2
  136. package/dist/generate/kinds/extend-event-sourced-aggregate.js.map +1 -1
  137. package/dist/generate/kinds/integration-handler-kind.d.ts.map +1 -1
  138. package/dist/generate/kinds/integration-handler-kind.js +1 -13
  139. package/dist/generate/kinds/integration-handler-kind.js.map +1 -1
  140. package/dist/generate/kinds/job/grant-system-actor.js +4 -2
  141. package/dist/generate/kinds/job/grant-system-actor.js.map +1 -1
  142. package/dist/generate/kinds/job/read-sent-command.d.ts.map +1 -1
  143. package/dist/generate/kinds/job/read-sent-command.js +2 -1
  144. package/dist/generate/kinds/job/read-sent-command.js.map +1 -1
  145. package/dist/generate/kinds/module-kind.d.ts.map +1 -1
  146. package/dist/generate/kinds/module-kind.js +22 -2
  147. package/dist/generate/kinds/module-kind.js.map +1 -1
  148. package/dist/generate/kinds/projection-kind.d.ts.map +1 -1
  149. package/dist/generate/kinds/projection-kind.js +15 -10
  150. package/dist/generate/kinds/projection-kind.js.map +1 -1
  151. package/dist/generate/kinds/repository-line.d.ts +4 -0
  152. package/dist/generate/kinds/repository-line.d.ts.map +1 -0
  153. package/dist/generate/kinds/repository-line.js +5 -0
  154. package/dist/generate/kinds/repository-line.js.map +1 -0
  155. package/dist/generate/kinds/subscription-vars.d.ts +8 -0
  156. package/dist/generate/kinds/subscription-vars.d.ts.map +1 -0
  157. package/dist/generate/kinds/subscription-vars.js +14 -0
  158. package/dist/generate/kinds/subscription-vars.js.map +1 -0
  159. package/dist/generate/kinds/wire-repository-on-first-use.d.ts +3 -2
  160. package/dist/generate/kinds/wire-repository-on-first-use.d.ts.map +1 -1
  161. package/dist/generate/kinds/wire-repository-on-first-use.js +8 -3
  162. package/dist/generate/kinds/wire-repository-on-first-use.js.map +1 -1
  163. package/dist/generate/refuse-shared-writes.d.ts +1 -1
  164. package/dist/generate/refuse-shared-writes.d.ts.map +1 -1
  165. package/dist/generate/refuse-shared-writes.js +25 -2
  166. package/dist/generate/refuse-shared-writes.js.map +1 -1
  167. package/dist/generate/registration.d.ts +10 -0
  168. package/dist/generate/registration.d.ts.map +1 -0
  169. package/dist/generate/registration.js +2 -0
  170. package/dist/generate/registration.js.map +1 -0
  171. package/dist/generate/wire.d.ts +5 -2
  172. package/dist/generate/wire.d.ts.map +1 -1
  173. package/dist/generate/wire.js +6 -3
  174. package/dist/generate/wire.js.map +1 -1
  175. package/dist/generate/wirings.d.ts +2 -1
  176. package/dist/generate/wirings.d.ts.map +1 -1
  177. package/dist/generate/wirings.js +25 -4
  178. package/dist/generate/wirings.js.map +1 -1
  179. package/dist/init/files/persistence-files.d.ts.map +1 -1
  180. package/dist/init/files/persistence-files.js +5 -2
  181. package/dist/init/files/persistence-files.js.map +1 -1
  182. package/dist/init/first-install-note.d.ts.map +1 -1
  183. package/dist/init/first-install-note.js +1 -0
  184. package/dist/init/first-install-note.js.map +1 -1
  185. package/dist/init/manifest/versions.js +24 -24
  186. package/dist/migration/ensure-database-reachable.d.ts +13 -0
  187. package/dist/migration/ensure-database-reachable.d.ts.map +1 -0
  188. package/dist/migration/ensure-database-reachable.js +51 -0
  189. package/dist/migration/ensure-database-reachable.js.map +1 -0
  190. package/dist/migration/index.d.ts +1 -0
  191. package/dist/migration/index.d.ts.map +1 -1
  192. package/dist/migration/index.js +1 -0
  193. package/dist/migration/index.js.map +1 -1
  194. package/dist/model-modules/index.d.ts +4 -0
  195. package/dist/model-modules/index.d.ts.map +1 -1
  196. package/dist/model-modules/index.js +4 -0
  197. package/dist/model-modules/index.js.map +1 -1
  198. package/dist/model-modules/module-file-of.d.ts +7 -0
  199. package/dist/model-modules/module-file-of.d.ts.map +1 -0
  200. package/dist/model-modules/module-file-of.js +9 -0
  201. package/dist/model-modules/module-file-of.js.map +1 -0
  202. package/dist/model-modules/module-of-module-file.d.ts +3 -0
  203. package/dist/model-modules/module-of-module-file.d.ts.map +1 -0
  204. package/dist/model-modules/module-of-module-file.js +6 -0
  205. package/dist/model-modules/module-of-module-file.js.map +1 -0
  206. package/dist/model-modules/wiring-files-of.d.ts +4 -0
  207. package/dist/model-modules/wiring-files-of.d.ts.map +1 -0
  208. package/dist/model-modules/wiring-files-of.js +6 -0
  209. package/dist/model-modules/wiring-files-of.js.map +1 -0
  210. package/dist/model-modules/wiring-text-of.d.ts +5 -0
  211. package/dist/model-modules/wiring-text-of.d.ts.map +1 -0
  212. package/dist/model-modules/wiring-text-of.js +8 -0
  213. package/dist/model-modules/wiring-text-of.js.map +1 -0
  214. package/dist/presets/apply-preset.d.ts.map +1 -1
  215. package/dist/presets/apply-preset.js +5 -0
  216. package/dist/presets/apply-preset.js.map +1 -1
  217. package/dist/presets/identity-preset.d.ts.map +1 -1
  218. package/dist/presets/identity-preset.js +1 -0
  219. package/dist/presets/identity-preset.js.map +1 -1
  220. package/dist/presets/no-flags.d.ts.map +1 -1
  221. package/dist/presets/no-flags.js +1 -0
  222. package/dist/presets/no-flags.js.map +1 -1
  223. package/dist/presets/preset.d.ts +6 -0
  224. package/dist/presets/preset.d.ts.map +1 -1
  225. package/dist/version.d.ts +1 -1
  226. package/dist/version.js +1 -1
  227. package/dist/worker/add-worktree.d.ts +5 -1
  228. package/dist/worker/add-worktree.d.ts.map +1 -1
  229. package/dist/worker/add-worktree.js +6 -2
  230. package/dist/worker/add-worktree.js.map +1 -1
  231. package/dist/workspace/workspace.d.ts +2 -1
  232. package/dist/workspace/workspace.d.ts.map +1 -1
  233. package/dist/workspace/workspace.js +6 -5
  234. package/dist/workspace/workspace.js.map +1 -1
  235. package/package.json +4 -4
  236. package/templates/aggregate/event-sourced.events.mapper.ts.tpl +2 -2
  237. package/templates/command/handler.declared.ts.tpl +39 -1
  238. package/templates/command/handler.spec.buses.ts.tpl +4 -4
  239. package/templates/command/handler.spec.tsyringe.ts.tpl +2 -2
  240. package/templates/command/handler.ts.tpl +38 -1
  241. package/templates/command/wiring.manual.tpl +4 -1
  242. package/templates/command/wiring.tsyringe.tpl +7 -2
  243. package/templates/e2e/e2e-job-case.ts.tpl +8 -0
  244. package/templates/e2e/e2e-job.spec.ts.tpl +43 -0
  245. package/templates/init/e2e/start-application.database.ts.tpl +94 -9
  246. package/templates/init/e2e/start-application.memory.ts.tpl +76 -9
  247. package/templates/init/jest.config.js.tpl +11 -2
  248. package/templates/init/platform/composition/compose-application.manual.ts.tpl +11 -2
  249. package/templates/init/platform/composition/compose-application.tsyringe.ts.tpl +4 -0
  250. package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +1 -5
  251. package/templates/init/platform/database/open-test-database.knex.ts.tpl +1 -5
  252. package/templates/init/platform/database/open-test-database.prisma.ts.tpl +1 -5
  253. package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +1 -5
  254. package/templates/init/platform/database/test-database-teardown.ts.tpl +11 -0
  255. package/templates/init/platform/database/test-database-template.ts.tpl +16 -1
  256. package/templates/init/rules/tests.md.tpl +1 -1
  257. package/templates/module/module-file.manual.ts.tpl +46 -0
  258. package/templates/module/module-file.tsyringe.ts.tpl +14 -0
  259. package/templates/module/wiring.manual.tpl +14 -0
  260. package/templates/module/wiring.tsyringe.tpl +6 -0
  261. package/templates/pipeline/package-scripts.json +1 -1
  262. package/templates/presets/identity/context/__context__.module.explicit.ts.tpl +10 -4
  263. package/templates/presets/identity/e2e/support.wiring.tpl +17 -0
  264. package/templates/projection/projection.manual.ts.tpl +8 -0
  265. package/templates/projection/wiring.manual.tpl +22 -0
  266. package/templates/projection/wiring.tsyringe.tpl +4 -0
@@ -7,16 +7,27 @@ import {
7
7
  PurgingPublisher,
8
8
  type IntegrationEvent,
9
9
  type IntegrationEventSubscriber,
10
+ type JobScheduler,
10
11
  } from '@ddd-ts-kit/kernel';
11
12
  {{/if}}
12
13
  {{#unless httpCache.varnish}}
13
- import type { IntegrationEvent, IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
14
+ import type { IntegrationEvent, IntegrationEventSubscriber, JobScheduler } from '@ddd-ts-kit/kernel';
14
15
  {{/unless}}
16
+ {{#if di.tsyringe}}
17
+ import { defineContextModule } from '@ddd-ts-kit/di';
18
+ {{/if}}
15
19
  import { createHttpClient, settled, type HttpClient, type SettledOptions } from '@ddd-ts-kit/testing/e2e';
16
20
  {{#if authz.rebac}}
21
+ import { relateSystemActors } from '{{alias.platform}}/auth/relationships/relate-system-actors{{alias.ext}}';
17
22
  import { relationTuples } from '{{alias.platform}}/auth/relationships/relation-tuples{{alias.ext}}';
18
23
  {{/if}}
19
- import { composeApplication } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
24
+ {{#if di.tsyringe}}
25
+ import { composeApplication, everyContext } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
26
+ import type { ContextSelection } from '{{alias.platform}}/composition/context-selection{{alias.ext}}';
27
+ {{/if}}
28
+ {{#unless di.tsyringe}}
29
+ import { composeApplication, everyContext } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
30
+ {{/unless}}
20
31
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
21
32
  import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
22
33
  import { openTestDatabase, type TestDatabase } from '{{alias.platform}}/database/open-test-database{{alias.ext}}';
@@ -50,6 +61,9 @@ import { testEnvironment } from '{{alias.test}}/e2e/support/test-environment{{al
50
61
  {{/unless}}
51
62
  {{/unless}}
52
63
 
64
+ // ddd-ts-kit:imports
65
+ // /ddd-ts-kit:imports
66
+
53
67
  /** The whole application, real adapters included, as a client and another context see it. */
54
68
  export interface RunningApplication {
55
69
  readonly client: HttpClient;
@@ -98,7 +112,22 @@ export interface RunningApplication {
98
112
  relate(tuple: RelationTuple): Promise<void>;
99
113
  {{/if}}
100
114
 
115
+ /**
116
+ * Runs a job at once, as its schedule would, for a spec of what only a job starts: the name is
117
+ * `<context>.<job>`. It rejects when the job failed or did not run. Await `settled()` next, before
118
+ * asserting what the job started.
119
+ */
120
+ runJob(name: string): Promise<void>;
121
+
122
+ {{#if authz.rebac}}
123
+ /**
124
+ * Empties the database and writes the relationships of the system actors again, the state right
125
+ * after start: call it before each test.
126
+ */
127
+ {{/if}}
128
+ {{#unless authz.rebac}}
101
129
  /** Empties the database: call it before each test. */
130
+ {{/unless}}
102
131
  reset(): Promise<void>;
103
132
 
104
133
  close(): Promise<void>;
@@ -124,11 +153,20 @@ export async function startApplication(): Promise<RunningApplication> {
124
153
  {{/if}}
125
154
  as: async (actor) => started.client.withHeaders(await credentials.headersOf(actor)),
126
155
  publish: (events) => started.publish(events),
156
+ runJob: (name) => started.runJob(name),
127
157
  {{#if authz.rebac}}
128
158
  relate: (tuple) => relationTuples.write([tuple]),
129
159
  {{/if}}
130
160
  settled: (options) => started.settled(options),
161
+ {{#if authz.rebac}}
162
+ reset: async () => {
163
+ await database.reset();
164
+ await relateSystemActors();
165
+ },
166
+ {{/if}}
167
+ {{#unless authz.rebac}}
131
168
  reset: () => database.reset(),
169
+ {{/unless}}
132
170
  close: () => started.close(),
133
171
  };
134
172
  }
@@ -142,6 +180,8 @@ interface Started {
142
180
 
143
181
  publish(events: readonly IntegrationEvent[]): Promise<void>;
144
182
 
183
+ runJob(name: string): Promise<void>;
184
+
145
185
  settled(options?: SettledOptions): Promise<void>;
146
186
 
147
187
  close(): Promise<void>;
@@ -153,13 +193,8 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
153
193
  const redis = config.redisUrl === noRedis ? undefined : openRedis(config);
154
194
 
155
195
  {{/if}}
156
- const application = composeApplication(database.persistence, {
157
- events: {{#if broker.provided}}eventsOf(config){{/if}}{{#unless broker.provided}}inProcessEvents(){{/unless}},
158
- authenticator: credentials.authenticator,
159
- {{#if cache.redis}}
160
- ...(redis === undefined ? {} : { redis }),
161
- {{/if}}
162
- });
196
+ const options = optionsOf(config, credentials{{#if cache.redis}}, redis{{/if}});
197
+ const application = composeApplication(database.persistence, options, contextsOfTheRun());
163
198
 
164
199
  await application.start();
165
200
 
@@ -191,6 +226,7 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
191
226
  purges,
192
227
  {{/if}}
193
228
  publish: (events) => application.eventBus.publish(events),
229
+ runJob: (name) => runJob(application.jobs, name),
194
230
  {{#if events.outbox}}
195
231
  settled: (options) => settled({ outbox: () => database.persistence.outbox.stats() }, options),
196
232
  {{/if}}
@@ -211,9 +247,58 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
211
247
  },
212
248
  };
213
249
  }
250
+
251
+ /** What the application is built on in a test run: the events, the credentials of the specs and what the environment provides. */
252
+ function optionsOf(config: AppConfig, credentials: Credentials{{#if cache.redis}}, redis: ReturnType<typeof openRedis> | undefined{{/if}}) {
253
+ return {
254
+ events: {{#if broker.provided}}eventsOf(config){{/if}}{{#unless broker.provided}}inProcessEvents(){{/unless}},
255
+ authenticator: credentials.authenticator,
256
+ {{#if cache.redis}}
257
+ ...(redis === undefined ? {} : { redis }),
258
+ {{/if}}
259
+ };
260
+ }
214
261
  {{#if broker.provided}}
215
262
 
216
263
  function eventsOf(config: AppConfig): EventProvider {
217
264
  return {{broker.inProcessWhen}} ? inProcessEvents() : createEventProvider(config);
218
265
  }
219
266
  {{/if}}
267
+
268
+ /**
269
+ * The contexts as a test run composes them. An outside system that answers nowhere in a test run
270
+ * (an identity provider, a payment service) is answered by its fake of `test/fakes/` here, where
271
+ * the preset or the person who adds it binds it, so that its handlers settle instead of retrying.
272
+ */
273
+ {{#if di.tsyringe}}
274
+ function contextsOfTheRun(): ContextSelection {
275
+ const fakes = defineContextModule({
276
+ name: 'end-to-end-fakes',
277
+ register(builder) {
278
+ // ddd-ts-kit:e2e-fakes
279
+ // /ddd-ts-kit:e2e-fakes
280
+ },
281
+ });
282
+
283
+ return { ...everyContext, modules: [...everyContext.modules, fakes] };
284
+ }
285
+ {{/if}}
286
+ {{#unless di.tsyringe}}
287
+ function contextsOfTheRun(): typeof everyContext {
288
+ return everyContext.map((module): (typeof everyContext)[number] => {
289
+ // ddd-ts-kit:e2e-fakes
290
+ // /ddd-ts-kit:e2e-fakes
291
+
292
+ return module;
293
+ });
294
+ }
295
+ {{/unless}}
296
+
297
+ /** Runs the job now; a run that failed or did not happen fails the spec with its outcome, never the message of an error. */
298
+ async function runJob(jobs: JobScheduler, name: string): Promise<void> {
299
+ const { outcome, errorCode } = await jobs.runNow(name);
300
+
301
+ if (outcome !== 'succeeded') {
302
+ throw new Error(`The job ${name} ended ${outcome}${errorCode === undefined ? '' : ` (${errorCode})`}.`);
303
+ }
304
+ }
@@ -7,16 +7,26 @@ import {
7
7
  PurgingPublisher,
8
8
  type IntegrationEvent,
9
9
  type IntegrationEventSubscriber,
10
+ type JobScheduler,
10
11
  } from '@ddd-ts-kit/kernel';
11
12
  {{/if}}
12
13
  {{#unless httpCache.varnish}}
13
- import type { IntegrationEvent, IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
14
+ import type { IntegrationEvent, IntegrationEventSubscriber, JobScheduler } from '@ddd-ts-kit/kernel';
14
15
  {{/unless}}
16
+ {{#if di.tsyringe}}
17
+ import { defineContextModule } from '@ddd-ts-kit/di';
18
+ {{/if}}
15
19
  import { createHttpClient, settled, type HttpClient, type SettledOptions } from '@ddd-ts-kit/testing/e2e';
16
20
  {{#if authz.rebac}}
17
21
  import { relationTuples } from '{{alias.platform}}/auth/relationships/relation-tuples{{alias.ext}}';
18
22
  {{/if}}
19
- import { composeApplication } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
23
+ {{#if di.tsyringe}}
24
+ import { composeApplication, everyContext } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
25
+ import type { ContextSelection } from '{{alias.platform}}/composition/context-selection{{alias.ext}}';
26
+ {{/if}}
27
+ {{#unless di.tsyringe}}
28
+ import { composeApplication, everyContext } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
29
+ {{/unless}}
20
30
  {{#if broker.provided}}
21
31
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
22
32
  {{/if}}
@@ -51,6 +61,8 @@ import { noRedis, testEnvironment } from '{{alias.test}}/e2e/support/test-enviro
51
61
  import { testEnvironment } from '{{alias.test}}/e2e/support/test-environment{{alias.ext}}';
52
62
  {{/unless}}
53
63
  {{/unless}}
64
+ // ddd-ts-kit:imports
65
+ // /ddd-ts-kit:imports
54
66
 
55
67
  /** The whole application as a client and another context see it. */
56
68
  export interface RunningApplication {
@@ -101,6 +113,13 @@ export interface RunningApplication {
101
113
  relate(tuple: RelationTuple): Promise<void>;
102
114
  {{/if}}
103
115
 
116
+ /**
117
+ * Runs a job at once, as its schedule would, for a spec of what only a job starts: the name is
118
+ * `<context>.<job>`. It rejects when the job failed or did not run. Await `settled()` next, before
119
+ * asserting what the job started.
120
+ */
121
+ runJob(name: string): Promise<void>;
122
+
104
123
  /** Starts from nothing again: call it before each test. */
105
124
  reset(): Promise<void>;
106
125
 
@@ -126,6 +145,7 @@ export async function startApplication(): Promise<RunningApplication> {
126
145
  {{/if}}
127
146
  as: async (actor) => current.client.withHeaders(await credentials.headersOf(actor)),
128
147
  publish: (events) => current.publish(events),
148
+ runJob: (name) => current.runJob(name),
129
149
  {{#if authz.rebac}}
130
150
  relate: (tuple) => relationTuples.write([tuple]),
131
151
  {{/if}}
@@ -147,6 +167,8 @@ interface Started {
147
167
 
148
168
  publish(events: readonly IntegrationEvent[]): Promise<void>;
149
169
 
170
+ runJob(name: string): Promise<void>;
171
+
150
172
  settled(options?: SettledOptions): Promise<void>;
151
173
 
152
174
  close(): Promise<void>;
@@ -159,13 +181,8 @@ async function start(credentials: Credentials): Promise<Started> {
159
181
  const redis = config.redisUrl === noRedis ? undefined : openRedis(config);
160
182
  {{/if}}
161
183
 
162
- const application = composeApplication(persistence, {
163
- events: {{#if broker.provided}}eventsOf(config){{/if}}{{#unless broker.provided}}inProcessEvents(){{/unless}},
164
- authenticator: credentials.authenticator,
165
- {{#if cache.redis}}
166
- ...(redis === undefined ? {} : { redis }),
167
- {{/if}}
168
- });
184
+ const options = optionsOf({{#if broker.provided}}config, {{/if}}credentials{{#if cache.redis}}, redis{{/if}});
185
+ const application = composeApplication(persistence, options, contextsOfTheRun());
169
186
 
170
187
  await application.start();
171
188
 
@@ -197,6 +214,7 @@ async function start(credentials: Credentials): Promise<Started> {
197
214
  purges,
198
215
  {{/if}}
199
216
  publish: (events) => application.eventBus.publish(events),
217
+ runJob: (name) => runJob(application.jobs, name),
200
218
  {{#if events.outbox}}
201
219
  settled: (options) => settled({ outbox: () => persistence.outbox.stats() }, options),
202
220
  {{/if}}
@@ -217,9 +235,58 @@ async function start(credentials: Credentials): Promise<Started> {
217
235
  },
218
236
  };
219
237
  }
238
+
239
+ /** What the application is built on in a test run: the events, the credentials of the specs and what the environment provides. */
240
+ function optionsOf({{#if broker.provided}}config: AppConfig, {{/if}}credentials: Credentials{{#if cache.redis}}, redis: ReturnType<typeof openRedis> | undefined{{/if}}) {
241
+ return {
242
+ events: {{#if broker.provided}}eventsOf(config){{/if}}{{#unless broker.provided}}inProcessEvents(){{/unless}},
243
+ authenticator: credentials.authenticator,
244
+ {{#if cache.redis}}
245
+ ...(redis === undefined ? {} : { redis }),
246
+ {{/if}}
247
+ };
248
+ }
220
249
  {{#if broker.provided}}
221
250
 
222
251
  function eventsOf(config: AppConfig): EventProvider {
223
252
  return {{broker.inProcessWhen}} ? inProcessEvents() : createEventProvider(config);
224
253
  }
225
254
  {{/if}}
255
+
256
+ /**
257
+ * The contexts as a test run composes them. An outside system that answers nowhere in a test run
258
+ * (an identity provider, a payment service) is answered by its fake of `test/fakes/` here, where
259
+ * the preset or the person who adds it binds it, so that its handlers settle instead of retrying.
260
+ */
261
+ {{#if di.tsyringe}}
262
+ function contextsOfTheRun(): ContextSelection {
263
+ const fakes = defineContextModule({
264
+ name: 'end-to-end-fakes',
265
+ register(builder) {
266
+ // ddd-ts-kit:e2e-fakes
267
+ // /ddd-ts-kit:e2e-fakes
268
+ },
269
+ });
270
+
271
+ return { ...everyContext, modules: [...everyContext.modules, fakes] };
272
+ }
273
+ {{/if}}
274
+ {{#unless di.tsyringe}}
275
+ function contextsOfTheRun(): typeof everyContext {
276
+ return everyContext.map((module): (typeof everyContext)[number] => {
277
+ // ddd-ts-kit:e2e-fakes
278
+ // /ddd-ts-kit:e2e-fakes
279
+
280
+ return module;
281
+ });
282
+ }
283
+ {{/unless}}
284
+
285
+ /** Runs the job now; a run that failed or did not happen fails the spec with its outcome, never the message of an error. */
286
+ async function runJob(jobs: JobScheduler, name: string): Promise<void> {
287
+ const { outcome, errorCode } = await jobs.runNow(name);
288
+
289
+ if (outcome !== 'succeeded') {
290
+ throw new Error(`The job ${name} ended ${outcome}${errorCode === undefined ? '' : ` (${errorCode})`}.`);
291
+ }
292
+ }
@@ -12,7 +12,15 @@ export default {
12
12
  {{/if}}
13
13
  },
14
14
  testMatch: ['<rootDir>/{{config.sourceRoot}}/**/*.spec.ts', '<rootDir>/test/architecture/**/*.spec.ts'],
15
- // A hook opens the test database (PGlite started and its tables created, or a server reached): on a busy machine it outlasts the 5 seconds Jest gives a test and its hooks, as Vitest is given 60.
15
+ {{#if persistence.hasDatabase}}
16
+ // PostgreSQL in process is initialised once per run, and each spec opens a copy of that cluster instead of an initdb of its own.
17
+ globalSetup: '<rootDir>/test/support/test-database-template.ts',
18
+ globalTeardown: '<rootDir>/test/support/test-database-teardown.ts',
19
+ // A hook opens a copy of that cluster and creates its tables, or reaches a server: on a busy machine it can outlast the 5 seconds Jest gives a test and its hooks, as Vitest is given 60.
20
+ {{/if}}
21
+ {{#unless persistence.hasDatabase}}
22
+ // A hook opens the test database: on a busy machine it can outlast the 5 seconds Jest gives a test and its hooks, as Vitest is given 60.
23
+ {{/unless}}
16
24
  testTimeout: 60_000,
17
25
  // Each spec file is held to the time budget of its level ("budget" in ddd-ts-kit.config.json, the reference when it is absent): the slowest named at the end of the run, a file over its budget fails it.
18
26
  reporters: ['default', '@ddd-ts-kit/testing/budget/jest'],
@@ -40,7 +48,8 @@ export default {
40
48
  },
41
49
  // A developer machine shares its cores with the editor, the coding agents and their worktrees: the specs take half of them. A pipeline runner has its own.
42
50
  ...(process.env.CI ? {} : { maxWorkers: '50%' }),
43
- coverageProvider: 'v8',
51
+ // Babel instruments the code @swc/jest has transformed: two to three times faster than `v8` on a grown project, the same branches as the `v8` provider of Vitest. A line left out of the measure carries `istanbul ignore`, the hint it reads.
52
+ coverageProvider: 'babel',
44
53
  coverageReporters: ['text', 'cobertura', 'lcov'],
45
54
  coverageDirectory: 'coverage',
46
55
  // What is measured and the floor of each layer come from "coverage" in ddd-ts-kit.config.json, the reference when it is absent: a threshold is written nowhere else.
@@ -24,10 +24,16 @@ import { ArchiveAuditEntries } from '@ddd-ts-kit/audit';
24
24
  import { PurgeStagedFiles } from '@ddd-ts-kit/kernel';
25
25
  {{/if}}
26
26
  {{#if cache.rateLimit}}
27
- import type { IntegrationEventPublisher, IntegrationEventSubscriber, Logger, RateLimiter } from '@ddd-ts-kit/kernel';
27
+ import type {
28
+ IntegrationEventPublisher,
29
+ IntegrationEventSubscriber,
30
+ JobScheduler,
31
+ Logger,
32
+ RateLimiter,
33
+ } from '@ddd-ts-kit/kernel';
28
34
  {{/if}}
29
35
  {{#unless cache.rateLimit}}
30
- import type { IntegrationEventPublisher, IntegrationEventSubscriber, Logger } from '@ddd-ts-kit/kernel';
36
+ import type { IntegrationEventPublisher, IntegrationEventSubscriber, JobScheduler, Logger } from '@ddd-ts-kit/kernel';
31
37
  {{/unless}}
32
38
  {{#if audit.route}}
33
39
  import { auditModule } from '{{alias.platform}}/audit/audit.module{{alias.ext}}';
@@ -131,6 +137,8 @@ export interface Application {
131
137
  /** Where another context, or a test, listens to what this application publishes. */
132
138
  readonly eventSubscriber: IntegrationEventSubscriber;
133
139
  readonly logger: Logger;
140
+ /** Runs a job at once, for a test: `jobs.runNow('<context>.<job>')`. */
141
+ readonly jobs: JobScheduler;
134
142
  {{#if cache.rateLimit}}
135
143
  /** What the HTTP server asks before anything else: on the Redis protocol server, or in the memory of the process without one. */
136
144
  readonly rateLimiter: RateLimiter;
@@ -217,6 +225,7 @@ export function composeApplication(
217
225
  eventSubscriber: platform.subscriber,
218
226
  {{/unless}}
219
227
  logger,
228
+ jobs: platform.jobs,
220
229
  {{#if cache.rateLimit}}
221
230
  rateLimiter: platform.rateLimiter,
222
231
  {{/if}}
@@ -41,6 +41,7 @@ import {
41
41
  {{#unless broker.external}}
42
42
  IntegrationEventSubscriber,
43
43
  {{/unless}}
44
+ JobScheduler,
44
45
  Logger,
45
46
  Metrics,
46
47
  {{#if httpCache.perTenant}}
@@ -137,6 +138,8 @@ export interface Application {
137
138
  /** Where another context, or a test, listens to what this application publishes. */
138
139
  readonly eventSubscriber: IntegrationEventSubscriber;
139
140
  readonly logger: Logger;
141
+ /** Runs a job at once, for a test: `jobs.runNow('<context>.<job>')`. */
142
+ readonly jobs: JobScheduler;
140
143
  {{#if cache.rateLimit}}
141
144
  /** What the HTTP server asks before anything else: on the Redis protocol server, or in the memory of the process without one. */
142
145
  readonly rateLimiter: RateLimiter;
@@ -364,6 +367,7 @@ function running({ container, options, contexts }: Composed): Application {
364
367
  eventSubscriber: container.resolve(IntegrationEventSubscriber),
365
368
  {{/unless}}
366
369
  logger,
370
+ jobs: container.resolve(JobScheduler),
367
371
  {{#if cache.rateLimit}}
368
372
  rateLimiter: container.resolve(RateLimiter),
369
373
  {{/if}}
@@ -1,6 +1,4 @@
1
- {{#if tests.vitest}}
2
1
  import { openAsBlob } from 'node:fs';
3
- {{/if}}
4
2
  import { PGlite } from '@electric-sql/pglite';
5
3
  import { sql } from 'drizzle-orm';
6
4
  import { drizzle } from 'drizzle-orm/pglite';
@@ -29,7 +27,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
29
27
  }
30
28
 
31
29
  async function openInProcess(): Promise<TestDatabase> {
32
- const engine = await {{#if tests.vitest}}inProcessPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
30
+ const engine = await inProcessPostgres();
33
31
  const statements = new TableStatements();
34
32
 
35
33
  for (const statement of statements.creating()) {
@@ -45,7 +43,6 @@ async function openInProcess(): Promise<TestDatabase> {
45
43
  };
46
44
  }
47
45
 
48
- {{#if tests.vitest}}
49
46
  /**
50
47
  * A copy of the cluster the global setup of the run initialised once (test/support/test-database-template.ts),
51
48
  * which spares each spec the initdb of its own; a cluster initialised here when the run names no
@@ -57,7 +54,6 @@ async function inProcessPostgres(): Promise<PGlite> {
57
54
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
58
55
  }
59
56
 
60
- {{/if}}
61
57
  async function openServer(url: string): Promise<TestDatabase> {
62
58
  const connection = connectToDatabase(url);
63
59
  const statements = new TableStatements();
@@ -1,6 +1,4 @@
1
- {{#if tests.vitest}}
2
1
  import { openAsBlob } from 'node:fs';
3
- {{/if}}
4
2
  import { PGlite } from '@electric-sql/pglite';
5
3
  import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
6
4
  import type { Knex } from 'knex';
@@ -33,7 +31,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
33
31
  }
34
32
 
35
33
  async function openInProcess(): Promise<TestDatabase> {
36
- const engine = await {{#if tests.vitest}}inProcessPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
34
+ const engine = await inProcessPostgres();
37
35
  const server = new PGLiteSocketServer({ db: engine, host: '127.0.0.1', port: 0, maxConnections: 10 });
38
36
 
39
37
  await server.start();
@@ -54,7 +52,6 @@ async function openInProcess(): Promise<TestDatabase> {
54
52
  return { persistence: persistenceOver({ db: connection.db, close }), reset: () => emptyTables(connection.db), close };
55
53
  }
56
54
 
57
- {{#if tests.vitest}}
58
55
  /**
59
56
  * A copy of the cluster the global setup of the run initialised once (test/support/test-database-template.ts),
60
57
  * which spares each spec the initdb of its own; a cluster initialised here when the run names no
@@ -66,7 +63,6 @@ async function inProcessPostgres(): Promise<PGlite> {
66
63
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
67
64
  }
68
65
 
69
- {{/if}}
70
66
  async function openServer(url: string): Promise<TestDatabase> {
71
67
  const connection = connectToDatabase(url);
72
68
 
@@ -1,6 +1,4 @@
1
- {{#if tests.vitest}}
2
1
  import { openAsBlob } from 'node:fs';
3
- {{/if}}
4
2
  import { readFile } from 'node:fs/promises';
5
3
  import { PGlite } from '@electric-sql/pglite';
6
4
  import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
@@ -33,7 +31,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
33
31
  }
34
32
 
35
33
  async function openInProcess(): Promise<TestDatabase> {
36
- const engine = await {{#if tests.vitest}}inProcessPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
34
+ const engine = await inProcessPostgres();
37
35
  const server = new PGLiteSocketServer({ db: engine, host: '127.0.0.1', port: 0, maxConnections: 10 });
38
36
 
39
37
  await server.start();
@@ -54,7 +52,6 @@ async function openInProcess(): Promise<TestDatabase> {
54
52
  return { persistence: persistenceOver(client), reset: () => emptyTables(client), close };
55
53
  }
56
54
 
57
- {{#if tests.vitest}}
58
55
  /**
59
56
  * A copy of the cluster the global setup of the run initialised once (test/support/test-database-template.ts),
60
57
  * which spares each spec the initdb of its own; a cluster initialised here when the run names no
@@ -66,7 +63,6 @@ async function inProcessPostgres(): Promise<PGlite> {
66
63
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
67
64
  }
68
65
 
69
- {{/if}}
70
66
  async function openServer(url: string): Promise<TestDatabase> {
71
67
  const client = createClient(url);
72
68
 
@@ -1,6 +1,4 @@
1
- {{#if tests.vitest}}
2
1
  import { openAsBlob } from 'node:fs';
3
- {{/if}}
4
2
  import { PGlite } from '@electric-sql/pglite';
5
3
  import { PGLiteSocketServer } from '@electric-sql/pglite-socket';
6
4
  {{#if audit.on}}
@@ -33,7 +31,7 @@ export function openTestDatabase(url?: string): Promise<TestDatabase> {
33
31
  }
34
32
 
35
33
  async function openInProcess(): Promise<TestDatabase> {
36
- const engine = await {{#if tests.vitest}}inProcessPostgres(){{/if}}{{#if tests.jest}}PGlite.create(){{/if}};
34
+ const engine = await inProcessPostgres();
37
35
  const server = new PGLiteSocketServer({ db: engine, host: '127.0.0.1', port: 0, maxConnections: 10 });
38
36
 
39
37
  await server.start();
@@ -57,7 +55,6 @@ async function openInProcess(): Promise<TestDatabase> {
57
55
  return { persistence, reset: () => emptyTables(dataSource), close };
58
56
  }
59
57
 
60
- {{#if tests.vitest}}
61
58
  /**
62
59
  * A copy of the cluster the global setup of the run initialised once (test/support/test-database-template.ts),
63
60
  * which spares each spec the initdb of its own; a cluster initialised here when the run names no
@@ -69,7 +66,6 @@ async function inProcessPostgres(): Promise<PGlite> {
69
66
  return PGlite.create(template === undefined ? {} : { loadDataDir: await openAsBlob(template) });
70
67
  }
71
68
 
72
- {{/if}}
73
69
  async function openServer(url: string): Promise<TestDatabase> {
74
70
  const dataSource = createDataSource(url);
75
71
 
@@ -0,0 +1,11 @@
1
+ import { rm } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ /** The global teardown of the test runs (`globalTeardown` of jest.config.js): deletes the cluster test-database-template.ts saved. */
5
+ export default async function teardown(): Promise<void> {
6
+ const file = process.env['TEST_DATABASE_TEMPLATE'];
7
+
8
+ if (file !== undefined) {
9
+ await rm(path.dirname(file), { recursive: true, force: true });
10
+ }
11
+ }
@@ -1,8 +1,9 @@
1
- import { mkdtemp, rm, writeFile } from 'node:fs/promises';
1
+ import { mkdtemp, {{#if tests.vitest}}rm, {{/if}}writeFile } from 'node:fs/promises';
2
2
  import { tmpdir } from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { PGlite } from '@electric-sql/pglite';
5
5
 
6
+ {{#if tests.vitest}}
6
7
  /**
7
8
  * The global setup of the test runs (vitest.config.ts, vitest.e2e.config.ts): starts PostgreSQL in
8
9
  * process once and saves its initialised cluster to a file. Each spec of the run opens a copy of it
@@ -11,6 +12,18 @@ import { PGlite } from '@electric-sql/pglite';
11
12
  * resolves is the teardown, which deletes the file.
12
13
  */
13
14
  export async function setup(): Promise<() => Promise<void>> {
15
+ {{/if}}
16
+ {{#if tests.jest}}
17
+ /**
18
+ * The global setup of the test runs (`globalSetup` of jest.config.js, which jest.e2e.config.js
19
+ * extends): starts PostgreSQL in process once and saves its initialised cluster to a file. Each spec
20
+ * of the run opens a copy of it (open-test-database.ts) instead of running an initdb of its own, the
21
+ * slow part of starting, then creates its tables there, so that what creates them stays run and
22
+ * measured in every spec. The workers Jest starts next inherit the variable that names the file;
23
+ * test-database-teardown.ts deletes it.
24
+ */
25
+ export default async function setup(): Promise<void> {
26
+ {{/if}}
14
27
  const directory = await mkdtemp(path.join(tmpdir(), 'test-database-'));
15
28
  const file = path.join(directory, 'cluster.tar');
16
29
  const engine = await PGlite.create();
@@ -18,6 +31,8 @@ export async function setup(): Promise<() => Promise<void>> {
18
31
  await writeFile(file, new Uint8Array(await (await engine.dumpDataDir('none')).arrayBuffer()));
19
32
  await engine.close();
20
33
  process.env['TEST_DATABASE_TEMPLATE'] = file;
34
+ {{#if tests.vitest}}
21
35
 
22
36
  return () => rm(directory, { recursive: true, force: true });
37
+ {{/if}}
23
38
  }
@@ -21,7 +21,7 @@ paths:
21
21
  - The arrangement several specs of a context share, the test application or the buses with the fakes, is a world of `test/worlds/` written by `npx ddd-ts-kit generate test-world <context>`: `a<Name>World({ now, idPrefix, given })` returns every fake under the name of its port, `given` storing what the spec starts from. `test/unit/` and `test/integration/` hold specs only (`test/helper-placed`).
22
22
  - Name tests after the behaviour, in the words of the business: "refuses to issue an invoice without lines", not "should throw". Arrange, act, assert, separated by a blank line; one behaviour per test. `npm run lint` holds the shape: the title states the rule (`test/title-states-a-rule`), no `if` or loop in a test (`test/no-logic`), an assertion in every test (`test/assertion-present`), a refusal asserted by its code, never by a message (`test/refusal-by-code`), no snapshot (`test/no-snapshot`), no `.only` or `.skip` (`test/no-only-no-skip`).
23
23
  - Every aggregate, value object, domain service, handler, event handler and integration event handler has a spec named after its file (`test/spec-required`).
24
- - 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
+ - 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`), and one with it names the hint the provider of this project reads, {{#if tests.vitest}}`v8 ignore` (Vitest, `v8`){{/if}}{{#if tests.jest}}`istanbul ignore` (Jest, `babel`){{/if}}: the other one is not read, and the line is counted; a rate proves that code ran, never that a test asserts anything.
25
25
  - 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.
26
26
  - A test never asserts on a private field; it observes results, recorded events and what the fakes received.
27
27
  - `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. A spec past 350 lines is split by behaviour into `test/e2e/<use-case>-<behaviour>.e2e.spec.ts` beside it, and what the specs of one context share goes in `test/e2e/support/<context>/`.
@@ -0,0 +1,46 @@
1
+ import type { UseCaseDeclaration } from '@ddd-ts-kit/auth';
2
+ {{#if http.any}}
3
+ import type { Route } from '@ddd-ts-kit/http';
4
+ {{/if}}
5
+ import type { Platform } from '{{alias.platform}}/composition/platform{{alias.ext}}';
6
+ // ddd-ts-kit:imports
7
+ // /ddd-ts-kit:imports
8
+
9
+ /** What the module {{module.kebab}} of the model registers; {{context.kebab}}.module.ts composes it with the rest of the context. */
10
+ export const {{module.camel}}Module = {
11
+ /** The command and query handlers of the module, with the repositories and readers they are given. */
12
+ registerHandlers(platform: Platform): void {
13
+ // ddd-ts-kit:handlers
14
+ // /ddd-ts-kit:handlers
15
+ },
16
+
17
+ /** What the module does when an event happens: its own events and those of the other contexts. */
18
+ registerReactions(platform: Platform): void {
19
+ // ddd-ts-kit:reactions
20
+ // /ddd-ts-kit:reactions
21
+ },
22
+
23
+ /** The jobs of the module, scheduled and in the background. */
24
+ registerJobs(platform: Platform): void {
25
+ // ddd-ts-kit:jobs
26
+ // /ddd-ts-kit:jobs
27
+ },
28
+
29
+ /** What each use case of the module requires, or that it is public. */
30
+ useCases(): UseCaseDeclaration[] {
31
+ return [
32
+ // ddd-ts-kit:authorization
33
+ // /ddd-ts-kit:authorization
34
+ ];
35
+ },
36
+ {{#if http.any}}
37
+
38
+ /** The routes the module answers, over the buses of the platform. */
39
+ routes(platform: Platform): Route[] {
40
+ return [
41
+ // ddd-ts-kit:routes
42
+ // /ddd-ts-kit:routes
43
+ ];
44
+ },
45
+ {{/if}}
46
+ };
@@ -0,0 +1,14 @@
1
+ import type { ModuleBuilder, ModuleContext } from '@ddd-ts-kit/di';
2
+ // ddd-ts-kit:imports
3
+ // /ddd-ts-kit:imports
4
+
5
+ export const {{module.camel}}Module = {
6
+ register(builder: ModuleBuilder): void {
7
+ // ddd-ts-kit:registrations
8
+ // /ddd-ts-kit:registrations
9
+ },
10
+ onStart({ resolve }: ModuleContext): void {
11
+ // ddd-ts-kit:start
12
+ // /ddd-ts-kit:start
13
+ },
14
+ };