File size: 1,233 Bytes
6c928c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
import { describe, it, expect, vi } from "vitest";

vi.mock("../curl-binary.js", () => ({
  resolveCurlBinary: () => "/mock/bin/curl-impersonate",
  getChromeTlsArgs: () => [],
  getProxyArgs: () => [],
  isImpersonate: () => true,
}));

import { formatSpawnError } from "../curl-cli-transport.js";

describe("formatSpawnError", () => {
  it("returns architecture mismatch hint for errno -86 (EBADARCH)", () => {
    const err = Object.assign(new Error("spawn Unknown system error -86"), { errno: -86 });
    const msg = formatSpawnError(err);
    expect(msg).toContain("wrong CPU architecture");
    expect(msg).toContain(process.arch);
    expect(msg).toContain("npm run setup");
    expect(msg).toContain("/mock/bin/curl-impersonate");
  });

  it("detects -86 from error message when errno is not set", () => {
    const err = new Error("spawn Unknown system error -86");
    const msg = formatSpawnError(err);
    expect(msg).toContain("wrong CPU architecture");
  });

  it("returns generic message for other spawn errors", () => {
    const err = new Error("spawn ENOENT");
    const msg = formatSpawnError(err);
    expect(msg).toBe("curl spawn error: spawn ENOENT");
    expect(msg).not.toContain("architecture");
  });
});