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 authored and GitHub committed 2021-08-03 08:51:52 -04:00
1 parent b546f1df72
commit 4fc340d0c6
7 files changed
+51 -57

No files matched your search

+3 -7
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");
+16 -19
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);
@@ -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...");
+10 -14
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