From 1c3a4fc66e7c2b72d093112cc6dd9f1814060783 Mon Sep 17 00:00:00 2001 From: "Benjamin P. Jones" Date: Thu, 23 Nov 2023 14:58:10 -0500 Subject: [PATCH] Clean up test logs. --- src/__tests__/GoEngine.test.ts | 3 +++ src/__tests__/GoEngine_sgf.test.ts | 9 ++++++++- src/__tests__/GobanCanvas.test.ts | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/__tests__/GoEngine.test.ts b/src/__tests__/GoEngine.test.ts index f4990d2f..07ad85e7 100644 --- a/src/__tests__/GoEngine.test.ts +++ b/src/__tests__/GoEngine.test.ts @@ -477,12 +477,15 @@ describe("moves", () => { { x: 0, y: 0 }, { x: 0, y: 0 }, ]; + // Placement errors are logged, not thrown + const log_spy = jest.spyOn(console, "log").mockImplementation(() => {}); const engine = new GoEngine({ width: 2, height: 2, moves: moves }); expect(engine.board).toEqual([ [0, 0], [0, 0], ]); + expect(log_spy.mock.calls[0][0].error).toBe("Error placing black at A2 (0, 0)"); }); }); diff --git a/src/__tests__/GoEngine_sgf.test.ts b/src/__tests__/GoEngine_sgf.test.ts index 78e06b55..573629f2 100644 --- a/src/__tests__/GoEngine_sgf.test.ts +++ b/src/__tests__/GoEngine_sgf.test.ts @@ -17,6 +17,7 @@ type SGFTestcase = { moves: string; id: string; size: number; + num_errors?: number; }; const SGF_TEST_CASES: Array = [ @@ -59,6 +60,7 @@ const SGF_TEST_CASES: Array = [ moves: ";B[aa];W[aa]", id: "invalid move - stone on top of stone", size: 3, + num_errors: 1, }, ]; @@ -71,8 +73,10 @@ function rmNewlines(txt: string): string { */ test.each(SGF_TEST_CASES)( "sgf -> parseSGF() -> toSGF() roundtrip (moves only)", - ({ template, moves, id, size }) => { + ({ template, moves, size, num_errors }) => { const sgf = template.replace(/_MOVES_/, moves); + // Placement errors are logged, not thrown + const log_spy = jest.spyOn(console, "log").mockImplementation(() => {}); const goban = new TestGoban({ original_sgf: sgf, removed: "" }); // by default, `edited = true` when `original_sgf` is used, which causes // the moves to be serialized as setup SGF props `AB` & `AW`. @@ -82,6 +86,9 @@ test.each(SGF_TEST_CASES)( const moves_gen = goban.engine.move_tree.toSGF(); expect(rmNewlines(moves_gen)).toBe(rmNewlines(moves)); expect(goban.engine.move_tree.size()).toBe(size); + if (num_errors) { + expect(log_spy).toBeCalledTimes(num_errors); + } }, ); diff --git a/src/__tests__/GobanCanvas.test.ts b/src/__tests__/GobanCanvas.test.ts index 320d7589..5ec65ae8 100644 --- a/src/__tests__/GobanCanvas.test.ts +++ b/src/__tests__/GobanCanvas.test.ts @@ -214,6 +214,8 @@ describe("onTap", () => { const goban = new GobanCanvas(basic3x3Config()); const canvas = document.getElementById("board-canvas") as HTMLCanvasElement; + const log_spy = jest.spyOn(console, "info").mockImplementation(() => {}); + await socket_server.connected; goban.enableStonePlacement(); @@ -232,6 +234,11 @@ describe("onTap", () => { [0, 0, 0], [0, 0, 0], ]); + expect(log_spy).toBeCalledWith( + "Submit button pressed only ", + 40, + "ms after stone was placed, presuming bad click", + ); jest.useRealTimers(); });