File tree 4 files changed +23
-13
lines changed
4 files changed +23
-13
lines changed Original file line number Diff line number Diff line change 1
1
import { commit , getPackageJson , version } from "../../src/node/constants"
2
- import { loggerModule } from "../utils/helpers"
2
+ import { createLoggerMock } from "../utils/helpers"
3
3
4
4
// jest.mock is hoisted above the imports so we must use `require` here.
5
+ const loggerModule = createLoggerMock ( )
5
6
jest . mock ( "@coder/logger" , ( ) => require ( "../utils/helpers" ) . loggerModule )
6
7
7
8
describe ( "constants" , ( ) => {
Original file line number Diff line number Diff line change 1
1
import { JSDOM } from "jsdom"
2
2
import { registerServiceWorker } from "../../src/browser/register"
3
- import { loggerModule } from "../utils/helpers"
3
+ import { createLoggerMock } from "../utils/helpers"
4
4
import { LocationLike } from "./util.test"
5
5
6
6
describe ( "register" , ( ) => {
@@ -21,6 +21,8 @@ describe("register", () => {
21
21
} )
22
22
} )
23
23
24
+ const loggerModule = createLoggerMock ( )
25
+
24
26
beforeEach ( ( ) => {
25
27
jest . clearAllMocks ( )
26
28
jest . mock ( "@coder/logger" , ( ) => loggerModule )
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
11
11
trimSlashes ,
12
12
normalize ,
13
13
} from "../../src/common/util"
14
- import { loggerModule } from "../utils/helpers"
14
+ import { createLoggerMock } from "../utils/helpers"
15
15
16
16
const dom = new JSDOM ( )
17
17
global . document = dom . window . document
@@ -229,6 +229,8 @@ describe("util", () => {
229
229
jest . restoreAllMocks ( )
230
230
} )
231
231
232
+ const loggerModule = createLoggerMock ( )
233
+
232
234
it ( "should log an error with the message and stack trace" , ( ) => {
233
235
const message = "You don't have access to that folder."
234
236
const error = new Error ( message )
Original file line number Diff line number Diff line change @@ -2,16 +2,21 @@ import * as fs from "fs"
2
2
import * as os from "os"
3
3
import * as path from "path"
4
4
5
- export const loggerModule = {
6
- field : jest . fn ( ) ,
7
- level : 2 ,
8
- logger : {
9
- debug : jest . fn ( ) ,
10
- error : jest . fn ( ) ,
11
- info : jest . fn ( ) ,
12
- trace : jest . fn ( ) ,
13
- warn : jest . fn ( ) ,
14
- } ,
5
+ /**
6
+ * Return a mock of @coder/logger.
7
+ */
8
+ export function createLoggerMock ( ) {
9
+ return {
10
+ field : jest . fn ( ) ,
11
+ level : 2 ,
12
+ logger : {
13
+ debug : jest . fn ( ) ,
14
+ error : jest . fn ( ) ,
15
+ info : jest . fn ( ) ,
16
+ trace : jest . fn ( ) ,
17
+ warn : jest . fn ( ) ,
18
+ } ,
19
+ }
15
20
}
16
21
17
22
/**
You can’t perform that action at this time.
0 commit comments