diff --git a/integration/__tests__/app.tests.ts b/integration/__tests__/app.tests.ts index 00e4f1ef74..30e88e602f 100644 --- a/integration/__tests__/app.tests.ts +++ b/integration/__tests__/app.tests.ts @@ -4,7 +4,6 @@ import { listHelmRepositories } from "../helpers/utils"; import { fail } from "assert"; import open from "open"; - jest.setTimeout(60000); // FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below) @@ -29,7 +28,7 @@ describe("Lens integration tests", () => { await app.client.waitUntilTextExists("h2", "Add Cluster"); }); - describe("protocol app start", () => { + describe.only("protocol app start", () => { it("should handle opening lens:// links", async () => { await open("lens://app/foobar"); diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index 31b9e0ca76..6a3ea4332e 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -1,8 +1,9 @@ import { AppConstructorOptions, Application } from "spectron"; import * as util from "util"; -import { exec } from "child_process"; -import fse from "fs-extra"; +import { exec, spawnSync } from "child_process"; +import fse, { writeFile } from "fs-extra"; import path from "path"; +import os from "os"; import { delay } from "../../src/common/utils"; interface AppTestingPaths { @@ -10,7 +11,7 @@ interface AppTestingPaths { libraryPath: string, } -function getAppTestingPaths(): AppTestingPaths { +export function getAppTestingPaths(): AppTestingPaths { switch (process.platform) { case "win32": return { @@ -69,6 +70,27 @@ export async function appStart() { await app.client.windowByIndex(0); await app.client.waitUntilWindowLoaded(); + if (process.platform === "linux") { + const testingDesktop = [ + "[Desktop Entry]", + "Name=Lens", + `Exec=${path.resolve(getAppTestingPaths().testingPath)} %U`, + "Terminal=false", + "Type=Application", + "Icon=lens", + "StartupWMClass=Lens", + "Comment=Lens - The Kubernetes IDE", + "MimeType=x-scheme-handler/lens;", + "Categories=Network;" + ].join("\n"); + + await writeFile(path.join(os.homedir(), ".local/share/applications/lens-testing.desktop"), testingDesktop); + + const { status } = spawnSync("xdg-settings set default-url-scheme-handler lens lens-testing.desktop", { shell: true }); + + expect(status).toBe(0); + } + return app; } @@ -134,6 +156,8 @@ async function* splitLogs(app: Application): AsyncGenerator(); + + for (const arg of process.argv) { + if (arg.toLowerCase().startsWith("lens://")) { + lprm.route(arg) + .catch(error => logger.error(`${LensProtocolRouterMain.LoggingPrefix}: an error occured`, { error, rawUrl: arg })); + } + } } -app.on("second-instance", () => { - console.log(process.argv); +app.on("second-instance", (event, argv) => { + const lprm = LensProtocolRouterMain.getInstance(); + + for (const arg of argv) { + if (arg.toLowerCase().startsWith("lens://")) { + lprm.route(arg) + .catch(error => logger.error(`${LensProtocolRouterMain.LoggingPrefix}: an error occured`, { error, rawUrl: arg })); + } + } + windowManager?.ensureMainWindow(); });