@cmodjs/core 8.3.0 → 8.3.1
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/docs/dependencies.md +1 -1
- package/docs/testing.md +2 -0
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +10 -7
- package/mod.d.ts +282 -0
- package/mod.d.ts.map +1 -1
- package/package.json +1 -1
- package/records.d.ts +1 -1
- package/records.js +1 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +14 -5
- package/runtime/interfaces.d.ts +8 -1
- package/runtime/interfaces.d.ts.map +1 -1
- package/runtime/interfaces.js +23 -6
- package/src/jobs/program.ts +8 -4
- package/src/mod.ts +55 -0
- package/src/records.ts +1 -1
- package/src/runtime/conversations.ts +15 -7
- package/src/runtime/interfaces.ts +25 -5
- package/src/testing/fake-serve.ts +14 -5
- package/src/testing.ts +32 -15
- package/testing/fake-serve.d.ts.map +1 -1
- package/testing/fake-serve.js +15 -7
- package/testing.d.ts +4 -1
- package/testing.d.ts.map +1 -1
- package/testing.js +30 -8
package/testing.js
CHANGED
|
@@ -245,26 +245,48 @@ export function testMod(definition, options = {}) {
|
|
|
245
245
|
after,
|
|
246
246
|
report,
|
|
247
247
|
});
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
return undefined;
|
|
248
|
+
const inSession = (index) => {
|
|
249
|
+
const { name: named, mod, methods } = given[index];
|
|
251
250
|
const made = sessionMods.get(mod) ?? createProviders({ name: mod, call: (_to, method, input) => served.answer(method, input, mod) ?? Promise.reject(new Error(`${mod} reaches no ${method} in the test kit.`)), changed: () => undefined, after, report });
|
|
252
251
|
sessionMods.set(mod, made);
|
|
253
252
|
return made.provide(named, methods);
|
|
254
|
-
}
|
|
253
|
+
};
|
|
254
|
+
const asProgram = (index) => {
|
|
255
|
+
const { name: named, mod, program, device, methods } = given[index];
|
|
256
|
+
return { name: named, mod, program: program, ...(device === undefined ? {} : { device }), methods };
|
|
257
|
+
};
|
|
258
|
+
const isFirst = (index) => given[index]?.isStarted !== false;
|
|
259
|
+
const providedInSession = given.map((each, index) => (each.program === undefined && isFirst(index) ? inSession(index) : undefined));
|
|
260
|
+
const late = new Map();
|
|
261
|
+
const startLate = (index) => {
|
|
262
|
+
const known = late.get(index);
|
|
263
|
+
if (known !== undefined)
|
|
264
|
+
return known;
|
|
265
|
+
const started = fakeProviders().then(async () => (given[index]?.program === undefined ? inSession(index) : (await fake.serve.provide([asProgram(index)], { after, report }))[0]));
|
|
266
|
+
late.set(index, started);
|
|
267
|
+
return started;
|
|
268
|
+
};
|
|
255
269
|
let fakesReady;
|
|
256
270
|
const fakeProviders = () => (fakesReady ??= (async () => {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
return
|
|
271
|
+
const first = given.flatMap((each, index) => (each.program !== undefined && isFirst(index) ? [index] : []));
|
|
272
|
+
const programs = await fake.serve.provide(first.map(asProgram), { after, report });
|
|
273
|
+
return given.map((_each, index) => providedInSession[index] ?? (first.includes(index) ? programs[first.indexOf(index)] : undefined));
|
|
260
274
|
})());
|
|
261
275
|
const fakeProvider = (index) => {
|
|
262
276
|
const reached = async () => {
|
|
263
|
-
const
|
|
277
|
+
const started = late.get(index);
|
|
278
|
+
const each = (await fakeProviders())[index] ?? (started === undefined ? undefined : await started);
|
|
279
|
+
if (each === undefined)
|
|
280
|
+
throw new Error(`The test kit's fake provider ${index} has isStarted: false, so start() it before it tells, asks, or leaves.`);
|
|
264
281
|
await fake.settle();
|
|
265
282
|
return each;
|
|
266
283
|
};
|
|
267
284
|
return {
|
|
285
|
+
start: () => {
|
|
286
|
+
if (isFirst(index))
|
|
287
|
+
throw new Error(`The test kit's fake provider ${index} runs from the start. Give it isStarted: false to start it later.`);
|
|
288
|
+
void modeling(startLate(index).then(() => fake.settle()));
|
|
289
|
+
},
|
|
268
290
|
remove: () => void modeling(reached().then((each) => each.remove())),
|
|
269
291
|
tell: (event, payload) => void modeling(reached().then((each) => each.tell(event, payload))),
|
|
270
292
|
ask: (event, payload) => modeling(reached().then((each) => each.ask(event, payload))),
|