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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115/** Unit tests for `name@version` spec parsing and exclude-entry expansion.
@module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { expandExcludeEntry, PackageSpecError, parsePackageSpec,} from './spec.ts';
/** Captures a synchronous throw for assertion.
@param fn - code expected to throw
@returns thrown value, or a marker string when nothing was thrown
@example ```ts expect(caught(() => parsePackageSpec('a'))).toBeInstanceOf(PackageSpecError); ``` */function caught(fn: () => unknown,): unknown { try { fn(); return 'did not throw'; } catch (error) { return error; }}
await describe({ name: '', children: [ describe({ name: parsePackageSpec.name, children: [ it({ name: 'splits a scoped spec at its last @', fn: async () => { expect(parsePackageSpec('@earendil-works/chord@0.87.1',),).toEqual({ name: '@earendil-works/chord', version: '0.87.1', },); }, },), it({ name: 'splits an unscoped spec', fn: async () => { expect(parsePackageSpec('left-pad@1.3.0',),).toEqual({ name: 'left-pad', version: '1.3.0', },); }, },), ...['left-pad', '@scope/name', 'left-pad@', '@1.0.0',].map(function rejects(spec,) { return it({ name: `rejects ${JSON.stringify(spec,)}`, fn: async () => { expect(caught(function parse(): unknown { return parsePackageSpec(spec,); },),).toBeInstanceOf(PackageSpecError,); }, },); },), ], },), describe({ name: expandExcludeEntry.name, children: [ it({ name: 'expands a merged version union', fn: async () => { expect(expandExcludeEntry('a@1.0.0 || 1.1.0',),).toEqual([ { name: 'a', version: '1.0.0', }, { name: 'a', version: '1.1.0', }, ],); }, },), ...['left-pad', '@scope/*', '@earendil-works/pi-*',].map(function bare(entry,) { return it({ name: `expands bare pattern ${entry} to nothing`, fn: async () => { expect(expandExcludeEntry(entry,),).toEqual([],); }, },); },), it({ name: 'rejects an empty version inside a union', fn: async () => { expect(caught(function expand(): unknown { return expandExcludeEntry('a@1.0.0 || ',); },),).toBeInstanceOf(PackageSpecError,); }, },), ], },), ],},);