import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { mo } from 'moroutine'; describe('mo()', () => { it('returns a function', () => { const double = mo(import.meta, (x: number) => 2 * x); assert.equal(typeof double, 'function'); }); it('calling it returns a Task with correct args', () => { const double = mo(import.meta, (x: number) => 2 * x); const task = double(2); assert.deepEqual(task.args, [2]); }); it('Task is a thenable', () => { const double = mo(import.meta, (x: number) => 2 * x); const task = double(2); assert.equal(typeof task.then, 'function'); }); it('tasks from the same moroutine share an id', () => { const double = mo(import.meta, (x: number) => 2 * x); assert.equal(double(1).id, double(2).id); }); it('different moroutines have different ids', () => { const a = mo(import.meta, (x: number) => x + 1); const b = mo(import.meta, (x: number) => x + 2); assert.notEqual(a(1).id, b(1).id); }); });