1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix integration tests and markdown

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-01-25 16:52:54 -05:00
parent bfc335a43c
commit 2ee1d3d794
3 changed files with 51 additions and 7 deletions

View File

@ -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.

View File

@ -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"),
]);
});
});

View File

@ -113,3 +113,47 @@ export async function listHelmRepositories(retries = 0): Promise<HelmRepository
return [];
}
const rendererLogPrefixMatcher = /^\[[0-9]{5}:[0-9]{4}\/[0-9]{6}\.[0-9]{6}:[A-Z]+:CONSOLE\([0-9)]+\)\]/;
/**
* Wait for all of `values` to be part of the logs. Does not clear logs. Does
* not work well with `app.client.get(Main|Renderer)ProcessLogs()`
*
* Note: this is a "best attempt" since spectron's `getMainProcessLogs` sometimes
* contains `renderer` logs.
* @param app The spectron app that we are testing against
* @param source Whether to wait for renderer or main logs
* @param values The list of strings that should all be contained in the logs
*/
export async function waitForLogsToContain(app: Application, source: "renderer" | "main", ...values: string[]): Promise<void> {
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
}
}