Move testing utilities to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-03-02 13:30:24 -05:00
1 parent 13673eaac4
commit 4fe106610a
10 files changed
+40

No files matched your search

@@ -1,7 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { setImmediate } from "timers";
export const flushPromises = () => new Promise(setImmediate);
@@ -1,17 +0,0 @@
/**
* 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;
};
@@ -1,25 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { act } from "@testing-library/react";
let usingFakeTime = false;
export const advanceFakeTime = (milliseconds: number) => {
if (!usingFakeTime) {
throw new Error("Tried to advance fake time but it was not enabled. Call useFakeTime() first.");
}
act(() => {
jest.advanceTimersByTime(milliseconds);
});
};
export const testUsingFakeTime = (dateTime = "2015-10-21T07:28:00Z") => {
usingFakeTime = true;
jest.useFakeTimers();
jest.setSystemTime(new Date(dateTime));
};
@@ -62,6 +62,7 @@ export const getOverrideFsWithFakes = () => {
ensureDirSync,
createReadStream: root.createReadStream as any,
stat: root.promises.stat as any,
unlink: root.promises.unlink,
}));
};
};