mirror of
https://github.com/danog/code-server.git
synced 2024-11-26 20:34:56 +01:00
refactor(register): use logError instead of logger
This commit is contained in:
parent
38891de0d9
commit
7ef630f7a4
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user