ddd-ts-kit 0.97.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.
- package/CHANGELOG.md +112 -0
- package/README.fr.md +5 -5
- package/README.md +4 -4
- package/dist/check/canonical/stray-entry.d.ts.map +1 -1
- package/dist/check/canonical/stray-entry.js +14 -2
- package/dist/check/canonical/stray-entry.js.map +1 -1
- package/dist/check/domain-events/event-handlers-of.d.ts.map +1 -1
- package/dist/check/domain-events/event-handlers-of.js +21 -8
- package/dist/check/domain-events/event-handlers-of.js.map +1 -1
- package/dist/check/events/consumer-registrations.d.ts +2 -0
- package/dist/check/events/consumer-registrations.d.ts.map +1 -1
- package/dist/check/events/consumer-registrations.js +44 -2
- package/dist/check/events/consumer-registrations.js.map +1 -1
- package/dist/check/explain/events-docs.js +1 -1
- package/dist/check/explain/events-docs.js.map +1 -1
- package/dist/check/explain/tree-docs.d.ts.map +1 -1
- package/dist/check/explain/tree-docs.js +7 -4
- package/dist/check/explain/tree-docs.js.map +1 -1
- package/dist/check/explain/wiring-docs.js +1 -1
- package/dist/check/explain/wiring-docs.js.map +1 -1
- package/dist/check/fixtures/consumer-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/consumer-fixtures.js +33 -0
- package/dist/check/fixtures/consumer-fixtures.js.map +1 -1
- package/dist/check/project/locate.js +9 -3
- package/dist/check/project/locate.js.map +1 -1
- package/dist/check/rules/composition-only-in-module.js +2 -2
- package/dist/check/rules/composition-only-in-module.js.map +1 -1
- package/dist/check/rules/declarations-port-adapter-wired.js +1 -1
- package/dist/check/rules/declarations-port-adapter-wired.js.map +1 -1
- package/dist/check/rules/events-consumer-idempotent.d.ts.map +1 -1
- package/dist/check/rules/events-consumer-idempotent.js +6 -3
- package/dist/check/rules/events-consumer-idempotent.js.map +1 -1
- package/dist/check/rules/tree-closed.js +1 -1
- package/dist/check/rules/tree-closed.js.map +1 -1
- package/dist/commands/generate.js +2 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/describe/context-sources.d.ts +1 -1
- package/dist/describe/context-sources.d.ts.map +1 -1
- package/dist/describe/describe-context.js +2 -2
- package/dist/describe/describe-context.js.map +1 -1
- package/dist/docs/personal-declarations-in.js +6 -1
- package/dist/docs/personal-declarations-in.js.map +1 -1
- package/dist/docs/personal-table-cells.js +7 -1
- package/dist/docs/personal-table-cells.js.map +1 -1
- package/dist/docs/personal-table-facts.d.ts +1 -1
- package/dist/docs/personal-table-facts.d.ts.map +1 -1
- package/dist/docs/read-jobs.d.ts +1 -1
- package/dist/docs/read-jobs.d.ts.map +1 -1
- package/dist/docs/read-jobs.js +3 -3
- package/dist/docs/read-jobs.js.map +1 -1
- package/dist/generate/apply-wiring.js +1 -1
- package/dist/generate/apply-wiring.js.map +1 -1
- package/dist/generate/kind.d.ts +2 -0
- package/dist/generate/kind.d.ts.map +1 -1
- package/dist/generate/kinds/adapter-kind.js +2 -2
- package/dist/generate/kinds/adapter-kind.js.map +1 -1
- package/dist/generate/kinds/ask-policy-in-generated-use-case.d.ts.map +1 -1
- package/dist/generate/kinds/ask-policy-in-generated-use-case.js +10 -4
- package/dist/generate/kinds/ask-policy-in-generated-use-case.js.map +1 -1
- package/dist/generate/kinds/command-context.d.ts +5 -2
- package/dist/generate/kinds/command-context.d.ts.map +1 -1
- package/dist/generate/kinds/command-context.js +11 -3
- package/dist/generate/kinds/command-context.js.map +1 -1
- package/dist/generate/kinds/command-kind.d.ts.map +1 -1
- package/dist/generate/kinds/command-kind.js +9 -4
- package/dist/generate/kinds/command-kind.js.map +1 -1
- package/dist/generate/kinds/e2e/jobs-sending.d.ts +5 -0
- package/dist/generate/kinds/e2e/jobs-sending.d.ts.map +1 -0
- package/dist/generate/kinds/e2e/jobs-sending.js +11 -0
- package/dist/generate/kinds/e2e/jobs-sending.js.map +1 -0
- package/dist/generate/kinds/e2e/reaction-of.d.ts +9 -2
- package/dist/generate/kinds/e2e/reaction-of.d.ts.map +1 -1
- package/dist/generate/kinds/e2e/reaction-of.js +16 -7
- package/dist/generate/kinds/e2e/reaction-of.js.map +1 -1
- package/dist/generate/kinds/e2e-kind.d.ts.map +1 -1
- package/dist/generate/kinds/e2e-kind.js +20 -5
- package/dist/generate/kinds/e2e-kind.js.map +1 -1
- package/dist/generate/kinds/erasure-handler-kind.js +7 -0
- package/dist/generate/kinds/erasure-handler-kind.js.map +1 -1
- package/dist/generate/kinds/job/read-sent-command.d.ts.map +1 -1
- package/dist/generate/kinds/job/read-sent-command.js +2 -1
- package/dist/generate/kinds/job/read-sent-command.js.map +1 -1
- package/dist/generate/kinds/module-kind.d.ts.map +1 -1
- package/dist/generate/kinds/module-kind.js +22 -2
- package/dist/generate/kinds/module-kind.js.map +1 -1
- package/dist/generate/kinds/repository-line.d.ts +4 -0
- package/dist/generate/kinds/repository-line.d.ts.map +1 -0
- package/dist/generate/kinds/repository-line.js +5 -0
- package/dist/generate/kinds/repository-line.js.map +1 -0
- package/dist/generate/kinds/wire-repository-on-first-use.d.ts +3 -2
- package/dist/generate/kinds/wire-repository-on-first-use.d.ts.map +1 -1
- package/dist/generate/kinds/wire-repository-on-first-use.js +8 -3
- package/dist/generate/kinds/wire-repository-on-first-use.js.map +1 -1
- package/dist/generate/registration.d.ts +10 -0
- package/dist/generate/registration.d.ts.map +1 -0
- package/dist/generate/registration.js +2 -0
- package/dist/generate/registration.js.map +1 -0
- package/dist/generate/wire.d.ts +5 -2
- package/dist/generate/wire.d.ts.map +1 -1
- package/dist/generate/wire.js +6 -3
- package/dist/generate/wire.js.map +1 -1
- package/dist/generate/wirings.d.ts +2 -1
- package/dist/generate/wirings.d.ts.map +1 -1
- package/dist/generate/wirings.js +25 -4
- package/dist/generate/wirings.js.map +1 -1
- package/dist/init/files/persistence-files.d.ts.map +1 -1
- package/dist/init/files/persistence-files.js +5 -2
- package/dist/init/files/persistence-files.js.map +1 -1
- package/dist/init/manifest/versions.js +24 -24
- package/dist/model-modules/index.d.ts +4 -0
- package/dist/model-modules/index.d.ts.map +1 -1
- package/dist/model-modules/index.js +4 -0
- package/dist/model-modules/index.js.map +1 -1
- package/dist/model-modules/module-file-of.d.ts +7 -0
- package/dist/model-modules/module-file-of.d.ts.map +1 -0
- package/dist/model-modules/module-file-of.js +9 -0
- package/dist/model-modules/module-file-of.js.map +1 -0
- package/dist/model-modules/module-of-module-file.d.ts +3 -0
- package/dist/model-modules/module-of-module-file.d.ts.map +1 -0
- package/dist/model-modules/module-of-module-file.js +6 -0
- package/dist/model-modules/module-of-module-file.js.map +1 -0
- package/dist/model-modules/wiring-files-of.d.ts +4 -0
- package/dist/model-modules/wiring-files-of.d.ts.map +1 -0
- package/dist/model-modules/wiring-files-of.js +6 -0
- package/dist/model-modules/wiring-files-of.js.map +1 -0
- package/dist/model-modules/wiring-text-of.d.ts +5 -0
- package/dist/model-modules/wiring-text-of.d.ts.map +1 -0
- package/dist/model-modules/wiring-text-of.js +8 -0
- package/dist/model-modules/wiring-text-of.js.map +1 -0
- package/dist/presets/apply-preset.d.ts.map +1 -1
- package/dist/presets/apply-preset.js +5 -0
- package/dist/presets/apply-preset.js.map +1 -1
- package/dist/presets/identity-preset.d.ts.map +1 -1
- package/dist/presets/identity-preset.js +1 -0
- package/dist/presets/identity-preset.js.map +1 -1
- package/dist/presets/no-flags.d.ts.map +1 -1
- package/dist/presets/no-flags.js +1 -0
- package/dist/presets/no-flags.js.map +1 -1
- package/dist/presets/preset.d.ts +6 -0
- package/dist/presets/preset.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspace/workspace.d.ts +2 -1
- package/dist/workspace/workspace.d.ts.map +1 -1
- package/dist/workspace/workspace.js +6 -5
- package/dist/workspace/workspace.js.map +1 -1
- package/package.json +4 -4
- package/templates/command/handler.declared.ts.tpl +39 -1
- package/templates/command/handler.spec.buses.ts.tpl +4 -4
- package/templates/command/handler.spec.tsyringe.ts.tpl +2 -2
- package/templates/command/handler.ts.tpl +38 -1
- package/templates/command/wiring.manual.tpl +4 -1
- package/templates/command/wiring.tsyringe.tpl +7 -2
- package/templates/e2e/e2e-job-case.ts.tpl +8 -0
- package/templates/e2e/e2e-job.spec.ts.tpl +43 -0
- package/templates/init/e2e/start-application.database.ts.tpl +94 -9
- package/templates/init/e2e/start-application.memory.ts.tpl +76 -9
- package/templates/init/jest.config.js.tpl +11 -2
- package/templates/init/platform/composition/compose-application.manual.ts.tpl +11 -2
- package/templates/init/platform/composition/compose-application.tsyringe.ts.tpl +4 -0
- package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +1 -5
- package/templates/init/platform/database/open-test-database.knex.ts.tpl +1 -5
- package/templates/init/platform/database/open-test-database.prisma.ts.tpl +1 -5
- package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +1 -5
- package/templates/init/platform/database/test-database-teardown.ts.tpl +11 -0
- package/templates/init/platform/database/test-database-template.ts.tpl +16 -1
- package/templates/init/rules/tests.md.tpl +1 -1
- package/templates/module/module-file.manual.ts.tpl +46 -0
- package/templates/module/module-file.tsyringe.ts.tpl +14 -0
- package/templates/module/wiring.manual.tpl +14 -0
- package/templates/module/wiring.tsyringe.tpl +6 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/presets/identity/context/__context__.module.explicit.ts.tpl +10 -4
- package/templates/presets/identity/e2e/support.wiring.tpl +17 -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
|
-
|
|
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
|
|
157
|
-
|
|
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
|
-
|
|
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
|
|
163
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
+
};
|