Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix/Refactor] Make all logs async #3507

Merged
merged 6 commits into from
Feb 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Uncomment test
  • Loading branch information
arielj committed Feb 3, 2024
commit 64cb725576a681b8426daacf5db7da6cfbc5b5f4
74 changes: 37 additions & 37 deletions src/backend/logger/__tests__/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,43 @@ function getStringPassedToLogFile(type: logLevel, skipMessagePrefix = false) {
describeSkipOnWindows('logger/logger.ts', () => {
afterEach(jest.restoreAllMocks)

// test('log invokes console', () => {
// const spyConsoleError = jest
// .spyOn(global.console, 'error')
// .mockImplementation()
// const spyConsoleLog = jest.spyOn(global.console, 'log').mockImplementation()
// const spyConsoleWarn = jest
// .spyOn(global.console, 'warn')
// .mockImplementation()

// interface TestCaseProps {
// function: typeof logger.logError
// spyConsole: jest.SpyInstance
// }

// const testCases = new Map<logLevel, TestCaseProps>([
// ['ERROR', { function: logger.logError, spyConsole: spyConsoleError }],
// ['INFO', { function: logger.logInfo, spyConsole: spyConsoleLog }],
// ['WARNING', { function: logger.logWarning, spyConsole: spyConsoleWarn }],
// ['DEBUG', { function: logger.logDebug, spyConsole: spyConsoleLog }]
// ])

// testCases.forEach((props, level) => {
// props.function(testData, {
// prefix: logger.LogPrefix.Backend,
// skipLogToFile: true
// })

// expect(props.spyConsole).toBeCalledWith(
// expect.stringContaining(
// `${level}:${' '.repeat(7 - level.length)} [${
// logger.LogPrefix.Backend
// }]`
// ),
// ...testData
// )
// })
// })
test('log invokes console', async () => {
const spyConsoleError = jest
.spyOn(global.console, 'error')
.mockImplementation()
const spyConsoleLog = jest.spyOn(global.console, 'log').mockImplementation()
const spyConsoleWarn = jest
.spyOn(global.console, 'warn')
.mockImplementation()

interface TestCaseProps {
function: typeof logger.logError
spyConsole: jest.SpyInstance
}

const testCases = new Map<logLevel, TestCaseProps>([
['ERROR', { function: logger.logError, spyConsole: spyConsoleError }],
['INFO', { function: logger.logInfo, spyConsole: spyConsoleLog }],
['WARNING', { function: logger.logWarning, spyConsole: spyConsoleWarn }],
['DEBUG', { function: logger.logDebug, spyConsole: spyConsoleLog }]
])

testCases.forEach((props, level) => {
props.function(testData, {
prefix: logger.LogPrefix.Backend,
skipLogToFile: true
})

expect(props.spyConsole).toBeCalledWith(
expect.stringContaining(
`${level}:${' '.repeat(7 - level.length)} [${
logger.LogPrefix.Backend
}]`
),
...testData
)
})
})

test('log appends to log file', () => {
jest.spyOn(global.console, 'error').mockImplementation()
Expand Down
Loading