From 2ee1d3d794fb952a70aec61d0b020b9fae8c8e6e Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 25 Jan 2021 16:52:54 -0500 Subject: [PATCH] fix integration tests and markdown Signed-off-by: Sebastian Malton --- docs/extensions/guides/protocol-handlers.md | 2 +- integration/__tests__/app.tests.ts | 12 +++--- integration/helpers/utils.ts | 44 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/docs/extensions/guides/protocol-handlers.md b/docs/extensions/guides/protocol-handlers.md index e7f2c0fc58..bd891b897a 100644 --- a/docs/extensions/guides/protocol-handlers.md +++ b/docs/extensions/guides/protocol-handlers.md @@ -6,7 +6,7 @@ Lens provides a routing mechanism that extensions can use to register custom han ## Registering A Protocol Handler -The field `protocolhandlers` exists both on [`LensMainExtension`](extensions/api/classes/lensmainextension/#protocolhandlers) and on [`LensRendererExtension`](extensions/api/classes/lensrendererextension/#protocolhandlers). +The field `protocolHandlers` exists both on [`LensMainExtension`](extensions/api/classes/lensmainextension/#protocolhandlers) and on [`LensRendererExtension`](extensions/api/classes/lensrendererextension/#protocolhandlers). This field will be iterated through every time a `lens://` request gets sent to the application. The `pathSchema` argument must comply with the [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) package's `compileToRegex` function. diff --git a/integration/__tests__/app.tests.ts b/integration/__tests__/app.tests.ts index 2329b6fe79..65e53335ea 100644 --- a/integration/__tests__/app.tests.ts +++ b/integration/__tests__/app.tests.ts @@ -30,13 +30,13 @@ describe("Lens integration tests", () => { }); describe("protocol app start", () => { - it ("should handle opening lens:// links", async () => { - await open("lens://internal/foobar?"); - await new Promise(resolve => setTimeout(resolve, 5000)); + it("should handle opening lens:// links", async () => { + await open("lens://internal/foobar"); - const logs = await app.client.getMainProcessLogs(); - - expect(logs.some(log => log.includes("no handler") || log.includes("lens://internal/foobar?"))).toBe(true); + await Promise.all([ + utils.waitForLogsToContain(app, "main", "No handler", "lens://internal/foobar"), + utils.waitForLogsToContain(app, "renderer", "No handler", "lens://internal/foobar"), + ]); }); }); diff --git a/integration/helpers/utils.ts b/integration/helpers/utils.ts index 3020bece44..79f54fe9ba 100644 --- a/integration/helpers/utils.ts +++ b/integration/helpers/utils.ts @@ -113,3 +113,47 @@ export async function listHelmRepositories(retries = 0): Promise { + const notFoundValues = new Set(values); + let lastLogLineCount = 0; + + while (notFoundValues.size > 0) { + // get all the logs (this returns both) and doesn't clear them + const curLogs = ((app as any).chromeDriver.getLogs() as string[]); + + // skip the logs already seen + const newLogs = curLogs.slice(lastLogLineCount); + + lastLogLineCount += newLogs.length; + + // filter the logs depending on whether we are waiting for logs from main or renderer + const filteredLogs = newLogs.filter(logLine => (source === "main") !== Boolean(logLine.match(rendererLogPrefixMatcher))); + + for (const logLine of filteredLogs) { + if (notFoundValues.size === 0) { + break; + } + + for (const value of notFoundValues) { + if (logLine.includes(value)) { + notFoundValues.delete(value); + } + } + } + + await new Promise(resolve => setTimeout(resolve, 500)); // long poll getting logs + } +}