-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(config): add logLevel option to suppress ionic warnings and errors #30015
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18909f0
feat(core): developers can suppress ionic warnings and errors
sean-perkins f8f274b
refactor: type and code style
sean-perkins f05ecc3
fix: adjust implementation
sean-perkins d101f2e
fix: warning message format
sean-perkins 5c18c91
Merge branch 'feature-8.5' into sp/log-level
brandyscarney e3c8acd
refactor(utils): update LogLevel to enum
brandyscarney 13b1441
refactor(utils): OFF not INFO
brandyscarney b4cff16
docs(config): string types
brandyscarney 68c079a
docs(config): order
brandyscarney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
import { config } from '@global/config'; | ||
|
||
import { printIonError, printIonWarning } from '../index'; | ||
|
||
describe('Logging', () => { | ||
describe('#printIonWarning', () => { | ||
let consoleWarnSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
consoleWarnSpy = jest.spyOn(console, 'warn'); | ||
// Suppress console.warn output from polluting the test output | ||
consoleWarnSpy.mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleWarnSpy.mockRestore(); | ||
}); | ||
|
||
describe('when the logLevel configuration is not set', () => { | ||
it('logs a warning to the console', () => { | ||
config.set('logLevel', undefined); | ||
|
||
printIonWarning('This is a warning message'); | ||
|
||
expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warn]: This is a warning message'); | ||
}); | ||
}); | ||
|
||
describe("when the logLevel configuration is set to 'WARN'", () => { | ||
it('logs a warning to the console', () => { | ||
config.set('logLevel', 'WARN'); | ||
|
||
printIonWarning('This is a warning message'); | ||
|
||
expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warn]: This is a warning message'); | ||
}); | ||
}); | ||
|
||
describe("when the logLevel configuration is set to 'ERROR'", () => { | ||
it('does not log a warning to the console', () => { | ||
config.set('logLevel', 'ERROR'); | ||
|
||
printIonWarning('This is a warning message'); | ||
|
||
expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("when the logLevel configuration is set to 'OFF'", () => { | ||
it('does not log a warning to the console', () => { | ||
config.set('logLevel', 'OFF'); | ||
|
||
printIonWarning('This is a warning message'); | ||
|
||
expect(consoleWarnSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#printIonError', () => { | ||
let consoleErrorSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
consoleErrorSpy = jest.spyOn(console, 'error'); | ||
// Suppress console.error output from polluting the test output | ||
consoleErrorSpy.mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleErrorSpy.mockRestore(); | ||
}); | ||
|
||
describe('when the logLevel configuration is not set', () => { | ||
it('logs an error to the console', () => { | ||
config.set('logLevel', undefined); | ||
|
||
printIonError('This is an error message'); | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message'); | ||
}); | ||
}); | ||
|
||
describe("when the logLevel configuration is set to 'ERROR'", () => { | ||
it('logs an error to the console', () => { | ||
config.set('logLevel', 'ERROR'); | ||
|
||
printIonError('This is an error message'); | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message'); | ||
}); | ||
}); | ||
|
||
describe("when the logLevel configuration is set to 'WARN'", () => { | ||
it('logs an error to the console', () => { | ||
config.set('logLevel', 'WARN'); | ||
|
||
printIonError('This is an error message'); | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message'); | ||
}); | ||
}); | ||
|
||
describe("when the logLevel configuration is set to 'OFF'", () => { | ||
it('does not log an error to the console', () => { | ||
config.set('logLevel', 'OFF'); | ||
|
||
printIonError('This is an error message'); | ||
|
||
expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.