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

Make resolving a proxy throw if no browser window is available

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-06-21 13:18:10 +03:00
parent 01c9c740bf
commit 2f4a409a1c
2 changed files with 45 additions and 2 deletions

View File

@ -3,7 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import assert from "assert";
import electronInjectable from "./electron.injectable";
const resolveProxyFromElectronInjectable = getInjectable({
@ -17,7 +16,9 @@ const resolveProxyFromElectronInjectable = getInjectable({
.getAllWebContents()
.find((x) => !x.isDestroyed());
assert(webContent);
if (!webContent) {
throw new Error(`Tried to resolve proxy for "${url}", but no browser window was available`);
}
return await webContent.session.resolveProxy(url);
};

View File

@ -81,4 +81,46 @@ describe("technical: resolve-proxy-from-electron", () => {
expect(await actualPromise).toBe("some-proxy");
});
});
describe("given there are only destroyed Lens windows, when called with URL, throws", () => {
let actualPromise: Promise<string>;
beforeEach(() => {
const di = getDiForUnitTesting();
di.override(
electronInjectable,
() =>
({
webContents: {
getAllWebContents: () => [
{
isDestroyed: () => true,
session: {
resolveProxy: () => {
throw new Error("should never come here");
},
},
},
],
},
} as unknown as typeof electron),
);
resolveProxyMock = asyncFn();
const resolveProxyFromElectron = di.inject(
resolveProxyFromElectronInjectable,
);
actualPromise = resolveProxyFromElectron("some-url");
});
it("rejects", () => {
return expect(actualPromise).rejects.toThrow(
'Tried to resolve proxy for "some-url", but no browser window was available',
);
});
});
});