File size: 1,300 Bytes
f778c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { describe, expect, it } from "vitest";
import {
  parseOptionalFiniteNumber,
  parseOptionalPositiveInteger,
  parseOptionalTimeoutMs,
} from "./shared.js";

describe("capability CLI numeric option parsing", () => {
  it("keeps omitted optional values absent and parses valid values", () => {
    expect(parseOptionalFiniteNumber(undefined, "--duration")).toBeUndefined();
    expect(parseOptionalFiniteNumber("2.5", "--duration")).toBe(2.5);

    expect(parseOptionalPositiveInteger(undefined, "--limit")).toBeUndefined();
    expect(parseOptionalPositiveInteger("3", "--limit")).toBe(3);

    expect(parseOptionalTimeoutMs(undefined)).toBeUndefined();
    expect(parseOptionalTimeoutMs("1200")).toBe(1200);
  });

  it.each([
    ["--duration", () => parseOptionalFiniteNumber("", "--duration")],
    ["--duration", () => parseOptionalFiniteNumber("  ", "--duration")],
    ["--limit", () => parseOptionalPositiveInteger("", "--limit")],
    ["--limit", () => parseOptionalPositiveInteger("  ", "--limit")],
  ])("rejects explicit blank %s values", (label, parse) => {
    expect(parse).toThrow(`${label} must be`);
  });

  it.each(["", "  "])("rejects explicit blank --timeout-ms value %j", (raw) => {
    expect(() => parseOptionalTimeoutMs(raw)).toThrow("Invalid --timeout");
  });
});