mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
fix(types): remove as type assertions from test mocks (#2913)
Add missing fields (signalCode, resourceUsage, pid, killed) to Bun.spawnSync and Bun.spawn mock return values so they satisfy the full return types without needing `as` casts or biome-ignore comments. Agent: style-reviewer Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
69a0d476a0
commit
a959a6db83
3 changed files with 13 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openrouter/spawn",
|
||||
"version": "0.25.19",
|
||||
"version": "0.25.20",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"spawn": "cli.js"
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ export function mockClackPrompts(overrides?: Partial<ClackPromptsMock>): ClackPr
|
|||
* and sprite-cov test files. Centralised here to avoid repetition.
|
||||
*/
|
||||
export function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
function createMockProc() {
|
||||
function createMockProc(): ReturnType<typeof Bun.spawn> {
|
||||
return {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
|
|
@ -201,9 +201,11 @@ export function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
|||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
killed: false,
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
signalCode: null,
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
|
|
@ -229,8 +231,7 @@ export function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
|||
};
|
||||
}
|
||||
// Return a fresh mock proc per call so ReadableStreams are not reused
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockImplementation(() => createMockProc() as ReturnType<typeof Bun.spawn>);
|
||||
return spyOn(Bun, "spawn").mockImplementation(() => createMockProc());
|
||||
}
|
||||
|
||||
// ── Fetch Mocks ────────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
|
|
@ -159,26 +159,30 @@ describe("selectFromList", () => {
|
|||
|
||||
describe("openBrowser", () => {
|
||||
it("shows URL in stderr output on linux", () => {
|
||||
// biome-ignore lint: test mock — spawnSync return type needs assertion
|
||||
const spawnSyncSpy = spyOn(Bun, "spawnSync").mockReturnValue({
|
||||
exitCode: 1,
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from(""),
|
||||
success: false,
|
||||
} satisfies Partial<ReturnType<typeof Bun.spawnSync>> as ReturnType<typeof Bun.spawnSync>);
|
||||
signalCode: null,
|
||||
resourceUsage: undefined,
|
||||
pid: 0,
|
||||
} satisfies ReturnType<typeof Bun.spawnSync>);
|
||||
openBrowser("https://example.com");
|
||||
spawnSyncSpy.mockRestore();
|
||||
expect(stderrOutput.join("")).toContain("https://example.com");
|
||||
});
|
||||
|
||||
it("shows different message when browser opens successfully", () => {
|
||||
// biome-ignore lint: test mock — spawnSync return type needs assertion
|
||||
const spawnSyncSpy = spyOn(Bun, "spawnSync").mockReturnValue({
|
||||
exitCode: 0,
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from(""),
|
||||
success: true,
|
||||
} satisfies Partial<ReturnType<typeof Bun.spawnSync>> as ReturnType<typeof Bun.spawnSync>);
|
||||
signalCode: null,
|
||||
resourceUsage: undefined,
|
||||
pid: 0,
|
||||
} satisfies ReturnType<typeof Bun.spawnSync>);
|
||||
openBrowser("https://example.com");
|
||||
spawnSyncSpy.mockRestore();
|
||||
expect(stderrOutput.join("")).toContain("https://example.com");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue