refactor(register): use logError instead of logger

This commit is contained in:
Joe Previte 2021-02-22 14:23:16 -07:00
parent 38891de0d9
commit 7ef630f7a4
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
2 changed files with 6 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -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", () => {