mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add error logging to resolving of proxy
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
fc0eb2c381
commit
7f6710d2f7
@ -4,14 +4,18 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import electronInjectable from "./electron.injectable";
|
||||
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||
|
||||
const resolveProxyFromElectronInjectable = getInjectable({
|
||||
id: "resolve-proxy-from-electron",
|
||||
|
||||
instantiate: (di) => {
|
||||
const electron = di.inject(electronInjectable);
|
||||
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||
|
||||
return async (url: string) => {
|
||||
const withErrorLogging = withErrorLoggingFor(() => "Error resolving proxy");
|
||||
|
||||
return withErrorLogging(async (url: string) => {
|
||||
const webContent = electron.webContents
|
||||
.getAllWebContents()
|
||||
.find((x) => !x.isDestroyed());
|
||||
@ -21,7 +25,7 @@ const resolveProxyFromElectronInjectable = getInjectable({
|
||||
}
|
||||
|
||||
return await webContent.session.resolveProxy(url);
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -10,16 +10,24 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type electron from "electron";
|
||||
import { getPromiseStatus } from "../../../../common/test-utils/get-promise-status";
|
||||
import logErrorInjectable from "../../../../common/log-error.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
|
||||
describe("technical: resolve-proxy-from-electron", () => {
|
||||
let resolveProxyMock: AsyncFnMock<(url: string) => Promise<string>>;
|
||||
let logErrorMock: jest.Mock;
|
||||
let di: DiContainer;
|
||||
let actualPromise: Promise<string>;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
logErrorMock = jest.fn();
|
||||
di.override(logErrorInjectable, () => logErrorMock);
|
||||
});
|
||||
|
||||
describe("given there are non-destroyed Lens windows, when called with URL", () => {
|
||||
let actualPromise: Promise<string>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
resolveProxyMock = asyncFn();
|
||||
|
||||
di.override(
|
||||
@ -82,12 +90,10 @@ describe("technical: resolve-proxy-from-electron", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("given there are only destroyed Lens windows, when called with URL, throws", () => {
|
||||
let actualPromise: Promise<string>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting();
|
||||
describe("given there are only destroyed Lens windows, when called with URL", () => {
|
||||
let error: unknown;
|
||||
|
||||
beforeEach(async () => {
|
||||
di.override(
|
||||
electronInjectable,
|
||||
() =>
|
||||
@ -114,13 +120,15 @@ describe("technical: resolve-proxy-from-electron", () => {
|
||||
resolveProxyFromElectronInjectable,
|
||||
);
|
||||
|
||||
actualPromise = resolveProxyFromElectron("some-url");
|
||||
try {
|
||||
await resolveProxyFromElectron("some-url");
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects", () => {
|
||||
return expect(actualPromise).rejects.toThrow(
|
||||
'Tried to resolve proxy for "some-url", but no browser window was available',
|
||||
);
|
||||
it("logs error", () => {
|
||||
expect(logErrorMock).toHaveBeenCalledWith("Error resolving proxy", error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user