mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-10 03:13:32 -07:00
feat(config): add configuration window (#70)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createElectronNetFetch, createGlobalFetch } from './fetch-adapter';
|
||||
import { createCurlFetch, createElectronNetFetch, createGlobalFetch } from './fetch-adapter';
|
||||
import type { FetchResponseLike } from './release-assets';
|
||||
|
||||
test('createElectronNetFetch delegates updater requests to Electron net.fetch', async () => {
|
||||
@@ -62,3 +62,53 @@ test('createGlobalFetch delegates updater requests to main-process fetch', async
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('createCurlFetch requests updater metadata without Electron networking', async () => {
|
||||
const calls: Array<{
|
||||
file: string;
|
||||
args: readonly string[];
|
||||
options: { encoding: 'utf8' | 'buffer'; maxBuffer?: number; timeout?: number };
|
||||
}> = [];
|
||||
const payload = Buffer.from(JSON.stringify([{ tag_name: 'v1.2.3', assets: [] }]));
|
||||
|
||||
const fetch = createCurlFetch({
|
||||
curlPath: '/usr/bin/curl',
|
||||
execFile: (file, args, options, callback) => {
|
||||
calls.push({ file, args, options });
|
||||
callback(null, payload, Buffer.alloc(0));
|
||||
return { kill: () => undefined };
|
||||
},
|
||||
});
|
||||
|
||||
const response = await fetch('https://api.github.com/repos/ksyasuda/SubMiner/releases', {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
'User-Agent': 'SubMiner updater',
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(response.ok, true);
|
||||
assert.equal(response.status, 200);
|
||||
assert.deepEqual(await response.json(), [{ tag_name: 'v1.2.3', assets: [] }]);
|
||||
assert.equal(await response.text(), '[{"tag_name":"v1.2.3","assets":[]}]');
|
||||
assert.deepEqual(Buffer.from(await response.arrayBuffer()), payload);
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0]?.file, '/usr/bin/curl');
|
||||
assert.deepEqual(calls[0]?.args, [
|
||||
'--fail',
|
||||
'--location',
|
||||
'--silent',
|
||||
'--show-error',
|
||||
'--connect-timeout',
|
||||
'30',
|
||||
'--max-time',
|
||||
'60',
|
||||
'--header',
|
||||
'Accept: application/vnd.github+json',
|
||||
'--header',
|
||||
'User-Agent: SubMiner updater',
|
||||
'https://api.github.com/repos/ksyasuda/SubMiner/releases',
|
||||
]);
|
||||
assert.equal(calls[0]?.options.encoding, 'buffer');
|
||||
assert.equal(calls[0]?.options.timeout, 65_000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user