mirror of https://git.tuxpa.in/a/code-server.git
refactor: move loggerModule into helpers
This commit is contained in:
parent
027e8e5adf
commit
711abd8d84
|
@ -1,14 +1,16 @@
|
|||
// Note: we need to import logger from the root
|
||||
// because this is the logger used in logError in ../src/common/util
|
||||
import { logger } from "../node_modules/@coder/logger"
|
||||
// import { logger } from "../node_modules/@coder/logger"
|
||||
import { commit, getPackageJson, version } from "../src/node/constants"
|
||||
import { loggerModule } from "./helpers"
|
||||
|
||||
describe("constants", () => {
|
||||
describe("getPackageJson", () => {
|
||||
let spy: jest.SpyInstance
|
||||
// let spy: jest.SpyInstance
|
||||
|
||||
beforeEach(() => {
|
||||
spy = jest.spyOn(logger, "warn")
|
||||
// spy = jest.spyOn(logger, "warn")
|
||||
jest.mock("@coder/logger", () => loggerModule)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -24,8 +26,10 @@ describe("constants", () => {
|
|||
|
||||
getPackageJson("./package.json")
|
||||
|
||||
expect(spy).toHaveBeenCalled()
|
||||
expect(spy).toHaveBeenCalledWith(expectedErrorMessage)
|
||||
// expect(spy).toHaveBeenCalled()
|
||||
// expect(spy).toHaveBeenCalledWith(expectedErrorMessage)
|
||||
expect(loggerModule.logger.warn).toHaveBeenCalled()
|
||||
expect(loggerModule.logger.warn).toHaveBeenCalledWith(expectedErrorMessage)
|
||||
})
|
||||
|
||||
it("should find the package.json", () => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { field, Level } from "@coder/logger"
|
||||
import { JSDOM } from "jsdom"
|
||||
import { loggerModule } from "./helpers"
|
||||
|
||||
describe("register", () => {
|
||||
const { window } = new JSDOM()
|
||||
|
@ -9,17 +9,6 @@ describe("register", () => {
|
|||
global.location = window.location
|
||||
|
||||
const mockRegisterFn = jest.fn()
|
||||
const loggerModule = {
|
||||
field,
|
||||
level: Level.Info,
|
||||
logger: {
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
trace: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
},
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
Object.defineProperty(global.navigator, "serviceWorker", {
|
||||
|
@ -63,5 +52,9 @@ describe("register", () => {
|
|||
|
||||
expect(mockRegisterFn).toHaveBeenCalled()
|
||||
expect(loggerModule.logger.error).toHaveBeenCalled()
|
||||
expect(loggerModule.logger.error).toHaveBeenCalledTimes(1)
|
||||
expect(loggerModule.logger.error).toHaveBeenCalledWith(
|
||||
`[Service Worker] registration: ${error.message} ${error.stack}`,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue