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

Cleanup integration and unit tests (#3531)

- Make mockWindow a function and call it when needed

- Change timeouts so that better error messages happen more often in
  integration tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-08-03 08:51:52 -04:00 committed by GitHub
parent b546f1df72
commit 4fc340d0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 57 deletions

View File

@ -19,14 +19,17 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
Object.defineProperty(window, "requestIdleCallback", {
writable: true,
value: jest.fn().mockImplementation(callback => callback()),
});
/**
* Mock the global window variable
*/
export function mockWindow() {
Object.defineProperty(window, "requestIdleCallback", {
writable: true,
value: jest.fn().mockImplementation(callback => callback()),
});
Object.defineProperty(window, "cancelIdleCallback", {
writable: true,
value: jest.fn(),
});
export default {};
Object.defineProperty(window, "cancelIdleCallback", {
writable: true,
value: jest.fn(),
});
}

View File

@ -30,7 +30,7 @@ import * as utils from "../helpers/utils";
import { listHelmRepositories } from "../helpers/utils";
import { fail } from "assert";
jest.setTimeout(60000);
jest.setTimeout(2 * 60 * 1000); // 2 minutes so that we can get better errors from spectron
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
describe("Lens integration tests", () => {
@ -38,14 +38,10 @@ describe("Lens integration tests", () => {
describe("app start", () => {
utils.beforeAllWrapped(async () => {
app = await utils.appStart();
app = await utils.setup();
});
utils.afterAllWrapped(async () => {
if (app?.isRunning()) {
await utils.tearDown(app);
}
});
utils.afterAllWrapped(() => utils.tearDown(app));
it('shows "add cluster"', async () => {
await app.electron.ipcRenderer.send("test-menu-item-click", "File", "Add Cluster");

View File

@ -33,7 +33,7 @@ import * as util from "util";
export const promiseExec = util.promisify(exec);
jest.setTimeout(60000);
jest.setTimeout(2 * 60 * 1000); // 2 minutes so that we can get better errors from spectron
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
describe("Lens cluster pages", () => {
@ -41,38 +41,36 @@ describe("Lens cluster pages", () => {
const BACKSPACE = "\uE003";
let app: Application;
const ready = minikubeReady(TEST_NAMESPACE);
let clusterAdded = false;
utils.describeIf(ready)("test common pages", () => {
let clusterAdded = false;
const addCluster = async () => {
await app.client.waitUntilTextExists("div", "Catalog");
await waitForMinikubeDashboard(app);
await app.client.click('a[href="/nodes"]');
await app.client.waitUntilTextExists("div.TableCell", "Ready");
};
const appStartAddCluster = async () => {
app = await utils.appStart();
await addCluster();
clusterAdded = true;
};
const tearDown = async () => {
await utils.tearDown(app);
clusterAdded = false;
};
describe("cluster add", () => {
utils.beforeAllWrapped(async () => {
app = await utils.appStart();
app = await utils.setup();
});
utils.afterAllWrapped(tearDown);
utils.afterAllWrapped(() => utils.tearDown(app));
it("allows to add a cluster", async () => {
await addCluster();
clusterAdded = true;
});
});
const appStartAddCluster = async () => {
if (clusterAdded) {
app = await utils.setup();
await addCluster();
}
};
function getSidebarSelectors(itemId: string) {
const root = `.SidebarItem[data-test-id="${itemId}"]`;
@ -84,7 +82,7 @@ describe("Lens cluster pages", () => {
describe("cluster pages", () => {
utils.beforeAllWrapped(appStartAddCluster);
utils.afterAllWrapped(tearDown);
utils.afterAllWrapped(() => utils.tearDown(app));
const tests: {
drawer?: string
@ -369,7 +367,7 @@ describe("Lens cluster pages", () => {
describe("viewing pod logs", () => {
utils.beforeEachWrapped(appStartAddCluster);
utils.afterEachWrapped(tearDown);
utils.afterEachWrapped(() => utils.tearDown(app));
it(`shows a log for a pod`, async () => {
expect(clusterAdded).toBe(true);
@ -397,7 +395,6 @@ describe("Lens cluster pages", () => {
// Open logs tab in dock
await app.client.click(".list .TableRow:first-child");
await app.client.waitForVisible(".Drawer");
const logsButton = "ul.KubeObjectMenu li.MenuItem i.Icon span[data-icon-name='subject']";
await app.client.waitForVisible(logsButton);
@ -419,7 +416,7 @@ describe("Lens cluster pages", () => {
describe("cluster operations", () => {
utils.beforeEachWrapped(appStartAddCluster);
utils.afterEachWrapped(tearDown);
utils.afterEachWrapped(() => utils.tearDown(app));
it("shows default namespace", async () => {
expect(clusterAdded).toBe(true);

View File

@ -22,21 +22,17 @@
import type { Application } from "spectron";
import * as utils from "../helpers/utils";
jest.setTimeout(60000);
jest.setTimeout(2 * 60 * 1000); // 2 minutes so that we can get better errors from spectron
describe("Lens command palette", () => {
let app: Application;
describe("menu", () => {
utils.beforeAllWrapped(async () => {
app = await utils.appStart();
app = await utils.setup();
});
utils.afterAllWrapped(async () => {
if (app?.isRunning()) {
await utils.tearDown(app);
}
});
utils.afterAllWrapped(() => utils.tearDown(app));
it("opens command dialog from menu", async () => {
await app.electron.ipcRenderer.send("test-menu-item-click", "View", "Command Palette...");

View File

@ -69,24 +69,20 @@ export function describeIf(condition: boolean) {
return condition ? describe : describe.skip;
}
export function setup(): Application {
return new Application({
path: AppPaths[process.platform], // path to electron app
args: [],
startTimeout: 30000,
waitTimeout: 60000,
env: {
CICD: "true"
}
});
}
export const keys = {
backspace: "\uE003"
};
export async function appStart() {
const app = setup();
export async function setup(): Promise<Application> {
const app = new Application({
path: AppPaths[process.platform], // path to electron app
args: [],
startTimeout: 60000,
waitTimeout: 10000,
env: {
CICD: "true"
}
});
await app.start();
// Wait for splash screen to be closed

View File

@ -30,6 +30,9 @@ import { ConfirmDialog } from "../../confirm-dialog";
import { ExtensionInstallationStateStore } from "../extension-install.store";
import { Extensions } from "../extensions";
import mockFs from "mock-fs";
import { mockWindow } from "../../../../../__mocks__/windowMock";
mockWindow();
jest.setTimeout(30000);
jest.mock("fs-extra");

View File

@ -22,6 +22,9 @@ import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render } from "@testing-library/react";
import { RenderDelay } from "../render-delay";
import { mockWindow } from "../../../../../__mocks__/windowMock";
mockWindow();
describe("<RenderDelay/>", () => {
it("renders w/o errors", () => {