Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166/** Tests for the input-probe and mapper contracts, exercised through the public `pMap` and `pMapIterable` entry points (`mapper.ts` is package-internal). @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { MapperRequiredError, pMap, pMapIterable,} from '../dist/final/neutral/index.mjs';
await describe({ name: 'mapper and probe contracts', children: [ describe({ name: 'mapper validation', children: [ it({ name: 'rejects a missing mapper with upstream p-map message text', fn: async () => { /** Failure observed from the run's promise. */ let caught: unknown; try { await pMap({ iterable: [1], mapper: undefined as never, },); } catch (error) { caught = error; } expect(caught,).toBeInstanceOf(MapperRequiredError,); expect((caught as Error).message,).toBe('Mapper function is required',); }, },),
it({ name: 'rejects a non-function mapper', fn: async () => { /** Failure observed from the run's promise. */ let caught: unknown; try { await pMap({ iterable: [1], mapper: true as never, },); } catch (error) { caught = error; } expect(caught,).toBeInstanceOf(MapperRequiredError,); }, },),
it({ name: 'accepts a function mapper and runs it', fn: async () => { const results = await pMap({ iterable: [4], mapper: function identity(value: number,): number { return value; }, },); expect(results,).toEqual([4],); }, },),
it({ name: 'validates the mapper synchronously for the streaming map too', fn: async () => { /** Failure caught at the call site, matching upstream `pMapIterable`'s synchronous validation. */ let caught: unknown; try { pMapIterable({ iterable: [1], mapper: undefined as never, },); } catch (error) { caught = error; } expect(caught,).toBeInstanceOf(MapperRequiredError,); }, },), ], },),
describe({ name: 'input probing', children: [ it({ name: 'walks a synchronous input through the iterator probe', fn: async () => { const results = await pMap({ iterable: [ 1, 2, ], mapper: function double(value: number,): number { return value * 2; }, },); expect(results,).toEqual([ 2, 4, ],); }, },),
it({ name: 'walks an asynchronous input through the iterator probe', fn: async () => { /** Asynchronous source yielding one value. */ const asyncIterable: AsyncIterable<number> = { [Symbol.asyncIterator]: function openAsyncIterable(): AsyncIterator<number> { const cursor = { position: 0, }; return { next: async function asyncNext(): Promise<IteratorResult<number>> { if (cursor.position >= 1) return { done: true, value: undefined, }; cursor.position += 1; return { done: false, value: 7, }; }, }; }, }; const results = await pMap({ iterable: asyncIterable, mapper: function identity(value: number,): number { return value; }, },); expect(results,).toEqual([7],); }, },), ], },), ],},);