diff --git a/__mocks__/windowMock.ts b/__mocks__/windowMock.ts index baf8fa1a65..6f599d5038 100644 --- a/__mocks__/windowMock.ts +++ b/__mocks__/windowMock.ts @@ -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(), + }); +} diff --git a/integration/__tests__/app.tests.ts b/integration/__tests__/app.tests.ts index 7b8ff11435..450f6bd039 100644 --- a/integration/__tests__/app.tests.ts +++ b/integration/__tests__/app.tests.ts @@ -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"); diff --git a/integration/__tests__/cluster-pages.tests.ts b/integration/__tests__/cluster-pages.tests.ts index 27a0b508a8..c863903259 100644 --- a/integration/__tests__/cluster-pages.tests.ts +++ b/integration/__tests__/cluster-pages.tests.ts @@ -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); diff --git a/integration/__tests__/command-palette.tests.ts b/integration/__tests__/command-palette.tests.ts index 14e95d1264..4695f48b33 100644 --- a/integration/__tests__/command-palette.tests.ts +++ b/integration/__tests__/command-palette.tests.ts @@ -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..."); diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index d6f633e416..15fec4d20b 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -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 { + 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 diff --git a/src/renderer/components/+extensions/__tests__/extensions.test.tsx b/src/renderer/components/+extensions/__tests__/extensions.test.tsx index f51ba24575..85e88b9792 100644 --- a/src/renderer/components/+extensions/__tests__/extensions.test.tsx +++ b/src/renderer/components/+extensions/__tests__/extensions.test.tsx @@ -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"); diff --git a/src/renderer/components/render-delay/__tests__/render-delay.test.tsx b/src/renderer/components/render-delay/__tests__/render-delay.test.tsx index f81003e588..6540ec4dd9 100644 --- a/src/renderer/components/render-delay/__tests__/render-delay.test.tsx +++ b/src/renderer/components/render-delay/__tests__/render-delay.test.tsx @@ -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("", () => { it("renders w/o errors", () => {