diff --git a/src/browser/register.ts b/src/browser/register.ts index 765580374..e430d9bf0 100644 --- a/src/browser/register.ts +++ b/src/browser/register.ts @@ -1,5 +1,4 @@ -import { logger } from "@coder/logger" -import { getOptions, Options, normalize } from "../common/util" +import { getOptions, Options, normalize, logError } from "../common/util" import "./pages/error.css" import "./pages/global.css" @@ -12,7 +11,7 @@ export async function registerServiceWorker(navigator: Navigator, path: string, }) console.log("[Service Worker] registered") } catch (error) { - logger.error(`[Service Worker] failed to register: ${error.message}`) + logError(`[Service Worker] registration`, error) } } diff --git a/test/register.test.ts b/test/register.test.ts index 421e1d4ff..799349a0b 100644 --- a/test/register.test.ts +++ b/test/register.test.ts @@ -57,6 +57,7 @@ describe("register", () => { it("should log an error if something doesn't work", () => { const message = "Can't find browser" + const error = new Error(message) const path = "/hello" const mockOptions = { base: "", @@ -64,13 +65,14 @@ describe("register", () => { logLevel: 0, } global.navigator.serviceWorker.register = () => { - throw new Error(message) + throw error } registerServiceWorker(navigator, path, mockOptions) expect(loggerSpy).toHaveBeenCalled() expect(loggerSpy).toHaveBeenCalledTimes(1) - expect(loggerSpy).toHaveBeenCalledWith(`[Service Worker] failed to register: ${message}`) + // Because we use logError, it will log the prefix along with the error message + expect(loggerSpy).toHaveBeenCalledWith(`[Service Worker] registration: ${error.message} ${error.stack}`) }) it("should work when base is undefined", () => {