refactor: new project struct (#8199)

packages/frontend/web -> packages/frontend/apps/web
packages/frontend/mobile -> packages/frontend/apps/mobile
packages/frontend/electron -> packages/frontend/apps/electron
This commit is contained in:
EYHN
2024-09-12 07:42:57 +00:00
parent 7c4eab6cd3
commit cc5a6e6d40
291 changed files with 139 additions and 134 deletions
@@ -0,0 +1,101 @@
import path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import { removeWithRetry } from '@affine-test/kit/utils/utils';
import { v4 } from 'uuid';
import { afterAll, afterEach, beforeEach, expect, test, vi } from 'vitest';
const tmpDir = path.join(__dirname, 'tmp');
const appDataPath = path.join(tmpDir, 'app-data');
vi.doMock('@affine/electron/helper/main-rpc', () => ({
mainRPC: {
getPath: async () => appDataPath,
},
}));
const constructorStub = vi.fn();
const destroyStub = vi.fn();
destroyStub.mockReturnValue(Promise.resolve());
function existProcess() {
process.emit('beforeExit', 0);
}
vi.doMock('@affine/electron/helper/db/secondary-db', () => {
return {
SecondaryWorkspaceSQLiteDB: class {
constructor(...args: any[]) {
constructorStub(...args);
}
connectIfNeeded = () => Promise.resolve();
pull = () => Promise.resolve();
destroy = destroyStub;
},
};
});
beforeEach(() => {
vi.useFakeTimers({ shouldAdvanceTime: true });
});
afterEach(async () => {
existProcess();
await removeWithRetry(tmpDir);
vi.useRealTimers();
});
afterAll(() => {
vi.doUnmock('@affine/electron/helper/main-rpc');
});
test('can get a valid WorkspaceSQLiteDB', async () => {
const { ensureSQLiteDB } = await import(
'@affine/electron/helper/db/ensure-db'
);
const workspaceId = v4();
const db0 = await ensureSQLiteDB('workspace', workspaceId);
expect(db0).toBeDefined();
expect(db0.workspaceId).toBe(workspaceId);
const db1 = await ensureSQLiteDB('workspace', v4());
expect(db1).not.toBe(db0);
expect(db1.workspaceId).not.toBe(db0.workspaceId);
// ensure that the db is cached
expect(await ensureSQLiteDB('workspace', workspaceId)).toBe(db0);
});
test('db should be destroyed when app quits', async () => {
const { ensureSQLiteDB } = await import(
'@affine/electron/helper/db/ensure-db'
);
const workspaceId = v4();
const db0 = await ensureSQLiteDB('workspace', workspaceId);
const db1 = await ensureSQLiteDB('workspace', v4());
expect(db0.adapter).not.toBeNull();
expect(db1.adapter).not.toBeNull();
existProcess();
// wait the async `db.destroy()` to be called
await setTimeout(100);
expect(db0.adapter.db).toBeNull();
expect(db1.adapter.db).toBeNull();
});
test('db should be removed in db$Map after destroyed', async () => {
const { ensureSQLiteDB, db$Map } = await import(
'@affine/electron/helper/db/ensure-db'
);
const workspaceId = v4();
const db = await ensureSQLiteDB('workspace', workspaceId);
await db.destroy();
await setTimeout(100);
expect(db$Map.has(`workspace:${workspaceId}`)).toBe(false);
});
@@ -0,0 +1,56 @@
import path from 'node:path';
import { removeWithRetry } from '@affine-test/kit/utils/utils';
import fs from 'fs-extra';
import { v4 } from 'uuid';
import { afterAll, afterEach, beforeAll, expect, test, vi } from 'vitest';
const tmpDir = path.join(__dirname, 'tmp');
const appDataPath = path.join(tmpDir, 'app-data');
beforeAll(() => {
vi.doMock('@affine/electron/helper/main-rpc', () => ({
mainRPC: {
getPath: async () => appDataPath,
},
}));
});
afterEach(async () => {
await removeWithRetry(tmpDir);
});
afterAll(() => {
vi.doUnmock('@affine/electron/helper/main-rpc');
});
test('can create new db file if not exists', async () => {
const { openWorkspaceDatabase } = await import(
'@affine/electron/helper/db/workspace-db-adapter'
);
const workspaceId = v4();
const db = await openWorkspaceDatabase('workspace', workspaceId);
const dbPath = path.join(
appDataPath,
`workspaces/${workspaceId}`,
`storage.db`
);
expect(await fs.exists(dbPath)).toBe(true);
await db.destroy();
});
test('on destroy, check if resources have been released', async () => {
const { openWorkspaceDatabase } = await import(
'@affine/electron/helper/db/workspace-db-adapter'
);
const workspaceId = v4();
const db = await openWorkspaceDatabase('workspace', workspaceId);
const updateSub = {
complete: vi.fn(),
next: vi.fn(),
};
db.update$ = updateSub as any;
await db.destroy();
expect(db.adapter.db).toBe(null);
expect(updateSub.complete).toHaveBeenCalled();
});
@@ -0,0 +1,75 @@
[
{
"url": "https://github.com/toeverything/AFFiNE/releases/tag/v0.16.3-beta.2",
"name": "0.16.3-beta.2",
"tag_name": "v0.16.3-beta.2",
"published_at": "2024-08-14T06:56:25Z",
"assets": [
{
"name": "affine-0.16.3-beta.2-beta-linux-x64.appimage",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-linux-x64.appimage",
"size": 178308288
},
{
"name": "affine-0.16.3-beta.2-beta-linux-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-linux-x64.zip",
"size": 176402697
},
{
"name": "affine-0.16.3-beta.2-beta-macos-arm64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-macos-arm64.dmg",
"size": 168063426
},
{
"name": "affine-0.16.3-beta.2-beta-macos-arm64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-macos-arm64.zip",
"size": 167528680
},
{
"name": "affine-0.16.3-beta.2-beta-macos-x64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-macos-x64.dmg",
"size": 175049454
},
{
"name": "affine-0.16.3-beta.2-beta-macos-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-macos-x64.zip",
"size": 174740492
},
{
"name": "affine-0.16.3-beta.2-beta-windows-x64.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-windows-x64.exe",
"size": 177771240
},
{
"name": "affine-0.16.3-beta.2-beta-windows-x64.nsis.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/affine-0.16.3-beta.2-beta-windows-x64.nsis.exe",
"size": 130309240
},
{
"name": "codecov.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/codecov.yml",
"size": 91
},
{
"name": "latest-linux.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/latest-linux.yml",
"size": 561
},
{
"name": "latest-mac.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/latest-mac.yml",
"size": 897
},
{
"name": "latest.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/latest.yml",
"size": 562
},
{
"name": "web-static.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3-beta.2/web-static.zip",
"size": 61990155
}
]
}
]
@@ -0,0 +1,75 @@
[
{
"url": "https://github.com/toeverything/AFFiNE/releases/tag/v0.17.0-canary.7",
"name": "0.17.0-canary.7",
"tag_name": "v0.17.0-canary.7",
"published_at": "2024-08-29T08:20:54Z",
"assets": [
{
"name": "affine-0.17.0-canary.7-canary-linux-x64.appimage",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-linux-x64.appimage",
"size": 181990592
},
{
"name": "affine-0.17.0-canary.7-canary-linux-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-linux-x64.zip",
"size": 180105256
},
{
"name": "affine-0.17.0-canary.7-canary-macos-arm64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-macos-arm64.dmg",
"size": 170556866
},
{
"name": "affine-0.17.0-canary.7-canary-macos-arm64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-macos-arm64.zip",
"size": 170382513
},
{
"name": "affine-0.17.0-canary.7-canary-macos-x64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-macos-x64.dmg",
"size": 176815834
},
{
"name": "affine-0.17.0-canary.7-canary-macos-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-macos-x64.zip",
"size": 176948223
},
{
"name": "affine-0.17.0-canary.7-canary-windows-x64.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-windows-x64.exe",
"size": 182557416
},
{
"name": "affine-0.17.0-canary.7-canary-windows-x64.nsis.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-windows-x64.nsis.exe",
"size": 133493672
},
{
"name": "codecov.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/codecov.yml",
"size": 91
},
{
"name": "latest-linux.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/latest-linux.yml",
"size": 575
},
{
"name": "latest-mac.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/latest-mac.yml",
"size": 919
},
{
"name": "latest.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/latest.yml",
"size": 576
},
{
"name": "web-static.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/web-static.zip",
"size": 61555023
}
]
}
]
@@ -0,0 +1,75 @@
[
{
"url": "https://github.com/toeverything/AFFiNE/releases/tag/v0.16.3",
"name": "0.16.3",
"tag_name": "v0.16.3",
"published_at": "2024-08-14T07:43:22Z",
"assets": [
{
"name": "affine-0.16.3-stable-linux-x64.appimage",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-linux-x64.appimage",
"size": 178308288
},
{
"name": "affine-0.16.3-stable-linux-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-linux-x64.zip",
"size": 176405078
},
{
"name": "affine-0.16.3-stable-macos-arm64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-arm64.dmg",
"size": 168093091
},
{
"name": "affine-0.16.3-stable-macos-arm64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-arm64.zip",
"size": 167540517
},
{
"name": "affine-0.16.3-stable-macos-x64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-x64.dmg",
"size": 175029125
},
{
"name": "affine-0.16.3-stable-macos-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-x64.zip",
"size": 174752343
},
{
"name": "affine-0.16.3-stable-windows-x64.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-windows-x64.exe",
"size": 177757416
},
{
"name": "affine-0.16.3-stable-windows-x64.nsis.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-windows-x64.nsis.exe",
"size": 130302976
},
{
"name": "codecov.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/codecov.yml",
"size": 91
},
{
"name": "latest-linux.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/latest-linux.yml",
"size": 539
},
{
"name": "latest-mac.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/latest-mac.yml",
"size": 865
},
{
"name": "latest.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/latest.yml",
"size": 540
},
{
"name": "web-static.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/web-static.zip",
"size": 61989498
}
]
}
]
@@ -0,0 +1,11 @@
version: 0.16.3-beta.2
files:
- url: affine-0.16.3-beta.2-beta-linux-x64.appimage
sha512: munCzfD0tOky2MRZVVu+/JCCMrQ4C/EcOSxkNXrEVwK0aoeYo3Q0H1Cm/KJ+7mZ2yMfxctdPH0KGfHRL0tNENg==
size: 178308288
- url: affine-0.16.3-beta.2-beta-linux-x64.zip
sha512: 6emy8f8QrhrAdNxOfHj9PSbWtRXI/LocvpsckrbqrYIi7sU12GmmS0dI2SCxvDBwYTDSoC4mh0erfzUeDSLAEg==
size: 176402697
path: affine-0.16.3-beta.2-beta-linux-x64.appimage
sha512: munCzfD0tOky2MRZVVu+/JCCMrQ4C/EcOSxkNXrEVwK0aoeYo3Q0H1Cm/KJ+7mZ2yMfxctdPH0KGfHRL0tNENg==
releaseDate: 2024-08-14T06:56:24.609Z
@@ -0,0 +1,17 @@
version: 0.16.3-beta.2
files:
- url: affine-0.16.3-beta.2-beta-macos-arm64.dmg
sha512: 5sR2TXAV+hgMOvplG2CobW5VSsrGXsAoZmgWqs7uEpf491XoYkUFl5iXQZaL23xi0HpuGkSS33jSZ/b7pwy0Hg==
size: 168063426
- url: affine-0.16.3-beta.2-beta-macos-arm64.zip
sha512: aI/q3DgyORjCNLxrtsT7W1KoAcuaxUT0AY0QtwnRjtMYiJYV/s4aTQtGFISDEdHcU9Vy+mS8ZcZ6yRVCksdKAg==
size: 167528680
- url: affine-0.16.3-beta.2-beta-macos-x64.dmg
sha512: P8JoSRP5tu2fpQb/EwdV6OSPNx9lEj1NT8iAZhawgeCVLaWokMMVkcsqyRYi7vX25Hf7eegvxF5LNpYzUsfKQQ==
size: 175049454
- url: affine-0.16.3-beta.2-beta-macos-x64.zip
sha512: gpzlGq0ucZUeJOZi6h/cIFRpvIhGJ5qYmWkrD6ncMgSJQOVWQapfFOrQrmU7SCwtE92pfRUcrZeH3g9cNrJDSQ==
size: 174740492
path: affine-0.16.3-beta.2-beta-macos-arm64.dmg
sha512: 5sR2TXAV+hgMOvplG2CobW5VSsrGXsAoZmgWqs7uEpf491XoYkUFl5iXQZaL23xi0HpuGkSS33jSZ/b7pwy0Hg==
releaseDate: 2024-08-14T06:56:23.981Z
@@ -0,0 +1,11 @@
version: 0.16.3-beta.2
files:
- url: affine-0.16.3-beta.2-beta-windows-x64.exe
sha512: iHiIF5Swrgz6RfL/Xf9KFZsmFggGFWtSrkj7IUJUt69Z+gxQQp2dO4wrQ4uaZmiqMVr+8Op++oeczMhcjXGPHw==
size: 177771240
- url: affine-0.16.3-beta.2-beta-windows-x64.nsis.exe
sha512: 5437aZddjbgzwGWsj/nxgepS2jBM/WB561DNz3XXA5sTtqPVafMvEmcbE1KE86JZTpAAJHcJheSwjxdYOL/Lgw==
size: 130309240
path: affine-0.16.3-beta.2-beta-windows-x64.exe
sha512: iHiIF5Swrgz6RfL/Xf9KFZsmFggGFWtSrkj7IUJUt69Z+gxQQp2dO4wrQ4uaZmiqMVr+8Op++oeczMhcjXGPHw==
releaseDate: 2024-08-14T06:56:22.750Z
@@ -0,0 +1,11 @@
version: 0.16.3
files:
- url: affine-0.16.3-stable-linux-x64.appimage
sha512: nmID71T7jq9yKCdujVUeL71TLXmwIdaaWZB0ouDX13Np1vahS1+1A5uJbHUzTH0N/sN0W+LKUg9L29wNgi42gw==
size: 178308288
- url: affine-0.16.3-stable-linux-x64.zip
sha512: fsHTT0fUeU/uLGdlRiuddzSuJWIOcaUTgUj7DB5XSQJ4qA5blAcpij8zOil0ww3Ea7Kwe7qcIe4SSCtNFu31sQ==
size: 176405078
path: affine-0.16.3-stable-linux-x64.appimage
sha512: nmID71T7jq9yKCdujVUeL71TLXmwIdaaWZB0ouDX13Np1vahS1+1A5uJbHUzTH0N/sN0W+LKUg9L29wNgi42gw==
releaseDate: 2024-08-14T07:11:42.171Z
@@ -0,0 +1,17 @@
version: 0.16.3
files:
- url: affine-0.16.3-stable-macos-arm64.dmg
sha512: fmJWpi45gVYYUavb0Cd6Y9DR2nxBc3wMagHOiMF1PPg+4tEyHGmVIhRIwY/QaJ5TAR+3tRAENZwen2gvja0UtQ==
size: 168093091
- url: affine-0.16.3-stable-macos-arm64.zip
sha512: u1ud8pJ613A5Oqh3fbcnUUOA4hNoURWBdtAMJoeZ6EIAUvZzV0tsDcAqLiEP89LKbitaH0IdrW3D8EFSsZ9kRw==
size: 167540517
- url: affine-0.16.3-stable-macos-x64.dmg
sha512: Ou1W6/xHyM+ZN9BLYvc+8qCB8wR9F3jLQP5m3oG0uIDDw7wwoR+ny3gcWbDzalfxoOR84CvM74LIfc7BQf69Uw==
size: 175029125
- url: affine-0.16.3-stable-macos-x64.zip
sha512: oot098M9qqdRbw+znnuLjVedZ1U59p4m+gzSxRtpCuYdfvumvu5/RN1jvY2cHssqstJj/Ybh4eBTlREZMgKyyg==
size: 174752343
path: affine-0.16.3-stable-macos-arm64.dmg
sha512: fmJWpi45gVYYUavb0Cd6Y9DR2nxBc3wMagHOiMF1PPg+4tEyHGmVIhRIwY/QaJ5TAR+3tRAENZwen2gvja0UtQ==
releaseDate: 2024-08-14T07:11:41.503Z
@@ -0,0 +1,11 @@
version: 0.16.3
files:
- url: affine-0.16.3-stable-windows-x64.exe
sha512: 47zaLkAhSxPuWsKq01dSEt8GusXqK1rmSaiOTBLe32lmUiXPhUqYO5JhzbrjJKx7/TFcic4UDJ/Zir3wf9fKRA==
size: 177757416
- url: affine-0.16.3-stable-windows-x64.nsis.exe
sha512: G3Rxa3onqlJTGQIcz7Rz6ZQ/6rAwjzjYnW/HB5yzXkjN6e5yfW2JBk765+AyiPFV5Mn4Rloj7V6GM6m4q7WfWg==
size: 130302976
path: affine-0.16.3-stable-windows-x64.exe
sha512: 47zaLkAhSxPuWsKq01dSEt8GusXqK1rmSaiOTBLe32lmUiXPhUqYO5JhzbrjJKx7/TFcic4UDJ/Zir3wf9fKRA==
releaseDate: 2024-08-14T07:11:40.285Z
@@ -0,0 +1,11 @@
version: 0.17.0-canary.7
files:
- url: affine-0.17.0-canary.7-canary-linux-x64.appimage
sha512: qspZkDlItrHu02vSItbjc3I+t4FcOiHOzGt0Ap6IeZEFKal+hoOh4WIcUN16dlS/OoFm+is8yPBHqN/70xhWKA==
size: 181990592
- url: affine-0.17.0-canary.7-canary-linux-x64.zip
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
path: affine-0.17.0-canary.7-canary-linux-x64.appimage
sha512: qspZkDlItrHu02vSItbjc3I+t4FcOiHOzGt0Ap6IeZEFKal+hoOh4WIcUN16dlS/OoFm+is8yPBHqN/70xhWKA==
releaseDate: 2024-08-29T08:20:53.453Z
@@ -0,0 +1,17 @@
version: 0.17.0-canary.7
files:
- url: affine-0.17.0-canary.7-canary-macos-arm64.dmg
sha512: Tdy7dgrCHP95PjsZBt1evxUk7DUkn+JpseBQj1Gz60MmcsFx+0NtJvofZbUcsLFiS0IC32JM/szHlHiNGEznrQ==
size: 170556866
- url: affine-0.17.0-canary.7-canary-macos-arm64.zip
sha512: pmYD0B5Z9hrzgjcHmRCKnNawoPJiO5r1RjBBZi+THVL3TyKXzpJBr9HTNQkjYnQYgqHX4q2eoONsDNCIoqTeBA==
size: 170382513
- url: affine-0.17.0-canary.7-canary-macos-x64.dmg
sha512: k4a4GUmy/6MmSc1xVGJNeNCCtYylWWSRcfDoZA+syUhZFY6x3xrOft972ONsiRrJukXWlKrFmVTwoW68Ywe49A==
size: 176815834
- url: affine-0.17.0-canary.7-canary-macos-x64.zip
sha512: PL24krtjeiQY53F7OuS+hh8EZP3YpbLle0JboXiddSrulypxzBRquOCCinNW88Kg8ZJbOrfTkxaNOHpOAVfeaQ==
size: 176948223
path: affine-0.17.0-canary.7-canary-macos-arm64.dmg
sha512: Tdy7dgrCHP95PjsZBt1evxUk7DUkn+JpseBQj1Gz60MmcsFx+0NtJvofZbUcsLFiS0IC32JM/szHlHiNGEznrQ==
releaseDate: 2024-08-29T08:20:52.810Z
@@ -0,0 +1,11 @@
version: 0.17.0-canary.7
files:
- url: affine-0.17.0-canary.7-canary-windows-x64.exe
sha512: cF47Wcu69PXyMVswSzrdNktNO2lqkjsyJ/HQr2qWjFPuIJfcad9QDTfOyCVsMCV6KGUSSeFiTHyObWgKd6z2DQ==
size: 182557416
- url: affine-0.17.0-canary.7-canary-windows-x64.nsis.exe
sha512: ztugqKwPpxDDSK1OpzUPkGvL8wLXwg9rh985bs9ZvxydY037yKBAZOk96PPtow2qqRb5/9Xn8MuGrWgchqXkVg==
size: 133493672
path: affine-0.17.0-canary.7-canary-windows-x64.exe
sha512: cF47Wcu69PXyMVswSzrdNktNO2lqkjsyJ/HQr2qWjFPuIJfcad9QDTfOyCVsMCV6KGUSSeFiTHyObWgKd6z2DQ==
releaseDate: 2024-08-29T08:20:51.573Z
@@ -0,0 +1,34 @@
import type { AppAdapter } from 'electron-updater/out/AppAdapter';
/**
* For testing and same as:
* https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/ElectronAppAdapter.ts
*/
export class MockedAppAdapter implements AppAdapter {
version: string;
name = 'AFFiNE-testing';
isPackaged = true;
appUpdateConfigPath = '';
userDataPath = '';
baseCachePath = '';
constructor(version: string) {
this.version = version;
}
whenReady() {
return Promise.resolve();
}
relaunch() {
return;
}
quit() {
return;
}
onQuit(_handler: (exitCode: number) => void) {
return;
}
}
@@ -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;
}
}
@@ -0,0 +1,3 @@
export * from './app-adapter';
export * from './http-executor';
export * from './updater';
@@ -0,0 +1,39 @@
import 'electron-updater'; // Prevent BaseUpdater is undefined.
import { randomBytes } from 'node:crypto';
import type { AllPublishOptions } from 'builder-util-runtime';
import { UUID } from 'builder-util-runtime';
import type { AppAdapter } from 'electron-updater/out/AppAdapter';
import type { DownloadUpdateOptions } from 'electron-updater/out/AppUpdater';
import type { InstallOptions } from 'electron-updater/out/BaseUpdater';
import { BaseUpdater } from 'electron-updater/out/BaseUpdater';
import { MockedHttpExecutor } from './http-executor';
/**
* For testing, like:
* https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/MacUpdater.ts
*/
export class MockedUpdater extends BaseUpdater {
httpExecutor: MockedHttpExecutor;
constructor(options?: AllPublishOptions | null, app?: AppAdapter) {
super(options, app);
this.httpExecutor = new MockedHttpExecutor();
Object.assign(this, {
getOrCreateStagingUserId: () => {
const id = UUID.v5(randomBytes(4096), UUID.OID);
return id;
},
});
}
doInstall(_options: InstallOptions) {
return true;
}
doDownloadUpdate(_options: DownloadUpdateOptions): Promise<string[]> {
return Promise.resolve([]);
}
}
@@ -0,0 +1,111 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { UpdateCheckResult } from 'electron-updater';
import fs from 'fs-extra';
import { flatten } from 'lodash-es';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import {
afterAll,
afterEach,
beforeAll,
describe,
expect,
it,
vi,
} from 'vitest';
import { AFFiNEUpdateProvider } from '../../src/main/updater/affine-update-provider';
import { MockedAppAdapter, MockedUpdater } from './mocks';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
vi.mock('electron', () => ({
app: {
getPath: () => __dirname,
},
}));
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' },
];
const basicRequestHandlers = [
http.get('https://affine.pro/api/worker/releases', async ({ request }) => {
const url = new URL(request.url);
const buffer = await fs.readFile(
path.join(
__dirname,
'fixtures',
'candidates',
`${url.searchParams.get('channel')}.json`
)
);
const content = buffer.toString();
return HttpResponse.text(content);
}),
...flatten(
expectReleaseList.map(({ version }) => {
return [
http.get(
`https://github.com/toeverything/AFFiNE/releases/download/v${version}/latest${platformTail}.yml`,
async req => {
const buffer = await fs.readFile(
path.join(
__dirname,
'fixtures',
'releases',
version,
path.parse(req.request.url).base
)
);
const content = buffer.toString();
return HttpResponse.text(content);
}
),
];
})
),
];
describe('release api request successfully', () => {
const server = setupServer(...basicRequestHandlers);
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
afterAll(() => server.close());
afterEach(() => server.resetHandlers());
for (const { buildType, version } of expectReleaseList) {
it(`check update for ${buildType} channel successfully`, async () => {
const app = new MockedAppAdapter('0.10.0');
const updater = new MockedUpdater(null, app);
updater.setFeedURL(
AFFiNEUpdateProvider.configFeed({
channel: buildType as any,
})
);
const info = (await updater.checkForUpdates()) as UpdateCheckResult;
expect(info).not.toBe(null);
expect(info.updateInfo.releaseName).toBe(version);
expect(info.updateInfo.version).toBe(version);
// expect(info.updateInfo.releaseNotes?.length).toBeGreaterThan(0);
});
}
});
});
@@ -0,0 +1,122 @@
import path from 'node:path';
import { removeWithRetry } from '@affine-test/kit/utils/utils';
import fs from 'fs-extra';
import { v4 } from 'uuid';
import { afterAll, afterEach, describe, expect, test, vi } from 'vitest';
const tmpDir = path.join(__dirname, 'tmp');
const appDataPath = path.join(tmpDir, 'app-data');
vi.doMock('@affine/electron/helper/db/ensure-db', () => ({
ensureSQLiteDB: async () => ({
destroy: () => {},
}),
}));
vi.doMock('@affine/electron/helper/main-rpc', () => ({
mainRPC: {
getPath: async () => appDataPath,
},
}));
afterEach(async () => {
await removeWithRetry(tmpDir);
});
afterAll(() => {
vi.doUnmock('@affine/electron/helper/main-rpc');
});
describe('delete workspace', () => {
test('deleteWorkspace', async () => {
const { deleteWorkspace } = await import(
'@affine/electron/helper/workspace/handlers'
);
const workspaceId = v4();
const workspacePath = path.join(appDataPath, 'workspaces', workspaceId);
await fs.ensureDir(workspacePath);
await deleteWorkspace(workspaceId);
expect(await fs.pathExists(workspacePath)).toBe(false);
// removed workspace will be moved to deleted-workspaces
expect(
await fs.pathExists(
path.join(appDataPath, 'deleted-workspaces', workspaceId)
)
).toBe(true);
});
});
describe('getWorkspaceMeta', () => {
test('can get meta', async () => {
const { getWorkspaceMeta } = await import(
'@affine/electron/helper/workspace/meta'
);
const workspaceId = v4();
const workspacePath = path.join(appDataPath, 'workspaces', workspaceId);
const meta = {
id: workspaceId,
};
await fs.ensureDir(workspacePath);
await fs.writeJSON(path.join(workspacePath, 'meta.json'), meta);
expect(await getWorkspaceMeta('workspace', workspaceId)).toEqual(meta);
});
test('can create meta if not exists', async () => {
const { getWorkspaceMeta } = await import(
'@affine/electron/helper/workspace/meta'
);
const workspaceId = v4();
const workspacePath = path.join(appDataPath, 'workspaces', workspaceId);
await fs.ensureDir(workspacePath);
expect(await getWorkspaceMeta('workspace', workspaceId)).toEqual({
id: workspaceId,
mainDBPath: path.join(workspacePath, 'storage.db'),
type: 'workspace',
});
expect(
await fs.pathExists(path.join(workspacePath, 'meta.json'))
).toBeTruthy();
});
test('can migrate meta if db file is a link', async () => {
const { getWorkspaceMeta } = await import(
'@affine/electron/helper/workspace/meta'
);
const workspaceId = v4();
const workspacePath = path.join(appDataPath, 'workspaces', workspaceId);
await fs.ensureDir(workspacePath);
const sourcePath = path.join(tmpDir, 'source.db');
await fs.writeFile(sourcePath, 'test');
await fs.ensureSymlink(sourcePath, path.join(workspacePath, 'storage.db'));
expect(await getWorkspaceMeta('workspace', workspaceId)).toEqual({
id: workspaceId,
mainDBPath: path.join(workspacePath, 'storage.db'),
type: 'workspace',
});
expect(
await fs.pathExists(path.join(workspacePath, 'meta.json'))
).toBeTruthy();
});
});
test('storeWorkspaceMeta', async () => {
const { storeWorkspaceMeta } = await import(
'@affine/electron/helper/workspace/handlers'
);
const workspaceId = v4();
const workspacePath = path.join(appDataPath, 'workspaces', workspaceId);
await fs.ensureDir(workspacePath);
const meta = {
id: workspaceId,
mainDBPath: path.join(workspacePath, 'storage.db'),
type: 'workspace',
};
await storeWorkspaceMeta(workspaceId, meta);
expect(await fs.readJSON(path.join(workspacePath, 'meta.json'))).toEqual(
meta
);
});