diff --git a/test/context.test.ts b/test/context.test.ts index 0d5b6fa..c802939 100644 --- a/test/context.test.ts +++ b/test/context.test.ts @@ -1,7 +1,7 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { workers } from 'moroutine'; -import { makeCtx, makeMultiplierCtx, readCtx, addWithCtx } from './fixtures/context.ts'; +import { makeCtx, makeMultiplierCtx, readCtx, addWithCtx, prefixValue } from './fixtures/context.ts'; describe('task-arg caching', () => { it('task arg is resolved on the worker', async () => { @@ -54,13 +54,15 @@ describe('task-arg caching', () => { } }); - it('moroutine task arg resolves and caches', async () => { - const ctx = makeCtx('nested'); + it('nested task args resolve recursively', async () => { + // makeCtx('hello') is a task-arg passed to prefixValue + // prefixValue itself is the outer task dispatched to the worker + // The worker must resolve makeCtx first, then call prefixValue with the result + const ctx = makeCtx('hello'); const run = workers(1); try { - const result = await run(readCtx(ctx)); - assert.equal(result.value, 'nested'); - assert.equal(typeof result.workerInitId, 'number'); + const result = await run(prefixValue(ctx, '>>> ')); + assert.equal(result, '>>> hello'); } finally { run[Symbol.dispose](); } diff --git a/test/fixtures/context.ts b/test/fixtures/context.ts index 6d79284..0a4f220 100644 --- a/test/fixtures/context.ts +++ b/test/fixtures/context.ts @@ -21,3 +21,7 @@ export const readCtx = mo( export const addWithCtx = mo(import.meta, (ctx: { multiplier: number }, a: number, b: number): number => { return (a + b) * ctx.multiplier; }); + +export const prefixValue = mo(import.meta, (ctx: { value: string; workerInitId: number }, prefix: string): string => { + return prefix + ctx.value; +});