refactor(infra): record legacy data to improve testing stability (#4590)
This commit is contained in:
5
tests/affine-migration/.gitignore
vendored
Normal file
5
tests/affine-migration/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
static
|
||||
fixtures/*.ydoc
|
||||
test-results
|
||||
*.zip
|
||||
web-static
|
||||
9
tests/affine-migration/README.md
Normal file
9
tests/affine-migration/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# AFFiNE Migration Testings
|
||||
|
||||
This package is used to testing migration logic for every breaking version.
|
||||
|
||||
```sh
|
||||
BUILD_TYPE=canary yarn run build
|
||||
cd tests/affine-migration
|
||||
yarn run e2e
|
||||
```
|
||||
122
tests/affine-migration/e2e/basic.spec.ts
Normal file
122
tests/affine-migration/e2e/basic.spec.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import { patchDataEnhancement } from '@affine-test/kit/e2e-enhance/initializer';
|
||||
import { SnapshotStorage } from '@affine-test/kit/e2e-enhance/snapshot';
|
||||
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
|
||||
import { coreUrl } from '@affine-test/kit/utils/load-page';
|
||||
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
|
||||
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
async function open404PageToInitData(page: Page, version: string) {
|
||||
const snapshotStorage = new SnapshotStorage(version);
|
||||
const { binaries, idbData, localStorageData } = await snapshotStorage.read();
|
||||
|
||||
// Open other page to init data
|
||||
await page.goto(`${coreUrl}/404`);
|
||||
await page.evaluate(
|
||||
([v1, v2]) => window.writeAffineDatabase(v1, v2),
|
||||
[idbData, binaries]
|
||||
);
|
||||
await page.evaluate(
|
||||
value => window.writeAffineLocalStorage(value),
|
||||
localStorageData
|
||||
);
|
||||
|
||||
return { localStorageData };
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await patchDataEnhancement(page);
|
||||
});
|
||||
|
||||
test('v1 to v4', async ({ page }) => {
|
||||
await open404PageToInitData(page, '0.7.0-canary.18');
|
||||
|
||||
await page.goto(coreUrl);
|
||||
await clickSideBarAllPageButton(page);
|
||||
await page.getByText('hello').click();
|
||||
|
||||
//#region fixme(himself65): blocksuite issue, data cannot be loaded to store
|
||||
const url = page.url();
|
||||
await page.waitForTimeout(5000);
|
||||
await page.goto(url);
|
||||
//#endregion
|
||||
|
||||
await waitForEditorLoad(page);
|
||||
expect(await page.locator('v-line').nth(0).textContent()).toBe('hello');
|
||||
|
||||
const changedLocalStorageData = await page.evaluate(() =>
|
||||
window.readAffineLocalStorage()
|
||||
);
|
||||
const workspaces = JSON.parse(
|
||||
changedLocalStorageData['jotai-workspaces']
|
||||
) as any[];
|
||||
for (const workspace of workspaces) {
|
||||
expect(workspace.version).toBe(4);
|
||||
}
|
||||
});
|
||||
|
||||
test('v2 to v4, database migration', async ({ page }) => {
|
||||
const { localStorageData } = await open404PageToInitData(
|
||||
page,
|
||||
'0.8.0-canary.7'
|
||||
);
|
||||
|
||||
//#region fixme(himself65): blocksuite issue, data cannot be loaded to store
|
||||
const allPagePath = `${coreUrl}/workspace/${localStorageData.last_workspace_id}/all`;
|
||||
await page.goto(allPagePath);
|
||||
await page.waitForTimeout(5000);
|
||||
//#endregion
|
||||
|
||||
const detailPagePath = `${coreUrl}/workspace/${localStorageData.last_workspace_id}/${localStorageData.last_page_id}`;
|
||||
await page.goto(detailPagePath);
|
||||
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 clickEdgelessModeButton(page);
|
||||
await page.waitForTimeout(200);
|
||||
expect(await page.locator('affine-database').isVisible()).toBe(true);
|
||||
|
||||
const changedLocalStorageData = await page.evaluate(() =>
|
||||
window.readAffineLocalStorage()
|
||||
);
|
||||
const workspaces = JSON.parse(
|
||||
changedLocalStorageData['jotai-workspaces']
|
||||
) as any[];
|
||||
for (const workspace of workspaces) {
|
||||
expect(workspace.version).toBe(4);
|
||||
}
|
||||
});
|
||||
|
||||
test('v3 to v4, surface migration', async ({ page }) => {
|
||||
const { localStorageData } = await open404PageToInitData(page, '0.8.4');
|
||||
|
||||
//#region fixme(himself65): blocksuite issue, data cannot be loaded to store
|
||||
const allPagePath = `${coreUrl}/workspace/${localStorageData.last_workspace_id}/all`;
|
||||
await page.goto(allPagePath);
|
||||
await page.waitForTimeout(5000);
|
||||
//#endregion
|
||||
|
||||
const detailPagePath = `${coreUrl}/workspace/${localStorageData.last_workspace_id}/${localStorageData.last_page_id}`;
|
||||
await page.goto(detailPagePath);
|
||||
await waitForEditorLoad(page);
|
||||
|
||||
// check edgeless mode is correct
|
||||
await clickEdgelessModeButton(page);
|
||||
await expect(page.locator('edgeless-toolbar')).toBeVisible();
|
||||
await expect(page.locator('affine-edgeless-page')).toBeVisible();
|
||||
|
||||
const changedLocalStorageData = await page.evaluate(() =>
|
||||
window.readAffineLocalStorage()
|
||||
);
|
||||
const workspaces = JSON.parse(
|
||||
changedLocalStorageData['jotai-workspaces']
|
||||
) as any[];
|
||||
for (const workspace of workspaces) {
|
||||
expect(workspace.version).toBe(4);
|
||||
}
|
||||
});
|
||||
17
tests/affine-migration/package.json
Normal file
17
tests/affine-migration/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@affine-test/affine-migration",
|
||||
"description": "AFFiNE migration e2e tests",
|
||||
"scripts": {
|
||||
"e2e": "yarn playwright test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@blocksuite/block-std": "0.0.0-20230926212737-6d4b1569-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230926212737-6d4b1569-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230926212737-6d4b1569-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230926212737-6d4b1569-nightly",
|
||||
"@playwright/test": "^1.38.1"
|
||||
},
|
||||
"version": "0.9.0-canary.13"
|
||||
}
|
||||
44
tests/affine-migration/playwright.config.ts
Normal file
44
tests/affine-migration/playwright.config.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type {
|
||||
PlaywrightTestConfig,
|
||||
PlaywrightWorkerOptions,
|
||||
} from '@playwright/test';
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
testDir: './e2e',
|
||||
fullyParallel: !process.env.CI,
|
||||
timeout: process.env.CI ? 50_000 : 30_000,
|
||||
use: {
|
||||
baseURL: 'http://localhost:8080/',
|
||||
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: process.env.CI ? 1 : 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;
|
||||
}
|
||||
|
||||
export default config;
|
||||
17
tests/affine-migration/tsconfig.json
Normal file
17
tests/affine-migration/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["e2e"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../fixtures"
|
||||
},
|
||||
{
|
||||
"path": "../kit"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user