fix: address cubic 4/5 review issues
- Preserve encoding/callback args in stdout.write wrapper (json-output.ts) - Restore global console spy in afterEach (server-connection.test.ts) - Restore console.error spy in afterEach (on-complete-hook.test.ts)
This commit is contained in:
parent
4059d02047
commit
eafcac1593
@ -20,9 +20,9 @@ export function createJsonOutputManager(
|
|||||||
const originalWrite = stdout.write.bind(stdout)
|
const originalWrite = stdout.write.bind(stdout)
|
||||||
|
|
||||||
function redirectToStderr(): void {
|
function redirectToStderr(): void {
|
||||||
stdout.write = function (chunk: string): boolean {
|
stdout.write = function (...args: Parameters<NodeJS.WriteStream["write"]>): boolean {
|
||||||
return stderr.write(chunk)
|
return (stderr.write as Function).apply(stderr, args)
|
||||||
}
|
} as NodeJS.WriteStream["write"]
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore(): void {
|
function restore(): void {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, spyOn, beforeEach } from "bun:test"
|
import { describe, it, expect, spyOn, beforeEach, afterEach } from "bun:test"
|
||||||
import { executeOnCompleteHook } from "./on-complete-hook"
|
import { executeOnCompleteHook } from "./on-complete-hook"
|
||||||
|
|
||||||
describe("executeOnCompleteHook", () => {
|
describe("executeOnCompleteHook", () => {
|
||||||
@ -9,8 +9,14 @@ describe("executeOnCompleteHook", () => {
|
|||||||
} as unknown as ReturnType<typeof Bun.spawn>
|
} as unknown as ReturnType<typeof Bun.spawn>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let consoleErrorSpy: ReturnType<typeof spyOn<typeof console, "error">>
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(console, "error").mockImplementation(() => {})
|
consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
consoleErrorSpy.mockRestore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("executes command with correct env vars", async () => {
|
it("executes command with correct env vars", async () => {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import { describe, it, expect, mock, beforeEach, afterEach } from "bun:test"
|
import { describe, it, expect, mock, beforeEach, afterEach } from "bun:test"
|
||||||
|
|
||||||
|
const originalConsole = globalThis.console
|
||||||
|
|
||||||
const mockServerClose = mock(() => {})
|
const mockServerClose = mock(() => {})
|
||||||
const mockCreateOpencode = mock(() =>
|
const mockCreateOpencode = mock(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
@ -36,6 +38,10 @@ describe("createServerConnection", () => {
|
|||||||
globalThis.console = { ...console, log: mockConsoleLog } as typeof console
|
globalThis.console = { ...console, log: mockConsoleLog } as typeof console
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
globalThis.console = originalConsole
|
||||||
|
})
|
||||||
|
|
||||||
it("attach mode returns client with no-op cleanup", async () => {
|
it("attach mode returns client with no-op cleanup", async () => {
|
||||||
// given
|
// given
|
||||||
const signal = new AbortController().signal
|
const signal = new AbortController().signal
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user