-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc848fd
commit 33c4652
Showing
3 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Logger } from "../log"; | ||
import { logger } from "../log"; | ||
|
||
describe("logger", () => { | ||
const mockDate = new Date(0); | ||
const spy = jest.spyOn(global, "Date").mockImplementation(() => mockDate); | ||
|
||
const patternTest = [ | ||
["DEBUG", "debug"], | ||
["INFO", "info"], | ||
["WARN", "warn"], | ||
["ERROR", "error"], | ||
["FATAL", "fatal"], | ||
]; | ||
it.each(patternTest)( | ||
`should show the %s log when calling logger with %s level`, | ||
(logDisplay, logLevel) => { | ||
const consoleMock = jest | ||
.spyOn(console, "error") | ||
.mockImplementation(() => { | ||
return true; | ||
}); | ||
|
||
logger[logLevel as keyof Logger]("This is an example message."); | ||
|
||
expect(consoleMock).toHaveBeenCalledTimes(1); | ||
expect(consoleMock).toHaveBeenCalledWith( | ||
expect.stringMatching( | ||
new RegExp( | ||
`\\[1970-01-01T00:00:00.000Z] (.*)${logDisplay}(.*): This is an example message.`, | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
|
||
afterAll(() => { | ||
spy.mockReset(); | ||
spy.mockRestore(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters