mirror of https://git.tuxpa.in/a/code-server.git
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, logError } from "../common/util"
|
||||||
import { getOptions, Options, normalize } from "../common/util"
|
|
||||||
|
|
||||||
import "./pages/error.css"
|
import "./pages/error.css"
|
||||||
import "./pages/global.css"
|
import "./pages/global.css"
|
||||||
|
@ -12,7 +11,7 @@ export async function registerServiceWorker(navigator: Navigator, path: string,
|
||||||
})
|
})
|
||||||
console.log("[Service Worker] registered")
|
console.log("[Service Worker] registered")
|
||||||
} catch (error) {
|
} 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", () => {
|
it("should log an error if something doesn't work", () => {
|
||||||
const message = "Can't find browser"
|
const message = "Can't find browser"
|
||||||
|
const error = new Error(message)
|
||||||
const path = "/hello"
|
const path = "/hello"
|
||||||
const mockOptions = {
|
const mockOptions = {
|
||||||
base: "",
|
base: "",
|
||||||
|
@ -64,13 +65,14 @@ describe("register", () => {
|
||||||
logLevel: 0,
|
logLevel: 0,
|
||||||
}
|
}
|
||||||
global.navigator.serviceWorker.register = () => {
|
global.navigator.serviceWorker.register = () => {
|
||||||
throw new Error(message)
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
registerServiceWorker(navigator, path, mockOptions)
|
registerServiceWorker(navigator, path, mockOptions)
|
||||||
expect(loggerSpy).toHaveBeenCalled()
|
expect(loggerSpy).toHaveBeenCalled()
|
||||||
expect(loggerSpy).toHaveBeenCalledTimes(1)
|
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", () => {
|
it("should work when base is undefined", () => {
|
||||||
|
|
Loading…
Reference in New Issue