mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat!: unified migration logic in server electron, and browser (#4079)
Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { test } from '@affine-test/kit/playwright';
|
||||
import {
|
||||
createRandomUser,
|
||||
deleteUser,
|
||||
enableCloudWorkspace,
|
||||
getLoginCookie,
|
||||
loginUser,
|
||||
runPrisma,
|
||||
} from '@affine-test/kit/utils/cloud';
|
||||
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
|
||||
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
|
||||
import { coreUrl } from '@affine-test/kit/utils/load-page';
|
||||
import {
|
||||
clickNewPageButton,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
|
||||
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
let user: {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
@@ -40,6 +52,63 @@ test.afterEach(async () => {
|
||||
});
|
||||
|
||||
test.describe('basic', () => {
|
||||
test('migration', async ({ page, browser }) => {
|
||||
let workspaceId: string;
|
||||
{
|
||||
// create the old cloud workspace in another browser
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
await loginUser(page, user.email);
|
||||
await page.reload();
|
||||
await createLocalWorkspace(
|
||||
{
|
||||
name: 'test',
|
||||
},
|
||||
page
|
||||
);
|
||||
await enableCloudWorkspace(page);
|
||||
await clickNewPageButton(page);
|
||||
await waitForEditorLoad(page);
|
||||
// http://localhost:8080/workspace/2bc0b6c8-f68d-4dd3-98a8-be746754f9e1/xxx
|
||||
workspaceId = page.url().split('/')[4];
|
||||
await runPrisma(async client => {
|
||||
const sqls = (
|
||||
await readFile(
|
||||
resolve(__dirname, 'fixtures', '0.9.0-canary.9-snapshots.sql'),
|
||||
'utf-8'
|
||||
)
|
||||
)
|
||||
.replaceAll('2bc0b6c8-f68d-4dd3-98a8-be746754f9e1', workspaceId)
|
||||
.split('\n');
|
||||
await client.snapshot.deleteMany({
|
||||
where: {
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
|
||||
for (const sql of sqls) {
|
||||
await client.$executeRawUnsafe(sql);
|
||||
}
|
||||
});
|
||||
await page.close();
|
||||
}
|
||||
await page.reload();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.goto(`${coreUrl}/workspace/${workspaceId}/all`);
|
||||
await page.getByTestId('upgrade-workspace').click();
|
||||
await expect(page.getByText('Done, please refresh the page.')).toBeVisible({
|
||||
timeout: 60000,
|
||||
});
|
||||
await page.goto(
|
||||
`${coreUrl}/workspace/${workspaceId}/gc5FeppNDv-hello-world`
|
||||
);
|
||||
await waitForEditorLoad(page);
|
||||
await clickEdgelessModeButton(page);
|
||||
await expect(page.locator('affine-edgeless-page')).toBeVisible({
|
||||
timeout: 1000,
|
||||
});
|
||||
});
|
||||
|
||||
test('can see and change email and password in setting panel', async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
14
tests/affine-cloud/e2e/fixtures/0.9.0-canary.9-snapshots.sql
Normal file
14
tests/affine-cloud/e2e/fixtures/0.9.0-canary.9-snapshots.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -10,10 +10,10 @@
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@blocksuite/block-std": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/block-std": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@playwright/test": "^1.37.1",
|
||||
"express": "^4.18.2",
|
||||
"http-proxy-middleware": "^3.0.0-beta.1",
|
||||
|
||||
@@ -32,17 +32,17 @@ test('database migration', async ({ page, context }) => {
|
||||
await page.keyboard.press('a', { delay: 50 });
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
|
||||
const url = page.url();
|
||||
|
||||
await switchToNext();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.goto('http://localhost:8081/');
|
||||
await page.click('text=hello');
|
||||
await page.goto(url);
|
||||
await waitForEditorLoad(page);
|
||||
// check page mode is correct
|
||||
expect(await page.locator('v-line').nth(0).textContent()).toBe('hello');
|
||||
expect(await page.locator('affine-database').isVisible()).toBe(true);
|
||||
|
||||
// check edgeless mode is correct
|
||||
await page.getByTestId('switch-edgeless-mode-button').click();
|
||||
await clickEdgelessModeButton(page);
|
||||
await page.waitForTimeout(200);
|
||||
expect(await page.locator('affine-database').isVisible()).toBe(true);
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@blocksuite/block-std": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230829150056-df43987c-nightly",
|
||||
"@blocksuite/block-std": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@playwright/test": "^1.37.1",
|
||||
"express": "^4.18.2",
|
||||
"http-proxy-middleware": "^3.0.0-beta.1",
|
||||
|
||||
3
tests/affine-legacy/0.8.3/.gitignore
vendored
Normal file
3
tests/affine-legacy/0.8.3/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
static
|
||||
fixtures/*.ydoc
|
||||
test-results
|
||||
7
tests/affine-legacy/0.8.3/README.md
Normal file
7
tests/affine-legacy/0.8.3/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# AFFiNE Legacy 0.8.3
|
||||
|
||||
> This package is static output of AFFiNE 0.8.3
|
||||
>
|
||||
> **This package is for debug only**.
|
||||
>
|
||||
> DO NOT MODIFY `affine-core.zip`
|
||||
BIN
tests/affine-legacy/0.8.3/affine-core.zip
Normal file
BIN
tests/affine-legacy/0.8.3/affine-core.zip
Normal file
Binary file not shown.
45
tests/affine-legacy/0.8.3/e2e/basic.spec.ts
Normal file
45
tests/affine-legacy/0.8.3/e2e/basic.spec.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
|
||||
import {
|
||||
getBlockSuiteEditorTitle,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import {
|
||||
check8080Available,
|
||||
setupProxyServer,
|
||||
} from '@affine-test/kit/utils/proxy';
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
const { switchToNext } = setupProxyServer(
|
||||
test,
|
||||
resolve(__dirname, '..', 'static')
|
||||
);
|
||||
|
||||
test('surface migration', async ({ page, context }) => {
|
||||
await check8080Available(context);
|
||||
await page.goto('http://localhost:8081/');
|
||||
await page.waitForSelector('v-line', {
|
||||
timeout: 10000,
|
||||
});
|
||||
await page.getByTestId('new-page-button').click();
|
||||
const title = getBlockSuiteEditorTitle(page);
|
||||
await title.type('hello');
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
await page.keyboard.type('world', {
|
||||
delay: 50,
|
||||
});
|
||||
await page.getByTestId('switch-edgeless-mode-button').click({
|
||||
delay: 50,
|
||||
});
|
||||
const url = page.url();
|
||||
|
||||
await switchToNext();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.goto(url);
|
||||
await waitForEditorLoad(page);
|
||||
|
||||
// check edgeless mode is correct
|
||||
await clickEdgelessModeButton(page);
|
||||
await page.waitForTimeout(200);
|
||||
});
|
||||
22
tests/affine-legacy/0.8.3/package.json
Normal file
22
tests/affine-legacy/0.8.3/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@affine-legacy/0.8.3",
|
||||
"description": "AFFiNE 0.8.3 static output",
|
||||
"scripts": {
|
||||
"unzip": "unzip affine-core -d static",
|
||||
"start": "yarn exec serve -s static -l 8082",
|
||||
"e2e": "yarn playwright test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@blocksuite/block-std": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly",
|
||||
"@playwright/test": "^1.37.1",
|
||||
"express": "^4.18.2",
|
||||
"http-proxy-middleware": "^3.0.0-beta.1",
|
||||
"serve": "^14.2.1"
|
||||
},
|
||||
"version": "0.9.0-canary.7"
|
||||
}
|
||||
45
tests/affine-legacy/0.8.3/playwright.config.ts
Normal file
45
tests/affine-legacy/0.8.3/playwright.config.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type {
|
||||
PlaywrightTestConfig,
|
||||
PlaywrightWorkerOptions,
|
||||
} from '@playwright/test';
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
testDir: './e2e',
|
||||
fullyParallel: true,
|
||||
timeout: process.env.CI ? 50_000 : 30_000,
|
||||
use: {
|
||||
baseURL: 'http://localhost:8081/',
|
||||
browserName:
|
||||
(process.env.BROWSER as PlaywrightWorkerOptions['browserName']) ??
|
||||
'chromium',
|
||||
permissions: ['clipboard-read', 'clipboard-write'],
|
||||
viewport: { width: 1440, height: 800 },
|
||||
actionTimeout: 5 * 1000,
|
||||
locale: 'en-US',
|
||||
trace: 'on-first-retry',
|
||||
video: 'on-first-retry',
|
||||
},
|
||||
forbidOnly: !!process.env.CI,
|
||||
workers: 4,
|
||||
retries: 1,
|
||||
reporter: process.env.CI ? 'github' : 'list',
|
||||
webServer: [
|
||||
// Intentionally not building the web, reminds you to run it by yourself.
|
||||
{
|
||||
command: 'yarn -T run start:web-static',
|
||||
port: 8080,
|
||||
timeout: 120 * 1000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
env: {
|
||||
COVERAGE: process.env.COVERAGE || 'false',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
if (process.env.CI) {
|
||||
config.retries = 3;
|
||||
config.workers = '50%';
|
||||
}
|
||||
|
||||
export default config;
|
||||
16
tests/affine-legacy/0.8.3/tsconfig.json
Normal file
16
tests/affine-legacy/0.8.3/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["e2e"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../fixtures"
|
||||
},
|
||||
{
|
||||
"path": "../../kit"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user