mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 04:04:27 +08:00
fix(electron): make sure updater receive correct installer files (#8798)
fix AF-1680
This commit is contained in:
@@ -2,6 +2,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import type { UpdateCheckResult } from 'electron-updater';
|
||||
import { parseUpdateInfo } from 'electron-updater/out/providers/Provider';
|
||||
import fs from 'fs-extra';
|
||||
import { flatten } from 'lodash-es';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
@@ -16,7 +17,10 @@ import {
|
||||
vi,
|
||||
} from 'vitest';
|
||||
|
||||
import { AFFiNEUpdateProvider } from '../../src/main/updater/affine-update-provider';
|
||||
import {
|
||||
AFFiNEUpdateProvider,
|
||||
availableForMyPlatformAndInstaller,
|
||||
} from '../../src/main/updater/affine-update-provider';
|
||||
import { MockedAppAdapter, MockedUpdater } from './mocks';
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
@@ -27,23 +31,11 @@ vi.mock('electron', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const platformTail = (() => {
|
||||
// https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/providers/Provider.ts#L30
|
||||
const platform = process.platform;
|
||||
if (platform === 'linux') {
|
||||
const arch = process.env['TEST_UPDATER_ARCH'] || process.arch;
|
||||
const archSuffix = arch === 'x64' ? '' : `-${arch}`;
|
||||
return '-linux' + archSuffix;
|
||||
} else {
|
||||
return platform === 'darwin' ? '-mac' : '';
|
||||
}
|
||||
})();
|
||||
|
||||
describe('testing for client update', () => {
|
||||
const expectReleaseList = [
|
||||
{ buildType: 'stable', version: '0.16.3' },
|
||||
{ buildType: 'beta', version: '0.16.3-beta.2' },
|
||||
{ buildType: 'canary', version: '0.17.0-canary.7' },
|
||||
{ buildType: 'stable', version: '0.18.0' },
|
||||
];
|
||||
|
||||
const basicRequestHandlers = [
|
||||
@@ -64,7 +56,7 @@ describe('testing for client update', () => {
|
||||
expectReleaseList.map(({ version }) => {
|
||||
return [
|
||||
http.get(
|
||||
`https://github.com/toeverything/AFFiNE/releases/download/v${version}/latest${platformTail}.yml`,
|
||||
`https://github.com/toeverything/AFFiNE/releases/download/v${version}/latest.yml`,
|
||||
async req => {
|
||||
const buffer = await fs.readFile(
|
||||
path.join(
|
||||
@@ -83,6 +75,7 @@ describe('testing for client update', () => {
|
||||
})
|
||||
),
|
||||
];
|
||||
|
||||
describe('release api request successfully', () => {
|
||||
const server = setupServer(...basicRequestHandlers);
|
||||
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
|
||||
@@ -108,4 +101,46 @@ describe('testing for client update', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('filter valid installer files', async () => {
|
||||
const platforms: NodeJS.Platform[] = ['darwin', 'win32', 'linux'];
|
||||
const arches: NodeJS.Architecture[] = ['x64', 'arm64'];
|
||||
|
||||
for (const platform of platforms) {
|
||||
for (const arch of arches) {
|
||||
if (platform === 'linux' && arch === 'arm64') {
|
||||
// not support arm64 on linux yet
|
||||
continue;
|
||||
}
|
||||
const data = await fs.readFile(
|
||||
path.join(__dirname, 'fixtures', 'releases', '0.18.0', `latest.yml`),
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
const files = parseUpdateInfo(
|
||||
data,
|
||||
'',
|
||||
new URL('https://affine.pro')
|
||||
).files.map(file => file.url);
|
||||
|
||||
it(`filter for platform [${platform}] arch [${arch}]`, () => {
|
||||
expect(
|
||||
files.filter(file =>
|
||||
availableForMyPlatformAndInstaller(file, platform, arch, false)
|
||||
)
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
if (platform === 'win32') {
|
||||
it(`filter for platform [${platform}] arch [${arch}] and is squirrel installer`, () => {
|
||||
expect(
|
||||
files.filter(file =>
|
||||
availableForMyPlatformAndInstaller(file, platform, arch, true)
|
||||
)
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user