Commit 61db02c2 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '344247-replace-setimmediate-in-tests' into 'master'

Lint against setImmediate usage in specs

See merge request gitlab-org/gitlab!80328
parents 73495489 ddfddd67
......@@ -105,6 +105,8 @@ overrides:
message: 'Avoid using "setData" on VTU wrapper'
- selector: MemberExpression[object.type!='ThisExpression'][property.type='Identifier'][property.name='$nextTick']
message: 'Using $nextTick from a component instance is discouraged. Import nextTick directly from the Vue package.'
- selector: Identifier[name='setImmediate']
message: 'Prefer explicit waitForPromises (or equivalent), or jest.runAllTimers (or equivalent) to vague setImmediate calls.'
- files:
- 'config/**/*'
- 'scripts/**/*'
......
export default function flushPromises() {
// eslint-disable-next-line no-restricted-syntax
return new Promise(setImmediate);
}
......@@ -25,6 +25,7 @@ const onRequest = () => {
// Use setImmediate to alloow the response interceptor to finish
const onResponse = (config) => {
activeRequests -= 1;
// eslint-disable-next-line no-restricted-syntax
setImmediate(() => {
events.emit('response', config);
});
......@@ -43,6 +44,7 @@ const subscribeToResponse = (predicate = () => true) =>
// If a request has been made synchronously, setImmediate waits for it to be
// processed and the counter incremented.
// eslint-disable-next-line no-restricted-syntax
setImmediate(listener);
});
......
......@@ -116,6 +116,7 @@ export default (
payload,
);
// eslint-disable-next-line no-restricted-syntax
return (result || new Promise((resolve) => setImmediate(resolve)))
.catch((error) => {
validateResults();
......
......@@ -123,6 +123,7 @@ class CustomEnvironment extends JSDOMEnvironment {
// Reset `Date` so that Jest can report timing accurately *roll eyes*...
setGlobalDateToRealDate();
// eslint-disable-next-line no-restricted-syntax
await new Promise(setImmediate);
if (this.rejectedPromises.length > 0) {
......
......@@ -8,6 +8,7 @@ initializeTestTimeout(process.env.CI ? 6000 : 500);
afterEach(() =>
// give Promises a bit more time so they fail the right test
// eslint-disable-next-line no-restricted-syntax
new Promise(setImmediate).then(() => {
// wait for pending setTimeout()s
jest.runOnlyPendingTimers();
......
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