mirror of
https://github.com/ansible/awx.git
synced 2026-04-10 20:49:24 -02:30
fail tests if anything logs an error
This commit is contained in:
@@ -14,13 +14,29 @@ require('@nteract/mockument');
|
|||||||
// eslint-disable-next-line import/prefer-default-export
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export const asyncFlush = () => new Promise(resolve => setImmediate(resolve));
|
export const asyncFlush = () => new Promise(resolve => setImmediate(resolve));
|
||||||
|
|
||||||
// this ensures that debug messages don't get logged out to the console
|
let consoleHasError = false;
|
||||||
// while tests are running i.e. websocket connect/disconnect
|
const { error } = global.console;
|
||||||
|
|
||||||
global.console = {
|
global.console = {
|
||||||
...console,
|
...console,
|
||||||
|
// this ensures that debug messages don't get logged out to the console
|
||||||
|
// while tests are running i.e. websocket connect/disconnect
|
||||||
debug: jest.fn(),
|
debug: jest.fn(),
|
||||||
|
// fail tests that log errors.
|
||||||
|
// adapted from https://github.com/facebook/jest/issues/6121#issuecomment-708330601
|
||||||
|
error: (...args) => {
|
||||||
|
consoleHasError = true;
|
||||||
|
error(...args);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (consoleHasError) {
|
||||||
|
consoleHasError = false;
|
||||||
|
throw new Error('Error logged to console');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// This global variable is part of our Content Security Policy framework
|
// This global variable is part of our Content Security Policy framework
|
||||||
// and so this mock ensures that we don't encounter a reference error
|
// and so this mock ensures that we don't encounter a reference error
|
||||||
// when running the tests
|
// when running the tests
|
||||||
|
|||||||
Reference in New Issue
Block a user