From 71c37fb4d3f95ecb8acc8260dd5baf8a96f619c8 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Sat, 22 Aug 2026 16:52:13 +0800 Subject: [PATCH] test(cli): make error assertions ANSI-safe --- __tests__/cli.spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/__tests__/cli.spec.ts b/__tests__/cli.spec.ts index 0e67430..f15a698 100644 --- a/__tests__/cli.spec.ts +++ b/__tests__/cli.spec.ts @@ -1,3 +1,5 @@ +import stripAnsi from "strip-ansi"; + describe("cli tests", () => { const originalArgv = process.argv; const originalExitCode = process.exitCode; @@ -248,10 +250,10 @@ describe("cli tests", () => { ]); await new Promise((resolve) => setImmediate(resolve)); - expect(mockError).toHaveBeenCalledWith( - expect.stringContaining( - "[lint-md] The following options cannot be used with --stdin:\n--threads\n--max-file-size" - ) + // chalk wraps each line of a multiline message in ANSI codes, so + // compare against the stripped text. + expect(stripAnsi(String(mockError.mock.calls[0][0]))).toBe( + "[lint-md] The following options cannot be used with --stdin:\n--threads\n--max-file-size" ); expect(runStdinLint).not.toHaveBeenCalled(); expect(process.exitCode).toBe(1);