1
0
mirror of https://github.com/lensapp/lens.git synced 2024-09-20 13:57:23 +03:00

Try solving flaky unit test by switch to use different implementation of setImmediate (#5655)

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-06-16 16:57:32 +03:00 committed by GitHub
parent 5c049ecca0
commit 9c420d6f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -2,4 +2,6 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const flushPromises = () => new Promise(resolve => setTimeout(resolve, 0));
import { setImmediate } from "timers";
export const flushPromises = () => new Promise(setImmediate);

View File

@ -6,6 +6,7 @@
import fetchMock from "jest-fetch-mock";
import configurePackages from "./common/configure-packages";
import { configure } from "mobx";
import { setImmediate } from "timers";
// setup default configuration for external npm-packages
configurePackages();
@ -22,7 +23,7 @@ fetchMock.enableMocks();
// Mock __non_webpack_require__ for tests
globalThis.__non_webpack_require__ = jest.fn();
global.setImmediate = global.setImmediate ?? (<TArgs extends any[]>(callback: (...args: TArgs) => void, ...args: TArgs) => setTimeout(() => callback(...args), 0));
global.setImmediate = setImmediate;
global.fail = ((error = "Test failed without explicit error") => {
console.error(error);