From 5701fdcaaff05f75bb4eccd6dd28d73a65e6a17b Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 16 Jun 2023 18:10:10 -0400 Subject: [PATCH] Replace snapshot with tests for error text - 7 Signed-off-by: Gene Johnston --- .../cmd/__tests__/CommandProcessor.test.ts | 23 ++++-- .../CommandProcessor.test.ts.snap | 80 ------------------- 2 files changed, 15 insertions(+), 88 deletions(-) diff --git a/packages/cmd/__tests__/CommandProcessor.test.ts b/packages/cmd/__tests__/CommandProcessor.test.ts index c14cbe296..0ce56c079 100644 --- a/packages/cmd/__tests__/CommandProcessor.test.ts +++ b/packages/cmd/__tests__/CommandProcessor.test.ts @@ -921,7 +921,7 @@ describe("Command Processor", () => { expect(stderrText).toContain("Profile loading failed!"); expect(commandResponse.message).toEqual("Profile loading failed!"); expect(commandResponse.error?.msg).toEqual("Profile loading failed!"); - expect(commandResponse.error?.additionalDetails).toEqual(undefined); + expect(commandResponse.error?.additionalDetails).not.toBeDefined(); }); it("should handle not being able to instantiate the handler", async () => { @@ -1281,12 +1281,12 @@ describe("Command Processor", () => { expect(commandResponse.message).toMatch( /Unexpected Command Error: Cannot read (property 'doesnt' of undefined|properties of undefined \(reading 'doesnt'\))/ ); - expect(commandResponse.error.msg).toMatch(/Cannot read (property 'doesnt' of undefined|properties of undefined \(reading 'doesnt'\))/); - expect(commandResponse.stdout.toString().length).toBe(0); - expect(commandResponse.stderr.toString()).toContain("Unexpected Command Error:"); - expect(commandResponse.stderr.toString()).toContain("Message:"); - expect(commandResponse.stderr.toString()).toContain("Stack:"); - expect(commandResponse.error.stack).toMatch( + expect(commandResponse?.error?.msg).toMatch(/Cannot read (property 'doesnt' of undefined|properties of undefined \(reading 'doesnt'\))/); + expect(commandResponse?.stdout?.toString().length).toBe(0); + expect(commandResponse?.stderr?.toString()).toContain("Unexpected Command Error:"); + expect(commandResponse?.stderr?.toString()).toContain("Message:"); + expect(commandResponse?.stderr?.toString()).toContain("Stack:"); + expect(commandResponse?.error?.stack).toMatch( /TypeError: Cannot read (property 'doesnt' of undefined|properties of undefined \(reading 'doesnt'\))/ ); }); @@ -1330,7 +1330,14 @@ describe("Command Processor", () => { }; const commandResponse: ICommandResponse = await processor.invoke(parms); expect(commandResponse).toBeDefined(); - expect(commandResponse).toMatchSnapshot(); + const stderrText = (commandResponse.stderr as Buffer).toString(); + expect(stderrText).toContain("Command Error:"); + expect(stderrText).toContain("Rejected with a message"); + expect(commandResponse.success).toEqual(false); + expect(commandResponse.exitCode).toEqual(1); + expect(commandResponse.message).toEqual("Rejected with a message"); + expect(commandResponse.error?.msg).toEqual("Rejected with a message"); + expect(commandResponse.error?.additionalDetails).not.toBeDefined(); }); it("should handle the handler rejecting with no messages", async () => { diff --git a/packages/cmd/__tests__/__snapshots__/CommandProcessor.test.ts.snap b/packages/cmd/__tests__/__snapshots__/CommandProcessor.test.ts.snap index bc0100c4e..eec473605 100644 --- a/packages/cmd/__tests__/__snapshots__/CommandProcessor.test.ts.snap +++ b/packages/cmd/__tests__/__snapshots__/CommandProcessor.test.ts.snap @@ -243,86 +243,6 @@ Object { } `; -exports[`Command Processor should handle the handler rejecting with a message 1`] = ` -Object { - "data": Object {}, - "error": Object { - "msg": "Rejected with a message", - }, - "exitCode": 1, - "message": "Rejected with a message", - "stderr": Object { - "data": Array [ - 27, - 91, - 51, - 49, - 109, - 67, - 111, - 109, - 109, - 97, - 110, - 100, - 32, - 69, - 114, - 114, - 111, - 114, - 58, - 27, - 91, - 51, - 57, - 109, - 10, - 27, - 91, - 51, - 49, - 109, - 27, - 91, - 51, - 57, - 109, - 82, - 101, - 106, - 101, - 99, - 116, - 101, - 100, - 32, - 119, - 105, - 116, - 104, - 32, - 97, - 32, - 109, - 101, - 115, - 115, - 97, - 103, - 101, - 10, - ], - "type": "Buffer", - }, - "stdout": Object { - "data": Array [], - "type": "Buffer", - }, - "success": false, -} -`; - exports[`Command Processor should handle the handler rejecting with no messages 1`] = ` Object { "data": Object {},