mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Upgrade to electron 12 and Node 14 (#3572)
Upgrade to electron 12 and Node 14 - Compute cluster ID for tests - Switch to temporary appData path while testing Signed-off-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Sebastian Malton <smalton@mirantis.com> Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
50 files changed
+1000
-1099
No files matched your search
@@ -19,7 +19,6 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { spawnSync } from "child_process";
|
||||
import type { Application } from "spectron";
|
||||
|
||||
export function minikubeReady(testNamespace: string): boolean {
|
||||
// determine if minikube is running
|
||||
@@ -57,18 +56,3 @@ export function minikubeReady(testNamespace: string): boolean {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function waitForMinikubeDashboard(app: Application) {
|
||||
await app.client.waitUntilTextExists("div.TableCell", "minikube");
|
||||
await app.client.waitForExist(".Input.SearchInput input");
|
||||
await app.client.setValue(".Input.SearchInput input", "minikube");
|
||||
await app.client.waitUntilTextExists("div.TableCell", "minikube");
|
||||
await app.client.click("div.TableRow");
|
||||
await app.client.waitUntilTextExists("div.drawer-title-text", "KubernetesCluster: minikube");
|
||||
await app.client.waitForExist("div.EntityIcon div.HotbarIcon div div.MuiAvatar-root");
|
||||
await app.client.click("div.EntityIcon div.HotbarIcon div div.MuiAvatar-root");
|
||||
await app.client.waitUntilTextExists("pre.kube-auth-out", "Authentication proxy started");
|
||||
await app.client.waitForExist(`iframe[name="minikube"]`);
|
||||
await app.client.frame("minikube");
|
||||
await app.client.waitUntilTextExists("span.link-text", "Cluster");
|
||||
}
|
||||
@@ -18,49 +18,20 @@
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { Application } from "spectron";
|
||||
import * as util from "util";
|
||||
import { exec } from "child_process";
|
||||
import { createHash } from "crypto";
|
||||
import { mkdirp, remove } from "fs-extra";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import * as uuid from "uuid";
|
||||
import { ElectronApplication, Frame, Page, _electron as electron } from "playwright";
|
||||
import { noop } from "lodash";
|
||||
|
||||
const AppPaths: Partial<Record<NodeJS.Platform, string>> = {
|
||||
export const AppPaths: Partial<Record<NodeJS.Platform, string>> = {
|
||||
"win32": "./dist/win-unpacked/OpenLens.exe",
|
||||
"linux": "./dist/linux-unpacked/open-lens",
|
||||
"darwin": "./dist/mac/OpenLens.app/Contents/MacOS/OpenLens",
|
||||
};
|
||||
|
||||
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<void> | void): (done: DoneCallback) => void {
|
||||
return function (done: DoneCallback) {
|
||||
(async () => fn())()
|
||||
.then(() => done())
|
||||
.catch(error => done.fail(error));
|
||||
};
|
||||
}
|
||||
|
||||
export function beforeAllWrapped(fn: () => Promise<void> | void): void {
|
||||
beforeAll(wrapJestLifecycle(fn));
|
||||
}
|
||||
|
||||
export function beforeEachWrapped(fn: () => Promise<void> | void): void {
|
||||
beforeEach(wrapJestLifecycle(fn));
|
||||
}
|
||||
|
||||
export function afterAllWrapped(fn: () => Promise<void> | void): void {
|
||||
afterAll(wrapJestLifecycle(fn));
|
||||
}
|
||||
|
||||
export function afterEachWrapped(fn: () => Promise<void> | void): void {
|
||||
afterEach(wrapJestLifecycle(fn));
|
||||
}
|
||||
|
||||
export function itIf(condition: boolean) {
|
||||
return condition ? it : it.skip;
|
||||
}
|
||||
@@ -69,71 +40,80 @@ export function describeIf(condition: boolean) {
|
||||
return condition ? describe : describe.skip;
|
||||
}
|
||||
|
||||
export const keys = {
|
||||
backspace: "\uE003"
|
||||
};
|
||||
async function getMainWindow(app: ElectronApplication, timeout = 50_000): Promise<Page> {
|
||||
const deadline = Date.now() + timeout;
|
||||
|
||||
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"
|
||||
for (; Date.now() < deadline;) {
|
||||
for (const page of app.windows()) {
|
||||
if (page.url().startsWith("http://localhost")) {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await app.start();
|
||||
// Wait for splash screen to be closed
|
||||
while (await app.client.getWindowCount() > 1);
|
||||
await app.client.windowByIndex(0);
|
||||
await app.client.waitUntilWindowLoaded();
|
||||
await showCatalog(app);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
export async function showCatalog(app: Application) {
|
||||
await app.client.waitForExist("#hotbarIcon-catalog-entity .Icon");
|
||||
await app.client.click("#hotbarIcon-catalog-entity .Icon");
|
||||
}
|
||||
|
||||
type AsyncPidGetter = () => Promise<number>;
|
||||
|
||||
export async function tearDown(app?: Application) {
|
||||
if (!app?.isRunning()) {
|
||||
return;
|
||||
await new Promise(resolve => setTimeout(resolve, 2_000));
|
||||
}
|
||||
|
||||
const pid = await (app.mainProcess.pid as any as AsyncPidGetter)();
|
||||
throw new Error(`Lens did not open the main window within ${timeout}ms`);
|
||||
}
|
||||
|
||||
await app.stop();
|
||||
export async function start() {
|
||||
const CICD = path.join(os.tmpdir(), "lens-integration-testing", uuid.v4());
|
||||
|
||||
// Make sure that the directory is clear
|
||||
await remove(CICD).catch(noop);
|
||||
await mkdirp(CICD);
|
||||
|
||||
const app = await electron.launch({
|
||||
args: ["--integration-testing"], // this argument turns off the blocking of quit
|
||||
executablePath: AppPaths[process.platform],
|
||||
bypassCSP: true,
|
||||
env: {
|
||||
CICD,
|
||||
...process.env
|
||||
},
|
||||
timeout: 100_000,
|
||||
} as Parameters<typeof electron["launch"]>[0]);
|
||||
|
||||
try {
|
||||
process.kill(pid, "SIGKILL");
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
const window = await getMainWindow(app);
|
||||
|
||||
return {
|
||||
app,
|
||||
window,
|
||||
cleanup: async () => {
|
||||
await app.close();
|
||||
await remove(CICD).catch(noop);
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
await app.close();
|
||||
await remove(CICD).catch(noop);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export const promiseExec = util.promisify(exec);
|
||||
export async function clickWelcomeButton(window: Page) {
|
||||
await window.click("#hotbarIcon-catalog-entity .Icon");
|
||||
}
|
||||
|
||||
type HelmRepository = {
|
||||
name: string;
|
||||
url: string;
|
||||
};
|
||||
function minikubeEntityId() {
|
||||
return createHash("md5").update(`${path.join(os.homedir(), ".kube", "config")}:minikube`).digest("hex");
|
||||
}
|
||||
|
||||
export async function listHelmRepositories(): Promise<HelmRepository[]>{
|
||||
for (let i = 0; i < 10; i += 1) {
|
||||
try {
|
||||
const { stdout } = await promiseExec("helm repo list -o json");
|
||||
/**
|
||||
* From the catalog, click the minikube entity and wait for it to connect, returning its frame
|
||||
*/
|
||||
export async function lauchMinikubeClusterFromCatalog(window: Page): Promise<Frame> {
|
||||
await window.waitForSelector("div.TableCell");
|
||||
await window.click("div.TableCell >> text='minikube'");
|
||||
await window.waitForSelector("div.drawer-title-text >> text='KubernetesCluster: minikube'");
|
||||
await window.click("div.EntityIcon div.HotbarIcon div div.MuiAvatar-root");
|
||||
|
||||
return JSON.parse(stdout);
|
||||
} catch {
|
||||
await new Promise(r => setTimeout(r, 2000)); // if no repositories, wait for Lens adding bitnami repository
|
||||
}
|
||||
}
|
||||
const minikubeFrame = await window.waitForSelector(`#cluster-frame-${minikubeEntityId()}`);
|
||||
|
||||
return [];
|
||||
const frame = await minikubeFrame.contentFrame();
|
||||
|
||||
await frame.waitForSelector("div.Sidebar");
|
||||
|
||||
return frame;
|
||||
}
|
||||
Reference in new issue
Block a user