feat!: unified migration logic in server electron, and browser (#4079)

Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
Alex Yang
2023-09-06 00:44:53 -07:00
committed by GitHub
parent 925c18300f
commit 1b6a78cd00
61 changed files with 10776 additions and 10267 deletions

View File

@@ -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,
}) => {

File diff suppressed because one or more lines are too long

View File

@@ -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",

View File

@@ -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);

View File

@@ -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
View File

@@ -0,0 +1,3 @@
static
fixtures/*.ydoc
test-results

View 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`

Binary file not shown.

View 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);
});

View 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"
}

View 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;

View File

@@ -0,0 +1,16 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"esModuleInterop": true,
"outDir": "lib"
},
"include": ["e2e"],
"references": [
{
"path": "../../fixtures"
},
{
"path": "../../kit"
}
]
}