-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: create test for the createLumberjackConfig
- Loading branch information
1 parent
0cc11dd
commit b9f1313
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/webworker/lumberjack/src/lib/configuration/create-lumberjack-config.spec.ts
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,55 @@ | ||
import { createFakeTime } from '@internal/core/test-util'; | ||
|
||
import { lumberjackFormatLog } from '../formatting/lumberjack-format-log'; | ||
import { createLumberjackLogFactory } from '../logging/create-lumberjack-log-factory'; | ||
import { LumberjackLog } from '../logs/lumberjack.log'; | ||
|
||
import { createLumberjackConfig } from './create-lumberjack-config'; | ||
import { defaultDevelopmentLevels } from './default-development-levels'; | ||
import { defaultProductionLevels } from './default-production-levels'; | ||
import { LumberjackConfig } from './lumberjack.config'; | ||
import { LumberjackOptions } from './lumberjack.options'; | ||
|
||
const fakeFormattedMessage = 'fake-formatted-message'; | ||
|
||
describe(createLumberjackConfig.name, () => { | ||
let mockOptions: LumberjackOptions; | ||
let mockDebugLog: LumberjackLog; | ||
|
||
const fakeTime = createFakeTime(); | ||
const logFactory = createLumberjackLogFactory({ getUnixEpochTicks: fakeTime.getUnixEpochTicks }); | ||
|
||
beforeEach(() => { | ||
mockOptions = { | ||
format: () => fakeFormattedMessage, | ||
}; | ||
mockDebugLog = logFactory.createDebugLog('fake-message').build(); | ||
}); | ||
|
||
test('should create a development environment configuration when isProductionEnvironment is false', () => { | ||
const config: LumberjackConfig = createLumberjackConfig(false, mockOptions); | ||
|
||
expect(config.format).toBeInstanceOf(Function); | ||
expect(config.format(mockDebugLog)).toBe(fakeFormattedMessage); | ||
expect(config.levels).toBe(defaultDevelopmentLevels); | ||
expect(config).toMatchObject(mockOptions); | ||
}); | ||
|
||
test('should create a production environment configuration when isProductionEnvironment is true', () => { | ||
const config: LumberjackConfig = createLumberjackConfig(true, mockOptions); | ||
|
||
expect(config.format).toBeInstanceOf(Function); | ||
expect(config.format(mockDebugLog)).toBe(fakeFormattedMessage); | ||
expect(config.levels).toBe(defaultProductionLevels); | ||
expect(config).toMatchObject(mockOptions); | ||
}); | ||
|
||
test('should handle default options correctly', () => { | ||
const config: LumberjackConfig = createLumberjackConfig(true); | ||
|
||
expect(config.format).toBeInstanceOf(Function); | ||
expect(config.format(mockDebugLog)).toBe(lumberjackFormatLog(mockDebugLog)); | ||
expect(config.levels).toBe(defaultProductionLevels); | ||
expect(config).toMatchObject({}); | ||
}); | ||
}); |