Skip to content

Commit

Permalink
Clean up test logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpjones committed Nov 23, 2023
1 parent be08d1b commit 1c3a4fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/__tests__/GoEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
});
});

Expand Down
9 changes: 8 additions & 1 deletion src/__tests__/GoEngine_sgf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SGFTestcase = {
moves: string;
id: string;
size: number;
num_errors?: number;
};

const SGF_TEST_CASES: Array<SGFTestcase> = [
Expand Down Expand Up @@ -59,6 +60,7 @@ const SGF_TEST_CASES: Array<SGFTestcase> = [
moves: ";B[aa];W[aa]",
id: "invalid move - stone on top of stone",
size: 3,
num_errors: 1,
},
];

Expand All @@ -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`.
Expand All @@ -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);
}
},
);

Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/GobanCanvas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
});
Expand Down

0 comments on commit 1c3a4fc

Please sign in to comment.