Commit 7fed1bff authored by Fatih Acet's avatar Fatih Acet

Merge branch 'winh-rejected-jest-promises-ee' into 'master'

Fail for unhandled Promise rejections in Jest (EE-port)

Closes gitlab-ce#56053

See merge request gitlab-org/gitlab-ee!10406
parents 49a263f8 b3b96a00
......@@ -27,6 +27,25 @@ class CustomEnvironment extends JSDOMEnvironment {
this.global.gon = {
ee: testEnvironmentOptions.IS_EE,
};
this.rejectedPromises = [];
this.global.promiseRejectionHandler = error => {
this.rejectedPromises.push(error);
};
}
async teardown() {
await new Promise(setImmediate);
if (this.rejectedPromises.length > 0) {
throw new ErrorWithStack(
`Unhandled Promise rejections: ${this.rejectedPromises.join(', ')}`,
this.teardown,
);
}
await super.teardown();
}
}
......
......@@ -5,10 +5,15 @@ import axios from '~/lib/utils/axios_utils';
import { initializeTestTimeout } from './helpers/timeout';
import { getJSONFixture, loadHTMLFixture, setHTMLFixture } from './helpers/fixtures';
// wait for pending setTimeout()s
afterEach(() => {
jest.runAllTimers();
});
process.on('unhandledRejection', global.promiseRejectionHandler);
afterEach(() =>
// give Promises a bit more time so they fail the right test
new Promise(setImmediate).then(() => {
// wait for pending setTimeout()s
jest.runAllTimers();
}),
);
initializeTestTimeout(300);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment