mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-27 07:38:51 +00:00
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { formatExecuteOutput } from "./execute-output.js"
|
|
|
|
describe("execute output", () => {
|
|
test("indents a JSON result", () => {
|
|
expect(formatExecuteOutput('{"a":1,"b":[2]}')).toEqual({
|
|
json: '{\n "a": 1,\n "b": [\n 2\n ]\n}',
|
|
rest: undefined,
|
|
text: '{\n "a": 1,\n "b": [\n 2\n ]\n}',
|
|
})
|
|
})
|
|
|
|
test("indents a JSON result followed by warnings and logs", () => {
|
|
expect(formatExecuteOutput('["x"]\n\nWarnings:\n- [unhandled] boom\n\nLogs:\nhi')).toEqual({
|
|
json: '[\n "x"\n]',
|
|
rest: "Warnings:\n- [unhandled] boom\n\nLogs:\nhi",
|
|
text: '[\n "x"\n]\n\nWarnings:\n- [unhandled] boom\n\nLogs:\nhi',
|
|
})
|
|
})
|
|
|
|
test("leaves other results as they are", () => {
|
|
expect(formatExecuteOutput("exit 0\nok\n\nLogs:\nhi")).toEqual({
|
|
json: undefined,
|
|
rest: "Logs:\nhi",
|
|
text: "exit 0\nok\n\nLogs:\nhi",
|
|
})
|
|
expect(formatExecuteOutput("{not json")).toEqual({ json: undefined, rest: undefined, text: "{not json" })
|
|
})
|
|
|
|
test("keeps output without a result line as it is", () => {
|
|
expect(formatExecuteOutput("Logs:\nhi").text).toBe("Logs:\nhi")
|
|
expect(formatExecuteOutput("Warnings:\n- [unhandled] boom\n\nLogs:\nhi").text).toBe(
|
|
"Warnings:\n- [unhandled] boom\n\nLogs:\nhi",
|
|
)
|
|
})
|
|
})
|