Skip to content

Commit

Permalink
👌 Add report test when init option is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Mar 2, 2022
1 parent 1049d11 commit f310e7b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions packages/logs/src/boot/startLogs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,24 @@ describe('logs', () => {
expect(logErrorSpy).not.toHaveBeenCalled()
expect(consoleLogSpy).toHaveBeenCalled()
})
})

describe('reports', () => {
let logger: Logger
let logErrorSpy: jasmine.Spy
let reportingObserverStub: ReturnType<typeof stubReportingObserver>

beforeEach(() => {
logger = new Logger(noop)
logErrorSpy = spyOn(logger, 'log')
reportingObserverStub = stubReportingObserver()
})

afterEach(() => {
reportingObserverStub.reset()
})

it('should send reports when ff forward-reports is enabled', () => {
const logger = new Logger(noop)
const logErrorSpy = spyOn(logger, 'log')
const reportingObserverStub = stubReportingObserver()
updateExperimentalFeatures(['forward-reports'])
originalStartLogs(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardReports: ['intervention'] })!,
Expand All @@ -244,28 +257,26 @@ describe('logs', () => {
expect(logErrorSpy).toHaveBeenCalled()

resetExperimentalFeatures()
reportingObserverStub.reset()
})

it('should not send reports when ff forward-reports is disabled', () => {
const logger = new Logger(noop)
const logErrorSpy = spyOn(logger, 'log')
const reportingObserverStub = stubReportingObserver()
originalStartLogs(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardReports: ['intervention'] })!,
logger
)
reportingObserverStub.raiseReport('intervention')

expect(logErrorSpy).not.toHaveBeenCalled()
})

reportingObserverStub.reset()
it('should not send reports the init option is not specified', () => {
originalStartLogs(validateAndBuildLogsConfiguration({ ...initConfiguration })!, logger)
reportingObserverStub.raiseReport('intervention')

expect(logErrorSpy).not.toHaveBeenCalled()
})

it('should add the source file information to the message for non error reports', () => {
const logger = new Logger(noop)
const logErrorSpy = spyOn(logger, 'log')
const reportingObserverStub = stubReportingObserver()
updateExperimentalFeatures(['forward-reports'])
originalStartLogs(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardReports: ['deprecation'] })!,
Expand All @@ -281,7 +292,6 @@ describe('logs', () => {
)

resetExperimentalFeatures()
reportingObserverStub.reset()
})
})

Expand Down

0 comments on commit f310e7b

Please sign in to comment.