1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Extract helpers for testing promises to test-utils

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-05-04 12:38:33 +03:00
parent 395ce7ab49
commit 16b91773ee
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
4 changed files with 28 additions and 18 deletions

View File

@ -2,7 +2,8 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import asyncFn, { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import { import {
createContainer, createContainer,
@ -10,7 +11,9 @@ import {
getInjectionToken, getInjectionToken,
} from "@ogre-tools/injectable"; } from "@ogre-tools/injectable";
import { runManyFor, Runnable } from "./run-many-for"; import type { Runnable } from "./run-many-for";
import { runManyFor } from "./run-many-for";
import { getPromiseStatus } from "../test-utils/get-promise-status";
describe("runManyFor", () => { describe("runManyFor", () => {
describe("given no hierarchy, when running many", () => { describe("given no hierarchy, when running many", () => {
@ -220,17 +223,3 @@ describe("runManyFor", () => {
}); });
}); });
}); });
const flushPromises = () => new Promise(setImmediate);
const getPromiseStatus = async (promise: Promise<unknown>) => {
const status = { fulfilled: false };
promise.finally(() => {
status.fulfilled = true;
});
await flushPromises();
return status;
};

View File

@ -0,0 +1,5 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const flushPromises = () => new Promise(setImmediate);

View File

@ -0,0 +1,17 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { flushPromises } from "./flush-promises";
export const getPromiseStatus = async (promise: Promise<unknown>) => {
const status = { fulfilled: false };
promise.finally(() => {
status.fulfilled = true;
});
await flushPromises();
return status;
};

View File

@ -42,6 +42,7 @@ import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-s
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable"; import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
import startMainApplicationInjectable from "../../../main/start-main-application/start-main-application.injectable"; import startMainApplicationInjectable from "../../../main/start-main-application/start-main-application.injectable";
import startFrameInjectable from "../../start-frame/start-frame.injectable"; import startFrameInjectable from "../../start-frame/start-frame.injectable";
import { flushPromises } from "../../../common/test-utils/flush-promises";
type Callback = (dis: DiContainers) => void | Promise<void>; type Callback = (dis: DiContainers) => void | Promise<void>;
@ -167,8 +168,6 @@ export const getApplicationBuilder = () => {
menuItem.click(undefined, undefined, undefined); menuItem.click(undefined, undefined, undefined);
const flushPromises = () => new Promise(setImmediate);
await flushPromises(); await flushPromises();
}, },
}, },