|
| 1 | +/** |
| 2 | + * Ambient types for the portable zero-dep SPEC runner (`spec-runner.mjs`). |
| 3 | + * Keep in sync with the runtime exports used by Vitest / typecheck. |
| 4 | + */ |
| 5 | + |
| 6 | +export interface SpecOptions { |
| 7 | + bold: boolean |
| 8 | + italic: boolean |
| 9 | + boldItalic: boolean |
| 10 | + inlineCode: boolean |
| 11 | + strikethrough: boolean |
| 12 | + links: boolean |
| 13 | + images: boolean |
| 14 | + linkMode: 'protocol' | 'text-only' | string |
| 15 | + incompleteLinkPlaceholder: string |
| 16 | + incompleteImagePlaceholder: string |
| 17 | + blockMath: boolean |
| 18 | + inlineMath: boolean |
| 19 | + htmlTags: boolean |
| 20 | + tables: boolean |
| 21 | + singleTilde: boolean |
| 22 | + comparisonOperators: boolean |
| 23 | + dropTrailingOpeners: boolean |
| 24 | + setextGuard: boolean |
| 25 | + streaming: boolean |
| 26 | + [key: string]: unknown |
| 27 | +} |
| 28 | + |
| 29 | +export interface SpecCase { |
| 30 | + position: number |
| 31 | + section: string |
| 32 | + input: string |
| 33 | + expected: string |
| 34 | + options: SpecOptions |
| 35 | +} |
| 36 | + |
| 37 | +export interface SpecResult { |
| 38 | + case: SpecCase |
| 39 | + actual: string |
| 40 | + passed: boolean |
| 41 | + durationMs: number |
| 42 | + error?: string |
| 43 | +} |
| 44 | + |
| 45 | +export interface SectionSummary { |
| 46 | + section: string |
| 47 | + total: number |
| 48 | + passed: number |
| 49 | + failed: number |
| 50 | + matchRate: number |
| 51 | + durationMs: number |
| 52 | +} |
| 53 | + |
| 54 | +export interface RunSummary { |
| 55 | + total: number |
| 56 | + passed: number |
| 57 | + failed: number |
| 58 | + matchRate: number |
| 59 | + durationMs: number |
| 60 | + meanMs: number |
| 61 | + medianMs: number |
| 62 | + opsPerSec: number |
| 63 | + bySection: SectionSummary[] |
| 64 | + failures: SpecResult[] |
| 65 | + results: SpecResult[] |
| 66 | +} |
| 67 | + |
| 68 | +export interface CandidateSummary extends RunSummary { |
| 69 | + name: string |
| 70 | +} |
| 71 | + |
| 72 | +export interface RankingEntry { |
| 73 | + name: string |
| 74 | + matchRate: number |
| 75 | + passed: number |
| 76 | + failed: number |
| 77 | + durationMs: number |
| 78 | + meanMs: number |
| 79 | + opsPerSec: number |
| 80 | +} |
| 81 | + |
| 82 | +export interface CompareReport { |
| 83 | + filePath: string |
| 84 | + caseCount: number |
| 85 | + candidates: CandidateSummary[] |
| 86 | + ranking: RankingEntry[] |
| 87 | +} |
| 88 | + |
| 89 | +export type SpecFn = (input: string, opts: SpecOptions) => string |
| 90 | + |
| 91 | +export type SpecCandidate = SpecFn | { name: string; fn: SpecFn } |
| 92 | + |
| 93 | +export type MapOptions = (opts: SpecOptions, testCase: SpecCase) => SpecOptions |
| 94 | + |
| 95 | +export interface SelectOptions { |
| 96 | + section?: string | RegExp | string[] |
| 97 | + filter?: (testCase: SpecCase) => boolean |
| 98 | + verbose?: boolean |
| 99 | + warmup?: number |
| 100 | + mapOptions?: MapOptions |
| 101 | + printSummary?: boolean |
| 102 | +} |
| 103 | + |
| 104 | +export const DEFAULT_SPEC_OPTIONS: SpecOptions |
| 105 | + |
| 106 | +export function resetLegacyWarnings(): void |
| 107 | +export function parseOptsAttribute(raw: string): Partial<SpecOptions> |
| 108 | +export function resolveOptions(overrides?: Partial<SpecOptions>): SpecOptions |
| 109 | +export function applySectionHints(section: string, opts: SpecOptions): SpecOptions |
| 110 | +export function decodeEscapes(s: string): string |
| 111 | +export function parseSpecCases(md: string, filePath?: string): SpecCase[] |
| 112 | +export function loadSpecCases(filePath: string): SpecCase[] |
| 113 | +export function matchesSection(sectionTitle: string, filter: string | RegExp | string[]): boolean |
| 114 | +export function selectCases(cases: SpecCase[], options?: SelectOptions): SpecCase[] |
| 115 | +export function runSpecCases(cases: SpecCase[], fn: SpecFn, options?: SelectOptions): RunSummary |
| 116 | +export function printCompareTable(report: CompareReport): void |
| 117 | +export function formatCompareMarkdown(report: CompareReport): string |
| 118 | +export function compareSpecFile(filePath: string, candidates: SpecCandidate[], options?: SelectOptions): CompareReport |
| 119 | +export function toGenericAutoCloseOptions(opts: SpecOptions): Record<string, unknown> |
| 120 | +export function sectionAwareMapOptions(opts: SpecOptions, testCase: SpecCase): SpecOptions |
0 commit comments