forked from osbuild/image-builder-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/test/jest.setup.js: add log supressor
Also filters warnings due to data-driven-forms/react-forms#1352 from the test logs.
- Loading branch information
1 parent
1697ae8
commit 414e819
Showing
2 changed files
with
64 additions
and
1 deletion.
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,63 @@ | ||
import 'whatwg-fetch'; | ||
import { server } from './mocks/server'; | ||
|
||
jest.mock('@unleash/proxy-client-react', () => ({ | ||
useUnleashContext: () => jest.fn(), | ||
useFlag: jest.fn(() => true), | ||
})); | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
// Upgrading @patternfly/react-core caused propTypes error in Pf4FormTemplate | ||
// https://github.com/data-driven-forms/react-forms/issues/1352 | ||
const filter1 = (args) => { | ||
if ( | ||
args[2] === | ||
'Invalid prop `FormWrapper` supplied to `FormTemplate`, expected one of type [function].' | ||
) { | ||
return [true, args[2]]; | ||
} | ||
return [false, null]; | ||
}; | ||
|
||
class FilteredConsole { | ||
constructor(console) { | ||
this.console = console; | ||
this.filters = [filter1]; | ||
} | ||
|
||
logSuppressedError(err) { | ||
this.console.info('Suppressed error: ', err); | ||
} | ||
|
||
filter(...args) { | ||
for (let fn of this.filters) { | ||
const [f, msg] = fn(args); | ||
if (f) { | ||
this.logSuppressedError(msg); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
log(...args) { | ||
this.console.log(...args); | ||
} | ||
|
||
info(...args) { | ||
this.console.info(...args); | ||
} | ||
|
||
warn(...args) { | ||
if (!this.filter(...args)) this.console.warn(...args); | ||
} | ||
|
||
error(...args) { | ||
if (!this.filter(...args)) this.console.error(...args); | ||
} | ||
} | ||
|
||
window.console = new FilteredConsole(window.console); |