mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
test(electron): add unit tests for updater (#5439)
This commit is contained in:
26
packages/frontend/electron/test/main/mocks/http-executor.ts
Normal file
26
packages/frontend/electron/test/main/mocks/http-executor.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import http from 'node:https';
|
||||
|
||||
import { HttpExecutor } from 'builder-util-runtime';
|
||||
import type { ClientRequest } from 'electron';
|
||||
|
||||
/**
|
||||
* For testing and same as:
|
||||
* https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/electronHttpExecutor.ts
|
||||
*/
|
||||
export class MockedHttpExecutor extends HttpExecutor<ClientRequest> {
|
||||
createRequest(
|
||||
options: any,
|
||||
callback: (response: any) => void
|
||||
): ClientRequest {
|
||||
if (options.headers && options.headers.Host) {
|
||||
// set host value from headers.Host
|
||||
options.host = options.headers.Host;
|
||||
// remove header property 'Host', if not removed causes net::ERR_INVALID_ARGUMENT exception
|
||||
delete options.headers.Host;
|
||||
}
|
||||
|
||||
const request = http.request(options);
|
||||
request.on('response', callback);
|
||||
return request as unknown as ClientRequest;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user