diff --git a/integration/__tests__/app.tests.ts b/integration/__tests__/app.tests.ts index e744a24c74..cf03bccf7c 100644 --- a/integration/__tests__/app.tests.ts +++ b/integration/__tests__/app.tests.ts @@ -13,7 +13,6 @@ import * as utils from "../helpers/utils"; import { listHelmRepositories } from "../helpers/utils"; import { fail } from "assert"; - jest.setTimeout(60000); // FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below) @@ -21,9 +20,11 @@ describe("Lens integration tests", () => { let app: Application; describe("app start", () => { - beforeAll(async () => app = await utils.appStart(), 20000); + utils.beforeAllWrapped(async () => { + app = await utils.appStart(); + }); - afterAll(async () => { + utils.afterAllWrapped(async () => { if (app?.isRunning()) { await utils.tearDown(app); } diff --git a/integration/__tests__/cluster-pages.tests.ts b/integration/__tests__/cluster-pages.tests.ts index 510110707e..ed2340f86f 100644 --- a/integration/__tests__/cluster-pages.tests.ts +++ b/integration/__tests__/cluster-pages.tests.ts @@ -33,10 +33,12 @@ describe("Lens cluster pages", () => { }; describe("cluster add", () => { - beforeAll(async () => app = await utils.appStart(), 20000); + utils.beforeAllWrapped(async () => { + app = await utils.appStart(); + }); - afterAll(async () => { - if (app && app.isRunning()) { + utils.afterAllWrapped(async () => { + if (app?.isRunning()) { return utils.tearDown(app); } }); @@ -64,11 +66,10 @@ describe("Lens cluster pages", () => { } describe("cluster pages", () => { + utils.beforeAllWrapped(appStartAddCluster); - beforeAll(appStartAddCluster, 40000); - - afterAll(async () => { - if (app && app.isRunning()) { + utils.afterAllWrapped(async () => { + if (app?.isRunning()) { return utils.tearDown(app); } }); @@ -355,10 +356,10 @@ describe("Lens cluster pages", () => { }); describe("viewing pod logs", () => { - beforeEach(appStartAddCluster, 40000); + utils.beforeEachWrapped(appStartAddCluster); - afterEach(async () => { - if (app && app.isRunning()) { + utils.afterEachWrapped(async () => { + if (app?.isRunning()) { return utils.tearDown(app); } }); @@ -405,10 +406,10 @@ describe("Lens cluster pages", () => { }); describe("cluster operations", () => { - beforeEach(appStartAddCluster, 40000); + utils.beforeEachWrapped(appStartAddCluster); - afterEach(async () => { - if (app && app.isRunning()) { + utils.afterEachWrapped(async () => { + if (app?.isRunning()) { return utils.tearDown(app); } }); diff --git a/integration/__tests__/command-palette.tests.ts b/integration/__tests__/command-palette.tests.ts index 789806c445..08da064bd2 100644 --- a/integration/__tests__/command-palette.tests.ts +++ b/integration/__tests__/command-palette.tests.ts @@ -7,9 +7,11 @@ describe("Lens command palette", () => { let app: Application; describe("menu", () => { - beforeAll(async () => app = await utils.appStart(), 20000); + utils.beforeAllWrapped(async () => { + app = await utils.appStart(); + }); - afterAll(async () => { + utils.afterAllWrapped(async () => { if (app?.isRunning()) { await utils.tearDown(app); } diff --git a/integration/__tests__/workspace.tests.ts b/integration/__tests__/workspace.tests.ts index 4164151b0f..6ad56d5255 100644 --- a/integration/__tests__/workspace.tests.ts +++ b/integration/__tests__/workspace.tests.ts @@ -13,13 +13,13 @@ describe("Lens integration tests", () => { const ready = minikubeReady("workspace-int-tests"); utils.describeIf(ready)("workspaces", () => { - beforeAll(async () => { + utils.beforeAllWrapped(async () => { app = await utils.appStart(); await utils.clickWhatsNew(app); - }, 20000); + }); - afterAll(async () => { - if (app && app.isRunning()) { + utils.afterAllWrapped(async () => { + if (app?.isRunning()) { return utils.tearDown(app); } }); diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index 1db9af1c4d..c7fd4e8ddb 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -8,6 +8,39 @@ const AppPaths: Partial> = { "darwin": "./dist/mac/Lens.app/Contents/MacOS/Lens", }; +interface DoneCallback { + (...args: any[]): any; + fail(error?: string | { message: string }): any; +} + +/** + * This is necessary because Jest doesn't do this correctly. + * @param fn The function to call + */ +export function wrapJestLifecycle(fn: () => Promise): (done: DoneCallback) => void { + return function (done: DoneCallback) { + fn() + .then(() => done()) + .catch(error => done.fail(error)); + }; +} + +export function beforeAllWrapped(fn: () => Promise): void { + beforeAll(wrapJestLifecycle(fn)); +} + +export function beforeEachWrapped(fn: () => Promise): void { + beforeEach(wrapJestLifecycle(fn)); +} + +export function afterAllWrapped(fn: () => Promise): void { + afterAll(wrapJestLifecycle(fn)); +} + +export function afterEachWrapped(fn: () => Promise): void { + afterEach(wrapJestLifecycle(fn)); +} + export function itIf(condition: boolean) { return condition ? it : it.skip; }