|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { createStderrTail, DockerRenderExitError } from "./dockerStderrTail.js"; |
| 3 | + |
| 4 | +describe("dockerStderrTail", () => { |
| 5 | + it("keeps only a bounded tail of stderr", () => { |
| 6 | + const tail = createStderrTail(); |
| 7 | + tail.push("a".repeat(5000)); |
| 8 | + tail.push("END"); |
| 9 | + expect(tail.tail().length).toBeLessThanOrEqual(2000); |
| 10 | + expect(tail.tail().endsWith("END")).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it("prefers the last error-looking line over trailing noise", () => { |
| 14 | + const text = "starting\nError: Page crashed\nstack frame\n"; |
| 15 | + expect(new DockerRenderExitError(1, text).message).toBe( |
| 16 | + "Docker render exited with code 1: Error: Page crashed", |
| 17 | + ); |
| 18 | + }); |
| 19 | + |
| 20 | + it("falls back to the last non-empty line", () => { |
| 21 | + expect(new DockerRenderExitError(1, "one\ntwo\n\n").message).toBe( |
| 22 | + "Docker render exited with code 1: two", |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + it("skips stack frames, splits carriage-return progress, and caps a long line", () => { |
| 27 | + const msg = (tail: string) => new DockerRenderExitError(1, tail).message; |
| 28 | + expect(msg("Error: Page crashed\n at CaptureFailure.run (x.js:1)")).toBe( |
| 29 | + "Docker render exited with code 1: Error: Page crashed", |
| 30 | + ); |
| 31 | + expect(msg("10%\r50%\rfailed to launch")).toBe( |
| 32 | + "Docker render exited with code 1: failed to launch", |
| 33 | + ); |
| 34 | + expect(msg(`error ${"x".repeat(500)}`).length).toBeLessThan(200); |
| 35 | + }); |
| 36 | + |
| 37 | + it("names the exit code and the cause in the failure message", () => { |
| 38 | + const error = new DockerRenderExitError(137, "frame 10\nKilled"); |
| 39 | + expect(error.message).toBe("Docker render exited with code 137: Killed"); |
| 40 | + expect(new DockerRenderExitError(1, "").message).toBe("Docker render exited with code 1"); |
| 41 | + }); |
| 42 | +}); |
0 commit comments