Skip to content

Commit

Permalink
Add mock and rename log to logger for consistency (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
EddieAbbondanzio authored Nov 18, 2023
1 parent 3d03118 commit f1bc379
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/marqus-desktop/src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useContextMenu } from "./menus/contextMenu";
import { Editor } from "./components/Editor";
import { h100, w100 } from "./css";
import { Config } from "../shared/domain/config";
import { log } from "./logger";
import { logger } from "./logger";
import { arrayify } from "../shared/utils";
import { NoteDirectoryModal } from "./components/NoteDirectoryModal";
import { Shortcut } from "../shared/domain/shortcut";
Expand All @@ -40,7 +40,7 @@ async function main() {
initialState = loadedState.state;
initialCache = loadedState.cache;
} catch (e) {
await log.error("Fatal: Failed to initialize the app.", e as Error);
await logger.error("Fatal: Failed to initialize the app.", e as Error);
await promptFatal("Failed to initialize app.", e as Error);
return;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export function App(props: AppProps): JSX.Element {
store.on("focus.pop", pop);

const onError = async (err: ErrorEvent) => {
await log.error("Uncaught Error:", err.error);
await logger.error("Uncaught Error:", err.error);
};
window.addEventListener("error", onError);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import { PropsWithChildren } from "react";
import styled from "styled-components";
import { pb2 } from "../css";
import { log } from "../logger";
import { logger } from "../logger";
import { Store } from "../store";
import { Icon } from "./shared/Icon";

Expand Down
4 changes: 2 additions & 2 deletions packages/marqus-desktop/src/renderer/io/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { sleep } from "../../shared/utils";
import { Shortcut } from "../../shared/domain/shortcut";
import { UIEventType } from "../../shared/ui/events";
import { Section } from "../../shared/ui/app";
import { log } from "../logger";
import { logger } from "../logger";
import { BrowserWindowEvent, IpcChannel } from "../../shared/ipc";

const INITIAL_DELAY_MS = 300;
Expand Down Expand Up @@ -112,7 +112,7 @@ export function useShortcuts(store: Store): void {
if (!ev.repeat) {
const key = parseKeyCode(ev.code);
if (key == null) {
void log.info(`Unknown key: ${ev.code}`);
void logger.info(`Unknown key: ${ev.code}`);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/marqus-desktop/src/renderer/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (!isTest() && getProcessType() !== "renderer") {
);
}

export const log: Logger = {
export const logger: Logger = {
info: async message => {
// eslint-disable-next-line no-console
console.log(message);
Expand Down
4 changes: 2 additions & 2 deletions packages/marqus-desktop/src/renderer/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Note } from "../shared/domain/note";
import { Shortcut } from "../shared/domain/shortcut";
import { UIEventType, UIEventInput } from "../shared/ui/events";
import { Section, AppState, serializeAppState } from "../shared/ui/app";
import { log } from "./logger";
import { logger } from "./logger";
import { arrayify } from "../shared/utils";
import { Cache } from "../shared/ui/app";

Expand Down Expand Up @@ -205,7 +205,7 @@ export function useStore(initialState: State, initialCache?: Cache): Store {

const eventListeners: any = listeners.current[event];
if (eventListeners == null || eventListeners.length === 0) {
await log.debug(`No store listener found for ${event}.`);
await logger.debug(`No store listener found for ${event}.`);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/marqus-desktop/src/renderer/utils/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PromptOptions } from "../../shared/ui/prompt";
import { log } from "../logger";
import { logger } from "../logger";

const { ipc } = window;

Expand Down Expand Up @@ -29,7 +29,7 @@ export const promptFatal = async (
});

if (button.text === "Quit") {
await log.info("Shutting down.");
await logger.info("Shutting down.");
await ipc("app.quit");
} else if (button.text === "Reload") {
await ipc("app.reload");
Expand Down
4 changes: 2 additions & 2 deletions packages/marqus-desktop/test/renderer/App.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { App } from "../../src/renderer/App";
import { createConfig } from "../__factories__/config";
import { createCache, createState } from "../__factories__/state";
import React from "react";
import { log } from "../../src/renderer/logger";
import { logger } from "../../src/renderer/logger";

jest.mock("./../../src/renderer/logger");

Expand All @@ -16,5 +16,5 @@ test("Uncaught errors are logged.", async () => {
fireEvent.error(window);
});

expect(log.error).toBeCalledWith("Uncaught Error:", undefined);
expect(logger.error).toBeCalledWith("Uncaught Error:", undefined);
});
2 changes: 2 additions & 0 deletions packages/marqus-desktop/test/renderer/utils/prompt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { promptFatal } from "../../../src/renderer/utils/prompt";

jest.mock("../../../src/renderer/logger");

test("promptFatal", async () => {
const err = {
message: "error-message",
Expand Down

0 comments on commit f1bc379

Please sign in to comment.