There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor(infra): record legacy data to improve testing stability (#4590)
Joooye_346ea10860b412
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 68ad8dc60c..46246e27f4 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -154,12 +154,6 @@ jobs:name: E2E Migration Testruns-on: ubuntu-latestenvironment: development- strategy:- matrix:- spec:- - { package: 0.7.0-canary.18 }- - { package: 0.8.0-canary.7 }- - { package: 0.8.4 }steps:- uses: actions/checkout@v4- name: Setup Node.js@@ -168,18 +162,15 @@ jobs:playwright-install: trueelectron-install: false- - name: Unzip- run: yarn workspace @affine-legacy/${{ matrix.spec.package }} unzip-- name: Run playwright tests- run: yarn workspace @affine-legacy/${{ matrix.spec.package }} e2e --forbid-only+ run: yarn workspace @affine-test/affine-migration e2e --forbid-only- name: Upload test resultsif: ${{ failure() }}uses: actions/upload-artifact@v3with:- name: test-results-e2e-migration-${{ matrix.spec.package }}- path: ./tests/affine-legacy/${{ matrix.spec.package }}/test-results+ name: test-results-e2e-migration+ path: ./tests/affine-migration/test-resultsif-no-files-found: ignoreunit-test:diff --git a/docs/BUILDING.md b/docs/BUILDING.mdindex 6fb7d0a673..e9e2b88316 100644--- a/docs/BUILDING.md+++ b/docs/BUILDING.md@@ -102,7 +102,7 @@ yarn test### E2E Test```shell-# there are `affine-local`, `affine-legacy/*`, `affine-local`, `affine-plugin`, `affine-prototype` e2e tests,+# there are `affine-local`, `affine-migration`, `affine-local`, `affine-plugin`, `affine-prototype` e2e tests,# which are run under different situations.cd tests/affine-localyarn e2ediff --git a/package.json b/package.jsonindex 78be69b07b..ca756cc267 100644--- a/package.json+++ b/package.json@@ -14,6 +14,7 @@"tests/kit","tests/affine-legacy/*","tests/affine-local",+ "tests/affine-migration","tests/affine-desktop","tests/affine-desktop-cloud","tests/affine-plugin",diff --git a/tests/affine-legacy/0.7.0-canary.18/README.md b/tests/affine-legacy/0.7.0-canary.18/README.mdindex a69605476c..a92a675c5f 100644--- a/tests/affine-legacy/0.7.0-canary.18/README.md+++ b/tests/affine-legacy/0.7.0-canary.18/README.md@@ -1,7 +1,12 @@# AFFiNE Legacy 0.7.0-canary.18-> This package is static output of AFFiNE 0.7.0-canary.18->-> **This package is for debug only**.->-> DO NOT MODIFY `affine-web.zip`+This package is used to record legacy data of 0.7.0-canary.18.+Run following commands locally to record data to `tests/fixtures/legacy/0.7.0-canary.18`.++```sh+cd tests/affine-legacy/0.7.0-canary.18+yarn run unzip+yarn run e2e+```++If you want to debug, running `yarn run e2e --ui` is ok. Or using https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright is more better.diff --git a/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts b/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.tsindex 71642c1ebb..d0913129b0 100644--- a/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts+++ b/tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts@@ -1,36 +1,33 @@-import { resolve } from 'node:path';-+import { patchDataEnhancement } from '@affine-test/kit/e2e-enhance/initializer';+import { SnapshotStorage } from '@affine-test/kit/e2e-enhance/snapshot';import { test } from '@affine-test/kit/playwright';import {clickNewPageButton,waitForEditorLoad,} from '@affine-test/kit/utils/page-logic';-import {- check8080Available,- setupProxyServer,-} from '@affine-test/kit/utils/proxy';-import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';-import { expect } from '@playwright/test';-const { switchToNext } = setupProxyServer(- test,- resolve(__dirname, '..', 'static')-);+test.beforeEach(async ({ page }) => {+ await patchDataEnhancement(page);+});-test('init page', async ({ page, context }) => {- await check8080Available(context);+test('record 0.7.0-canary.18 legacy data', async ({ page }) => {await page.goto('http://localhost:8081/');await waitForEditorLoad(page);await clickNewPageButton(page);const locator = page.locator('v-line').nth(0);await locator.fill('hello');- await switchToNext();- await page.waitForTimeout(1000);- await page.goto('http://localhost:8081/');- await waitForEditorLoad(page);- await clickSideBarAllPageButton(page);- await page.getByText('hello').click();- await waitForEditorLoad(page);- expect(await page.locator('v-line').nth(0).textContent()).toBe('hello');+ const localStorageData = await page.evaluate(() =>+ window.readAffineLocalStorage()+ );+ const { idbData, binaries } = await page.evaluate(() =>+ window.readAffineDatabase()+ );++ const snapshotStorage = new SnapshotStorage('0.7.0-canary.18');+ await snapshotStorage.write({+ idbData,+ localStorageData,+ binaries,+ });});diff --git a/tests/affine-legacy/0.7.0-canary.18/package.json b/tests/affine-legacy/0.7.0-canary.18/package.jsonindex 3dfab48504..c6313d75d8 100644--- a/tests/affine-legacy/0.7.0-canary.18/package.json+++ b/tests/affine-legacy/0.7.0-canary.18/package.json@@ -3,9 +3,8 @@"description": "AFFiNE 0.7.0-canary.18 static output","scripts": {"unzip": "wget -O static.zip https://github.com/toeverything/AFFiNE/releases/download/v0.7.0-canary.18/web-static.zip && unzip static.zip -d static",- "start": "yarn exec serve -s static -l 8082",- "e2e": "yarn playwright test",- "test": "vitest --run"+ "start": "yarn exec serve -s static -l 8081",+ "e2e": "yarn playwright test"},"devDependencies": {"@affine-test/fixtures": "workspace:*",diff --git a/tests/affine-legacy/0.7.0-canary.18/playwright.config.ts b/tests/affine-legacy/0.7.0-canary.18/playwright.config.tsindex 3178c8d316..5bc51cec56 100644--- a/tests/affine-legacy/0.7.0-canary.18/playwright.config.ts+++ b/tests/affine-legacy/0.7.0-canary.18/playwright.config.ts@@ -24,15 +24,11 @@ const config: PlaywrightTestConfig = {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,+ command: 'yarn run start',+ port: 8081,timeout: 120 * 1000,reuseExistingServer: !process.env.CI,- env: {- COVERAGE: process.env.COVERAGE || 'false',- },},],};diff --git a/tests/affine-legacy/0.8.0-canary.7/README.md b/tests/affine-legacy/0.8.0-canary.7/README.mdindex 1c660ffe68..2c552677f6 100644--- a/tests/affine-legacy/0.8.0-canary.7/README.md+++ b/tests/affine-legacy/0.8.0-canary.7/README.md@@ -1,7 +1,12 @@# AFFiNE Legacy 0.8.0-canary.7-> This package is static output of AFFiNE 0.8.0-canary.7->-> **This package is for debug only**.->-> DO NOT MODIFY `affine-core.zip`+This package is used to record legacy data of 0.8.0-canary.7.+Run following commands locally to record data to `tests/fixtures/legacy/0.8.0-canary.7`.++```sh+cd tests/affine-legacy/0.8.0-canary.7+yarn run unzip+yarn run e2e+```++If you want to debug, running `yarn run e2e --ui` is ok. Or using https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright is more better.diff --git a/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts b/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.tsindex f68514df25..5b0538941f 100644--- a/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts+++ b/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts@@ -1,20 +1,12 @@-import { join } from 'node:path';+import { patchDataEnhancement } from '@affine-test/kit/e2e-enhance/initializer';+import { SnapshotStorage } from '@affine-test/kit/e2e-enhance/snapshot';+import { test } from '@playwright/test';-import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';-import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';-import {- check8080Available,- setupProxyServer,-} from '@affine-test/kit/utils/proxy';-import { expect, test } from '@playwright/test';--const { switchToNext } = setupProxyServer(- test,- join(__dirname, '..', 'web-static')-);+test.beforeEach(async ({ page }) => {+ await patchDataEnhancement(page);+});-test('database migration', async ({ page, context }) => {- await check8080Available(context);+test('record 0.8.0-canary.7 database legacy data', async ({ page }) => {await page.goto('http://localhost:8081/');await page.waitForSelector('v-line', {timeout: 10000,@@ -32,22 +24,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();+ const localStorageData = await page.evaluate(() =>+ window.readAffineLocalStorage()+ );+ const { idbData, binaries } = await page.evaluate(() =>+ window.readAffineDatabase()+ );- await switchToNext();- await page.waitForTimeout(1000);- await page.goto(url);- //#region fixme(himself65): blocksuite issue, data cannot be loaded to store- await page.waitForTimeout(5000);- await page.reload();- //#endregion- 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 snapshotStorage = new SnapshotStorage('0.8.0-canary.7');+ await snapshotStorage.write({+ idbData,+ localStorageData,+ binaries,+ });});diff --git a/tests/affine-legacy/0.8.0-canary.7/package.json b/tests/affine-legacy/0.8.0-canary.7/package.jsonindex dbb19b79dd..2d0adaf1bf 100644--- a/tests/affine-legacy/0.8.0-canary.7/package.json+++ b/tests/affine-legacy/0.8.0-canary.7/package.json@@ -3,7 +3,7 @@"description": "AFFiNE 0.8.0-canary.7 static output","scripts": {"unzip": "wget -O static.zip https://github.com/toeverything/AFFiNE/releases/download/v0.8.0-canary.7/web-static.zip && unzip static.zip",- "start": "yarn exec serve -s web-static -l 8082",+ "start": "yarn exec serve -s web-static -l 8081","e2e": "yarn playwright test"},"devDependencies": {diff --git a/tests/affine-legacy/0.8.0-canary.7/playwright.config.ts b/tests/affine-legacy/0.8.0-canary.7/playwright.config.tsindex 3178c8d316..5bc51cec56 100644--- a/tests/affine-legacy/0.8.0-canary.7/playwright.config.ts+++ b/tests/affine-legacy/0.8.0-canary.7/playwright.config.ts@@ -24,15 +24,11 @@ const config: PlaywrightTestConfig = {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,+ command: 'yarn run start',+ port: 8081,timeout: 120 * 1000,reuseExistingServer: !process.env.CI,- env: {- COVERAGE: process.env.COVERAGE || 'false',- },},],};diff --git a/tests/affine-legacy/0.8.4/README.md b/tests/affine-legacy/0.8.4/README.mdindex 2003feabb8..17227b3bec 100644--- a/tests/affine-legacy/0.8.4/README.md+++ b/tests/affine-legacy/0.8.4/README.md@@ -1,7 +1,12 @@-# AFFiNE Legacy 0.8.3+# AFFiNE Legacy 0.8.4-> This package is static output of AFFiNE 0.8.3->-> **This package is for debug only**.->-> DO NOT MODIFY `affine-core.zip`+This package is used to record legacy data of 0.8.4.+Run following commands locally to record data to `tests/fixtures/legacy/0.8.4`.++```sh+cd tests/affine-legacy/0.8.4+yarn run unzip+yarn run e2e+```++If you want to debug, running `yarn run e2e --ui` is ok. Or using https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright is more better.diff --git a/tests/affine-legacy/0.8.4/e2e/basic.spec.ts b/tests/affine-legacy/0.8.4/e2e/basic.spec.tsindex ef1d6d030d..6637a88a44 100644--- a/tests/affine-legacy/0.8.4/e2e/basic.spec.ts+++ b/tests/affine-legacy/0.8.4/e2e/basic.spec.ts@@ -1,23 +1,13 @@-import { join } from 'node:path';+import { patchDataEnhancement } from '@affine-test/kit/e2e-enhance/initializer';+import { SnapshotStorage } from '@affine-test/kit/e2e-enhance/snapshot';+import { getBlockSuiteEditorTitle } from '@affine-test/kit/utils/page-logic';+import { test } from '@playwright/test';-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 { expect, test } from '@playwright/test';--const { switchToNext } = setupProxyServer(- test,- join(__dirname, '..', 'web-static')-);+test.beforeEach(async ({ page }) => {+ await patchDataEnhancement(page);+});-test('surface migration', async ({ page, context }) => {- await check8080Available(context);+test('record 0.8.4 surface legacy data', async ({ page }) => {await page.goto('http://localhost:8081/');await page.waitForSelector('v-line', {timeout: 10000,@@ -47,19 +37,18 @@ test('surface migration', async ({ page, context }) => {steps: 10,});await page.mouse.up();- const url = page.url();- await switchToNext();- await page.waitForTimeout(1000);- await page.goto(url);- //#region fixme(himself65): blocksuite issue, data cannot be loaded to store- await page.waitForTimeout(5000);- await page.reload();- //#endregion- await waitForEditorLoad(page);+ const localStorageData = await page.evaluate(() =>+ window.readAffineLocalStorage()+ );+ const { idbData, binaries } = await page.evaluate(() =>+ window.readAffineDatabase()+ );- // check edgeless mode is correct- await clickEdgelessModeButton(page);- await expect(page.locator('edgeless-toolbar')).toBeVisible();- await expect(page.locator('affine-edgeless-page')).toBeVisible();+ const snapshotStorage = new SnapshotStorage('0.8.4');+ await snapshotStorage.write({+ idbData,+ localStorageData,+ binaries,+ });});diff --git a/tests/affine-legacy/0.8.4/package.json b/tests/affine-legacy/0.8.4/package.jsonindex 79d7057cdf..590789ee2b 100644--- a/tests/affine-legacy/0.8.4/package.json+++ b/tests/affine-legacy/0.8.4/package.json@@ -3,7 +3,7 @@"description": "AFFiNE 0.8.4 static output","scripts": {"unzip": "wget -O static.zip https://github.com/toeverything/AFFiNE/releases/download/v0.8.4/web-static.zip && unzip static.zip",- "start": "yarn exec serve -s web-static -l 8082",+ "start": "yarn exec serve -s web-static -l 8081","e2e": "yarn playwright test"},"devDependencies": {diff --git a/tests/affine-legacy/0.8.4/playwright.config.ts b/tests/affine-legacy/0.8.4/playwright.config.tsindex 193dd0e2b8..eb7a38c2bc 100644--- a/tests/affine-legacy/0.8.4/playwright.config.ts+++ b/tests/affine-legacy/0.8.4/playwright.config.ts@@ -24,15 +24,11 @@ const config: PlaywrightTestConfig = {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,+ command: 'yarn run start',+ port: 8081,timeout: 120 * 1000,reuseExistingServer: !process.env.CI,- env: {- COVERAGE: process.env.COVERAGE || 'false',- },},],};diff --git a/tests/affine-migration/.gitignore b/tests/affine-migration/.gitignorenew file mode 100644index 0000000000..58f3409d7e--- /dev/null+++ b/tests/affine-migration/.gitignore@@ -0,0 +1,5 @@+static+fixtures/*.ydoc+test-results+*.zip+web-staticdiff --git a/tests/affine-migration/README.md b/tests/affine-migration/README.mdnew file mode 100644index 0000000000..ca03f7aac7--- /dev/null+++ b/tests/affine-migration/README.md@@ -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+```diff --git a/tests/affine-migration/e2e/basic.spec.ts b/tests/affine-migration/e2e/basic.spec.tsnew file mode 100644index 0000000000..65ea737df1--- /dev/null+++ b/tests/affine-migration/e2e/basic.spec.ts@@ -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);+ }+});diff --git a/tests/affine-migration/package.json b/tests/affine-migration/package.jsonnew file mode 100644index 0000000000..f6a64a9c7b--- /dev/null+++ b/tests/affine-migration/package.json@@ -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"+}diff --git a/tests/affine-migration/playwright.config.ts b/tests/affine-migration/playwright.config.tsnew file mode 100644index 0000000000..54f4fe5cc3--- /dev/null+++ b/tests/affine-migration/playwright.config.ts@@ -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;diff --git a/tests/affine-migration/tsconfig.json b/tests/affine-migration/tsconfig.jsonnew file mode 100644index 0000000000..a863240646--- /dev/null+++ b/tests/affine-migration/tsconfig.json@@ -0,0 +1,17 @@+{+ "extends": "../../tsconfig.json",+ "compilerOptions": {+ "esModuleInterop": true,+ "resolveJsonModule": true,+ "outDir": "lib"+ },+ "include": ["e2e"],+ "references": [+ {+ "path": "../fixtures"+ },+ {+ "path": "../kit"+ }+ ]+}diff --git a/tests/fixtures/legacy/0.7.0-canary.18/idb.bin b/tests/fixtures/legacy/0.7.0-canary.18/idb.binnew file mode 100644index 0000000000..c68e406fe0Binary files /dev/null and b/tests/fixtures/legacy/0.7.0-canary.18/idb.bin differdiff --git a/tests/fixtures/legacy/0.7.0-canary.18/idb.json b/tests/fixtures/legacy/0.7.0-canary.18/idb.jsonnew file mode 100644index 0000000000..e4a9741ea3--- /dev/null+++ b/tests/fixtures/legacy/0.7.0-canary.18/idb.json@@ -0,0 +1,470 @@+[+ {+ "name": "IBBNBMBvfp_blob",+ "version": 1,+ "stores": [+ {+ "name": "blob",+ "keyPath": null,+ "values": []+ }+ ]+ },+ {+ "name": "affine-local",+ "version": 1,+ "stores": [+ {+ "name": "milestone",+ "keyPath": "id",+ "values": []+ },+ {+ "name": "workspace",+ "keyPath": "id",+ "values": [+ {+ "id": "IBBNBMBvfp",+ "updates": [+ {+ "timestamp": 1697038970936,+ "update": "__BINARY__1"+ },+ {+ "timestamp": 1697038970941,+ "update": "__BINARY__2"+ },+ {+ "timestamp": 1697038970943,+ "update": "__BINARY__3"+ },+ {+ "timestamp": 1697038970946,+ "update": "__BINARY__4"+ },+ {+ "timestamp": 1697038970946,+ "update": "__BINARY__5"+ },+ {+ "timestamp": 1697038970947,+ "update": "__BINARY__6"+ },+ {+ "timestamp": 1697038970948,+ "update": "__BINARY__7"+ },+ {+ "timestamp": 1697038970949,+ "update": "__BINARY__8"+ },+ {+ "timestamp": 1697038970949,+ "update": "__BINARY__9"+ },+ {+ "timestamp": 1697038970964,+ "update": "__BINARY__10"+ },+ {+ "timestamp": 1697038970968,+ "update": "__BINARY__11"+ },+ {+ "timestamp": 1697038970975,+ "update": "__BINARY__12"+ },+ {+ "timestamp": 1697038970978,+ "update": "__BINARY__13"+ },+ {+ "timestamp": 1697038970981,+ "update": "__BINARY__14"+ },+ {+ "timestamp": 1697038970984,+ "update": "__BINARY__15"+ },+ {+ "timestamp": 1697038970987,+ "update": "__BINARY__16"+ },+ {+ "timestamp": 1697038970990,+ "update": "__BINARY__17"+ },+ {+ "timestamp": 1697038970993,+ "update": "__BINARY__18"+ },+ {+ "timestamp": 1697038970996,+ "update": "__BINARY__19"+ },+ {+ "timestamp": 1697038971001,+ "update": "__BINARY__20"+ },+ {+ "timestamp": 1697038971006,+ "update": "__BINARY__21"+ },+ {+ "timestamp": 1697038971009,+ "update": "__BINARY__22"+ },+ {+ "timestamp": 1697038971012,+ "update": "__BINARY__23"+ },+ {+ "timestamp": 1697038971015,+ "update": "__BINARY__24"+ },+ {+ "timestamp": 1697038971017,+ "update": "__BINARY__25"+ },+ {+ "timestamp": 1697038971020,+ "update": "__BINARY__26"+ },+ {+ "timestamp": 1697038971022,+ "update": "__BINARY__27"+ },+ {+ "timestamp": 1697038971025,+ "update": "__BINARY__28"+ },+ {+ "timestamp": 1697038971028,+ "update": "__BINARY__29"+ },+ {+ "timestamp": 1697038971031,+ "update": "__BINARY__30"+ },+ {+ "timestamp": 1697038971034,+ "update": "__BINARY__31"+ },+ {+ "timestamp": 1697038971037,+ "update": "__BINARY__32"+ },+ {+ "timestamp": 1697038971040,+ "update": "__BINARY__33"+ },+ {+ "timestamp": 1697038971042,+ "update": "__BINARY__34"+ },+ {+ "timestamp": 1697038971045,+ "update": "__BINARY__35"+ },+ {+ "timestamp": 1697038971047,+ "update": "__BINARY__36"+ },+ {+ "timestamp": 1697038971050,+ "update": "__BINARY__37"+ },+ {+ "timestamp": 1697038971052,+ "update": "__BINARY__38"+ },+ {+ "timestamp": 1697038971055,+ "update": "__BINARY__39"+ },+ {+ "timestamp": 1697038971058,+ "update": "__BINARY__40"+ },+ {+ "timestamp": 1697038971061,+ "update": "__BINARY__41"+ },+ {+ "timestamp": 1697038971063,+ "update": "__BINARY__42"+ },+ {+ "timestamp": 1697038971066,+ "update": "__BINARY__43"+ },+ {+ "timestamp": 1697038971068,+ "update": "__BINARY__44"+ },+ {+ "timestamp": 1697038971071,+ "update": "__BINARY__45"+ },+ {+ "timestamp": 1697038971074,+ "update": "__BINARY__46"+ },+ {+ "timestamp": 1697038971076,+ "update": "__BINARY__47"+ },+ {+ "timestamp": 1697038971079,+ "update": "__BINARY__48"+ },+ {+ "timestamp": 1697038971081,+ "update": "__BINARY__49"+ },+ {+ "timestamp": 1697038971083,+ "update": "__BINARY__50"+ },+ {+ "timestamp": 1697038971086,+ "update": "__BINARY__51"+ },+ {+ "timestamp": 1697038971089,+ "update": "__BINARY__52"+ },+ {+ "timestamp": 1697038971091,+ "update": "__BINARY__53"+ },+ {+ "timestamp": 1697038971095,+ "update": "__BINARY__54"+ },+ {+ "timestamp": 1697038971098,+ "update": "__BINARY__55"+ },+ {+ "timestamp": 1697038971100,+ "update": "__BINARY__56"+ },+ {+ "timestamp": 1697038971103,+ "update": "__BINARY__57"+ },+ {+ "timestamp": 1697038971106,+ "update": "__BINARY__58"+ },+ {+ "timestamp": 1697038971109,+ "update": "__BINARY__59"+ },+ {+ "timestamp": 1697038971112,+ "update": "__BINARY__60"+ },+ {+ "timestamp": 1697038971114,+ "update": "__BINARY__61"+ },+ {+ "timestamp": 1697038971117,+ "update": "__BINARY__62"+ },+ {+ "timestamp": 1697038971119,+ "update": "__BINARY__63"+ },+ {+ "timestamp": 1697038971123,+ "update": "__BINARY__64"+ },+ {+ "timestamp": 1697038971125,+ "update": "__BINARY__65"+ },+ {+ "timestamp": 1697038971128,+ "update": "__BINARY__66"+ },+ {+ "timestamp": 1697038971131,+ "update": "__BINARY__67"+ },+ {+ "timestamp": 1697038971134,+ "update": "__BINARY__68"+ },+ {+ "timestamp": 1697038971136,+ "update": "__BINARY__69"+ },+ {+ "timestamp": 1697038971139,+ "update": "__BINARY__70"+ },+ {+ "timestamp": 1697038971142,+ "update": "__BINARY__71"+ },+ {+ "timestamp": 1697038971146,+ "update": "__BINARY__72"+ },+ {+ "timestamp": 1697038971149,+ "update": "__BINARY__73"+ },+ {+ "timestamp": 1697038971153,+ "update": "__BINARY__74"+ },+ {+ "timestamp": 1697038971155,+ "update": "__BINARY__75"+ },+ {+ "timestamp": 1697038971158,+ "update": "__BINARY__76"+ },+ {+ "timestamp": 1697038971798,+ "update": "__BINARY__77"+ },+ {+ "timestamp": 1697038972979,+ "update": "__BINARY__78"+ },+ {+ "timestamp": 1697038973588,+ "update": "__BINARY__79"+ },+ {+ "timestamp": 1697038973913,+ "update": "__BINARY__80"+ },+ {+ "timestamp": 1697038973916,+ "update": "__BINARY__81"+ },+ {+ "timestamp": 1697038973920,+ "update": "__BINARY__82"+ },+ {+ "timestamp": 1697038973924,+ "update": "__BINARY__83"+ },+ {+ "timestamp": 1697038973928,+ "update": "__BINARY__84"+ },+ {+ "timestamp": 1697038973931,+ "update": "__BINARY__85"+ },+ {+ "timestamp": 1697038973935,+ "update": "__BINARY__86"+ },+ {+ "timestamp": 1697038973938,+ "update": "__BINARY__87"+ },+ {+ "timestamp": 1697038973942,+ "update": "__BINARY__88"+ },+ {+ "timestamp": 1697038973945,+ "update": "__BINARY__89"+ },+ {+ "timestamp": 1697038973948,+ "update": "__BINARY__90"+ },+ {+ "timestamp": 1697038973951,+ "update": "__BINARY__91"+ },+ {+ "timestamp": 1697038974427,+ "update": "__BINARY__92"+ },+ {+ "timestamp": 1697038974450,+ "update": "__BINARY__93"+ },+ {+ "timestamp": 1697038974453,+ "update": "__BINARY__94"+ },+ {+ "timestamp": 1697038974459,+ "update": "__BINARY__95"+ },+ {+ "timestamp": 1697038974464,+ "update": "__BINARY__96"+ },+ {+ "timestamp": 1697038974467,+ "update": "__BINARY__97"+ },+ {+ "timestamp": 1697038974475,+ "update": "__BINARY__98"+ },+ {+ "timestamp": 1697038974497,+ "update": "__BINARY__99"+ },+ {+ "timestamp": 1697038974501,+ "update": "__BINARY__100"+ },+ {+ "timestamp": 1697038974504,+ "update": "__BINARY__101"+ },+ {+ "timestamp": 1697038974511,+ "update": "__BINARY__102"+ },+ {+ "timestamp": 1697038974515,+ "update": "__BINARY__103"+ },+ {+ "timestamp": 1697038974518,+ "update": "__BINARY__104"+ },+ {+ "timestamp": 1697038974523,+ "update": "__BINARY__105"+ },+ {+ "timestamp": 1697038974527,+ "update": "__BINARY__106"+ }+ ]+ }+ ]+ }+ ]+ },+ {+ "name": "page-view",+ "version": 1,+ "stores": [+ {+ "name": "view",+ "keyPath": "id",+ "values": []+ }+ ]+ }+]diff --git a/tests/fixtures/legacy/0.7.0-canary.18/idb_index.json b/tests/fixtures/legacy/0.7.0-canary.18/idb_index.jsonnew file mode 100644index 0000000000..a884eb2f11--- /dev/null+++ b/tests/fixtures/legacy/0.7.0-canary.18/idb_index.json@@ -0,0 +1,532 @@+[+ {+ "name": "__BINARY__1",+ "start": 0,+ "end": 189+ },+ {+ "name": "__BINARY__2",+ "start": 189,+ "end": 251+ },+ {+ "name": "__BINARY__3",+ "start": 251,+ "end": 564+ },+ {+ "name": "__BINARY__4",+ "start": 564,+ "end": 626+ },+ {+ "name": "__BINARY__5",+ "start": 626,+ "end": 923+ },+ {+ "name": "__BINARY__6",+ "start": 923,+ "end": 985+ },+ {+ "name": "__BINARY__7",+ "start": 985,+ "end": 1280+ },+ {+ "name": "__BINARY__8",+ "start": 1280,+ "end": 1342+ },+ {+ "name": "__BINARY__9",+ "start": 1342,+ "end": 126036+ },+ {+ "name": "__BINARY__10",+ "start": 126036,+ "end": 126099+ },+ {+ "name": "__BINARY__11",+ "start": 126099,+ "end": 126402+ },+ {+ "name": "__BINARY__12",+ "start": 126402,+ "end": 126467+ },+ {+ "name": "__BINARY__13",+ "start": 126467,+ "end": 126769+ },+ {+ "name": "__BINARY__14",+ "start": 126769,+ "end": 126834+ },+ {+ "name": "__BINARY__15",+ "start": 126834,+ "end": 127137+ },+ {+ "name": "__BINARY__16",+ "start": 127137,+ "end": 127202+ },+ {+ "name": "__BINARY__17",+ "start": 127202,+ "end": 127504+ },+ {+ "name": "__BINARY__18",+ "start": 127504,+ "end": 127569+ },+ {+ "name": "__BINARY__19",+ "start": 127569,+ "end": 127873+ },+ {+ "name": "__BINARY__20",+ "start": 127873,+ "end": 127938+ },+ {+ "name": "__BINARY__21",+ "start": 127938,+ "end": 128261+ },+ {+ "name": "__BINARY__22",+ "start": 128261,+ "end": 128326+ },+ {+ "name": "__BINARY__23",+ "start": 128326,+ "end": 128647+ },+ {+ "name": "__BINARY__24",+ "start": 128647,+ "end": 128712+ },+ {+ "name": "__BINARY__25",+ "start": 128712,+ "end": 129034+ },+ {+ "name": "__BINARY__26",+ "start": 129034,+ "end": 129099+ },+ {+ "name": "__BINARY__27",+ "start": 129099,+ "end": 129370+ },+ {+ "name": "__BINARY__28",+ "start": 129370,+ "end": 129435+ },+ {+ "name": "__BINARY__29",+ "start": 129435,+ "end": 129895+ },+ {+ "name": "__BINARY__30",+ "start": 129895,+ "end": 129960+ },+ {+ "name": "__BINARY__31",+ "start": 129960,+ "end": 130307+ },+ {+ "name": "__BINARY__32",+ "start": 130307,+ "end": 130372+ },+ {+ "name": "__BINARY__33",+ "start": 130372,+ "end": 130738+ },+ {+ "name": "__BINARY__34",+ "start": 130738,+ "end": 130803+ },+ {+ "name": "__BINARY__35",+ "start": 130803,+ "end": 131698+ },+ {+ "name": "__BINARY__36",+ "start": 131698,+ "end": 131763+ },+ {+ "name": "__BINARY__37",+ "start": 131763,+ "end": 131916+ },+ {+ "name": "__BINARY__38",+ "start": 131916,+ "end": 131981+ },+ {+ "name": "__BINARY__39",+ "start": 131981,+ "end": 132435+ },+ {+ "name": "__BINARY__40",+ "start": 132435,+ "end": 132500+ },+ {+ "name": "__BINARY__41",+ "start": 132500,+ "end": 132730+ },+ {+ "name": "__BINARY__42",+ "start": 132730,+ "end": 132795+ },+ {+ "name": "__BINARY__43",+ "start": 132795,+ "end": 133172+ },+ {+ "name": "__BINARY__44",+ "start": 133172,+ "end": 133237+ },+ {+ "name": "__BINARY__45",+ "start": 133237,+ "end": 133466+ },+ {+ "name": "__BINARY__46",+ "start": 133466,+ "end": 133531+ },+ {+ "name": "__BINARY__47",+ "start": 133531,+ "end": 133935+ },+ {+ "name": "__BINARY__48",+ "start": 133935,+ "end": 134000+ },+ {+ "name": "__BINARY__49",+ "start": 134000,+ "end": 134228+ },+ {+ "name": "__BINARY__50",+ "start": 134228,+ "end": 134293+ },+ {+ "name": "__BINARY__51",+ "start": 134293,+ "end": 134626+ },+ {+ "name": "__BINARY__52",+ "start": 134626,+ "end": 134691+ },+ {+ "name": "__BINARY__53",+ "start": 134691,+ "end": 134921+ },+ {+ "name": "__BINARY__54",+ "start": 134921,+ "end": 134986+ },+ {+ "name": "__BINARY__55",+ "start": 134986,+ "end": 135372+ },+ {+ "name": "__BINARY__56",+ "start": 135372,+ "end": 135437+ },+ {+ "name": "__BINARY__57",+ "start": 135437,+ "end": 135679+ },+ {+ "name": "__BINARY__58",+ "start": 135679,+ "end": 135744+ },+ {+ "name": "__BINARY__59",+ "start": 135744,+ "end": 136129+ },+ {+ "name": "__BINARY__60",+ "start": 136129,+ "end": 136194+ },+ {+ "name": "__BINARY__61",+ "start": 136194,+ "end": 136417+ },+ {+ "name": "__BINARY__62",+ "start": 136417,+ "end": 136482+ },+ {+ "name": "__BINARY__63",+ "start": 136482,+ "end": 136758+ },+ {+ "name": "__BINARY__64",+ "start": 136758,+ "end": 136823+ },+ {+ "name": "__BINARY__65",+ "start": 136823,+ "end": 137319+ },+ {+ "name": "__BINARY__66",+ "start": 137319,+ "end": 137384+ },+ {+ "name": "__BINARY__67",+ "start": 137384,+ "end": 137538+ },+ {+ "name": "__BINARY__68",+ "start": 137538,+ "end": 137603+ },+ {+ "name": "__BINARY__69",+ "start": 137603,+ "end": 139400+ },+ {+ "name": "__BINARY__70",+ "start": 139400,+ "end": 139465+ },+ {+ "name": "__BINARY__71",+ "start": 139465,+ "end": 139692+ },+ {+ "name": "__BINARY__72",+ "start": 139692,+ "end": 139757+ },+ {+ "name": "__BINARY__73",+ "start": 139757,+ "end": 139980+ },+ {+ "name": "__BINARY__74",+ "start": 139980,+ "end": 140045+ },+ {+ "name": "__BINARY__75",+ "start": 140045,+ "end": 140266+ },+ {+ "name": "__BINARY__76",+ "start": 140266,+ "end": 140331+ },+ {+ "name": "__BINARY__77",+ "start": 140331,+ "end": 278777+ },+ {+ "name": "__BINARY__78",+ "start": 278777,+ "end": 278804+ },+ {+ "name": "__BINARY__79",+ "start": 278804,+ "end": 417260+ },+ {+ "name": "__BINARY__80",+ "start": 417260,+ "end": 417300+ },+ {+ "name": "__BINARY__81",+ "start": 417300,+ "end": 417388+ },+ {+ "name": "__BINARY__82",+ "start": 417388,+ "end": 417475+ },+ {+ "name": "__BINARY__83",+ "start": 417475,+ "end": 417565+ },+ {+ "name": "__BINARY__84",+ "start": 417565,+ "end": 417655+ },+ {+ "name": "__BINARY__85",+ "start": 417655,+ "end": 417743+ },+ {+ "name": "__BINARY__86",+ "start": 417743,+ "end": 417832+ },+ {+ "name": "__BINARY__87",+ "start": 417832,+ "end": 417922+ },+ {+ "name": "__BINARY__88",+ "start": 417922,+ "end": 418014+ },+ {+ "name": "__BINARY__89",+ "start": 418014,+ "end": 418103+ },+ {+ "name": "__BINARY__90",+ "start": 418103,+ "end": 418193+ },+ {+ "name": "__BINARY__91",+ "start": 418193,+ "end": 418230+ },+ {+ "name": "__BINARY__92",+ "start": 418230,+ "end": 418344+ },+ {+ "name": "__BINARY__93",+ "start": 418344,+ "end": 418493+ },+ {+ "name": "__BINARY__94",+ "start": 418493,+ "end": 418523+ },+ {+ "name": "__BINARY__95",+ "start": 418523,+ "end": 418676+ },+ {+ "name": "__BINARY__96",+ "start": 418676,+ "end": 418706+ },+ {+ "name": "__BINARY__97",+ "start": 418706,+ "end": 418979+ },+ {+ "name": "__BINARY__98",+ "start": 418979,+ "end": 419009+ },+ {+ "name": "__BINARY__99",+ "start": 419009,+ "end": 419210+ },+ {+ "name": "__BINARY__100",+ "start": 419210,+ "end": 419240+ },+ {+ "name": "__BINARY__101",+ "start": 419240,+ "end": 419281+ },+ {+ "name": "__BINARY__102",+ "start": 419281,+ "end": 419323+ },+ {+ "name": "__BINARY__103",+ "start": 419323,+ "end": 419360+ },+ {+ "name": "__BINARY__104",+ "start": 419360,+ "end": 419397+ },+ {+ "name": "__BINARY__105",+ "start": 419397,+ "end": 419438+ },+ {+ "name": "__BINARY__106",+ "start": 419438,+ "end": 419473+ }+]diff --git a/tests/fixtures/legacy/0.7.0-canary.18/local-storage.json b/tests/fixtures/legacy/0.7.0-canary.18/local-storage.jsonnew file mode 100644index 0000000000..10d930e818--- /dev/null+++ b/tests/fixtures/legacy/0.7.0-canary.18/local-storage.json@@ -0,0 +1,7 @@+{+ "jotai-workspaces": "[{\"id\":\"IBBNBMBvfp\",\"flavour\":\"local\"}]",+ "last_page_id": "P2JKlb2H46",+ "last_workspace_id": "IBBNBMBvfp",+ "affine-local-workspace": "[\"IBBNBMBvfp\"]",+ "is-first-open": "false"+}diff --git a/tests/fixtures/legacy/0.8.0-canary.7/idb.bin b/tests/fixtures/legacy/0.8.0-canary.7/idb.binnew file mode 100644index 0000000000..6656831809Binary files /dev/null and b/tests/fixtures/legacy/0.8.0-canary.7/idb.bin differdiff --git a/tests/fixtures/legacy/0.8.0-canary.7/idb.json b/tests/fixtures/legacy/0.8.0-canary.7/idb.jsonnew file mode 100644index 0000000000..70f4275227--- /dev/null+++ b/tests/fixtures/legacy/0.8.0-canary.7/idb.json@@ -0,0 +1,255 @@+[+ {+ "name": "52FVff-1rf_blob",+ "version": 1,+ "stores": [+ {+ "name": "blob",+ "keyPath": null,+ "values": []+ }+ ]+ },+ {+ "name": "52FVff-1rf_blob_mime",+ "version": 1,+ "stores": [+ {+ "name": "blob_mime",+ "keyPath": null,+ "values": []+ }+ ]+ },+ {+ "name": "affine-local",+ "version": 1,+ "stores": [+ {+ "name": "milestone",+ "keyPath": "id",+ "values": []+ },+ {+ "name": "workspace",+ "keyPath": "id",+ "values": [+ {+ "id": "52FVff-1rf",+ "updates": [+ {+ "timestamp": 1697039052176,+ "update": "__BINARY__1"+ },+ {+ "timestamp": 1697039052473,+ "update": "__BINARY__2"+ },+ {+ "timestamp": 1697039052508,+ "update": "__BINARY__3"+ },+ {+ "timestamp": 1697039052513,+ "update": "__BINARY__4"+ },+ {+ "timestamp": 1697039052647,+ "update": "__BINARY__5"+ },+ {+ "timestamp": 1697039052649,+ "update": "__BINARY__6"+ },+ {+ "timestamp": 1697039052651,+ "update": "__BINARY__7"+ },+ {+ "timestamp": 1697039052652,+ "update": "__BINARY__8"+ },+ {+ "timestamp": 1697039052653,+ "update": "__BINARY__9"+ },+ {+ "timestamp": 1697039052654,+ "update": "__BINARY__10"+ },+ {+ "timestamp": 1697039052655,+ "update": "__BINARY__11"+ },+ {+ "timestamp": 1697039052657,+ "update": "__BINARY__12"+ },+ {+ "timestamp": 1697039052658,+ "update": "__BINARY__13"+ },+ {+ "timestamp": 1697039052659,+ "update": "__BINARY__14"+ },+ {+ "timestamp": 1697039052661,+ "update": "__BINARY__15"+ },+ {+ "timestamp": 1697039052942,+ "update": "__BINARY__16"+ },+ {+ "timestamp": 1697039052943,+ "update": "__BINARY__17"+ },+ {+ "timestamp": 1697039052945,+ "update": "__BINARY__18"+ },+ {+ "timestamp": 1697039052947,+ "update": "__BINARY__19"+ }+ ]+ },+ {+ "id": "space:52FVff-1rf-hello-world",+ "updates": [+ {+ "timestamp": 1697039052209,+ "update": "__BINARY__20"+ }+ ]+ },+ {+ "id": "space:wtCoS4jUeY",+ "updates": [+ {+ "timestamp": 1697039052615,+ "update": "__BINARY__21"+ },+ {+ "timestamp": 1697039052648,+ "update": "__BINARY__22"+ },+ {+ "timestamp": 1697039052650,+ "update": "__BINARY__23"+ },+ {+ "timestamp": 1697039052652,+ "update": "__BINARY__24"+ },+ {+ "timestamp": 1697039052653,+ "update": "__BINARY__25"+ },+ {+ "timestamp": 1697039052655,+ "update": "__BINARY__26"+ },+ {+ "timestamp": 1697039052656,+ "update": "__BINARY__27"+ },+ {+ "timestamp": 1697039052657,+ "update": "__BINARY__28"+ },+ {+ "timestamp": 1697039052659,+ "update": "__BINARY__29"+ },+ {+ "timestamp": 1697039052660,+ "update": "__BINARY__30"+ },+ {+ "timestamp": 1697039052661,+ "update": "__BINARY__31"+ },+ {+ "timestamp": 1697039052730,+ "update": "__BINARY__32"+ },+ {+ "timestamp": 1697039052791,+ "update": "__BINARY__33"+ },+ {+ "timestamp": 1697039052802,+ "update": "__BINARY__34"+ },+ {+ "timestamp": 1697039052803,+ "update": "__BINARY__35"+ },+ {+ "timestamp": 1697039052821,+ "update": "__BINARY__36"+ },+ {+ "timestamp": 1697039052822,+ "update": "__BINARY__37"+ },+ {+ "timestamp": 1697039052823,+ "update": "__BINARY__38"+ },+ {+ "timestamp": 1697039052938,+ "update": "__BINARY__39"+ },+ {+ "timestamp": 1697039052939,+ "update": "__BINARY__40"+ },+ {+ "timestamp": 1697039052940,+ "update": "__BINARY__41"+ },+ {+ "timestamp": 1697039052941,+ "update": "__BINARY__42"+ },+ {+ "timestamp": 1697039052942,+ "update": "__BINARY__43"+ },+ {+ "timestamp": 1697039052944,+ "update": "__BINARY__44"+ },+ {+ "timestamp": 1697039052946,+ "update": "__BINARY__45"+ },+ {+ "timestamp": 1697039052948,+ "update": "__BINARY__46"+ },+ {+ "timestamp": 1697039052949,+ "update": "__BINARY__47"+ }+ ]+ }+ ]+ }+ ]+ },+ {+ "name": "page-view",+ "version": 1,+ "stores": [+ {+ "name": "view",+ "keyPath": "id",+ "values": []+ }+ ]+ }+]diff --git a/tests/fixtures/legacy/0.8.0-canary.7/idb_index.json b/tests/fixtures/legacy/0.8.0-canary.7/idb_index.jsonnew file mode 100644index 0000000000..48ada0ee11--- /dev/null+++ b/tests/fixtures/legacy/0.8.0-canary.7/idb_index.json@@ -0,0 +1,237 @@+[+ {+ "name": "__BINARY__1",+ "start": 0,+ "end": 774+ },+ {+ "name": "__BINARY__2",+ "start": 774,+ "end": 920+ },+ {+ "name": "__BINARY__3",+ "start": 920,+ "end": 974+ },+ {+ "name": "__BINARY__4",+ "start": 974,+ "end": 1013+ },+ {+ "name": "__BINARY__5",+ "start": 1013,+ "end": 1040+ },+ {+ "name": "__BINARY__6",+ "start": 1040,+ "end": 1067+ },+ {+ "name": "__BINARY__7",+ "start": 1067,+ "end": 1094+ },+ {+ "name": "__BINARY__8",+ "start": 1094,+ "end": 1121+ },+ {+ "name": "__BINARY__9",+ "start": 1121,+ "end": 1155+ },+ {+ "name": "__BINARY__10",+ "start": 1155,+ "end": 1183+ },+ {+ "name": "__BINARY__11",+ "start": 1183,+ "end": 1212+ },+ {+ "name": "__BINARY__12",+ "start": 1212,+ "end": 1242+ },+ {+ "name": "__BINARY__13",+ "start": 1242,+ "end": 1273+ },+ {+ "name": "__BINARY__14",+ "start": 1273,+ "end": 1305+ },+ {+ "name": "__BINARY__15",+ "start": 1305,+ "end": 1337+ },+ {+ "name": "__BINARY__16",+ "start": 1337,+ "end": 1369+ },+ {+ "name": "__BINARY__17",+ "start": 1369,+ "end": 1401+ },+ {+ "name": "__BINARY__18",+ "start": 1401,+ "end": 1433+ },+ {+ "name": "__BINARY__19",+ "start": 1433,+ "end": 1465+ },+ {+ "name": "__BINARY__20",+ "start": 1465,+ "end": 141929+ },+ {+ "name": "__BINARY__21",+ "start": 141929,+ "end": 142063+ },+ {+ "name": "__BINARY__22",+ "start": 142063,+ "end": 142224+ },+ {+ "name": "__BINARY__23",+ "start": 142224,+ "end": 142500+ },+ {+ "name": "__BINARY__24",+ "start": 142500,+ "end": 142684+ },+ {+ "name": "__BINARY__25",+ "start": 142684,+ "end": 143412+ },+ {+ "name": "__BINARY__26",+ "start": 143412,+ "end": 143431+ },+ {+ "name": "__BINARY__27",+ "start": 143431,+ "end": 143449+ },+ {+ "name": "__BINARY__28",+ "start": 143449,+ "end": 143467+ },+ {+ "name": "__BINARY__29",+ "start": 143467,+ "end": 143485+ },+ {+ "name": "__BINARY__30",+ "start": 143485,+ "end": 143503+ },+ {+ "name": "__BINARY__31",+ "start": 143503,+ "end": 143686+ },+ {+ "name": "__BINARY__32",+ "start": 143686,+ "end": 143705+ },+ {+ "name": "__BINARY__33",+ "start": 143705,+ "end": 143723+ },+ {+ "name": "__BINARY__34",+ "start": 143723,+ "end": 143741+ },+ {+ "name": "__BINARY__35",+ "start": 143741,+ "end": 143759+ },+ {+ "name": "__BINARY__36",+ "start": 143759,+ "end": 143777+ },+ {+ "name": "__BINARY__37",+ "start": 143777,+ "end": 143795+ },+ {+ "name": "__BINARY__38",+ "start": 143795,+ "end": 143819+ },+ {+ "name": "__BINARY__39",+ "start": 143819,+ "end": 143831+ },+ {+ "name": "__BINARY__40",+ "start": 143831,+ "end": 144329+ },+ {+ "name": "__BINARY__41",+ "start": 144329,+ "end": 144593+ },+ {+ "name": "__BINARY__42",+ "start": 144593,+ "end": 144768+ },+ {+ "name": "__BINARY__43",+ "start": 144768,+ "end": 144952+ },+ {+ "name": "__BINARY__44",+ "start": 144952,+ "end": 145135+ },+ {+ "name": "__BINARY__45",+ "start": 145135,+ "end": 145318+ },+ {+ "name": "__BINARY__46",+ "start": 145318,+ "end": 145437+ },+ {+ "name": "__BINARY__47",+ "start": 145437,+ "end": 145665+ }+]diff --git a/tests/fixtures/legacy/0.8.0-canary.7/local-storage.json b/tests/fixtures/legacy/0.8.0-canary.7/local-storage.jsonnew file mode 100644index 0000000000..1167731351--- /dev/null+++ b/tests/fixtures/legacy/0.8.0-canary.7/local-storage.json@@ -0,0 +1,7 @@+{+ "jotai-workspaces": "[{\"id\":\"52FVff-1rf\",\"flavour\":\"local\",\"version\":2}]",+ "last_page_id": "wtCoS4jUeY",+ "last_workspace_id": "52FVff-1rf",+ "affine-local-workspace": "[\"52FVff-1rf\"]",+ "is-first-open": "false"+}diff --git a/tests/fixtures/legacy/0.8.4/idb.bin b/tests/fixtures/legacy/0.8.4/idb.binnew file mode 100644index 0000000000..8cb12b3dbdBinary files /dev/null and b/tests/fixtures/legacy/0.8.4/idb.bin differdiff --git a/tests/fixtures/legacy/0.8.4/idb.json b/tests/fixtures/legacy/0.8.4/idb.jsonnew file mode 100644index 0000000000..114e6d9205--- /dev/null+++ b/tests/fixtures/legacy/0.8.4/idb.json@@ -0,0 +1,350 @@+[+ {+ "name": "affine-local",+ "version": 1,+ "stores": [+ {+ "name": "milestone",+ "keyPath": "id",+ "values": []+ },+ {+ "name": "workspace",+ "keyPath": "id",+ "values": [+ {+ "id": "hsraMjtX5k",+ "updates": [+ {+ "timestamp": 1697039130426,+ "update": "__BINARY__1"+ },+ {+ "timestamp": 1697039130428,+ "update": "__BINARY__2"+ },+ {+ "timestamp": 1697039130654,+ "update": "__BINARY__3"+ },+ {+ "timestamp": 1697039130699,+ "update": "__BINARY__4"+ },+ {+ "timestamp": 1697039130701,+ "update": "__BINARY__5"+ },+ {+ "timestamp": 1697039130822,+ "update": "__BINARY__6"+ },+ {+ "timestamp": 1697039130824,+ "update": "__BINARY__7"+ },+ {+ "timestamp": 1697039130826,+ "update": "__BINARY__8"+ },+ {+ "timestamp": 1697039130828,+ "update": "__BINARY__9"+ },+ {+ "timestamp": 1697039130855,+ "update": "__BINARY__10"+ },+ {+ "timestamp": 1697039130857,+ "update": "__BINARY__11"+ },+ {+ "timestamp": 1697039130858,+ "update": "__BINARY__12"+ },+ {+ "timestamp": 1697039130860,+ "update": "__BINARY__13"+ },+ {+ "timestamp": 1697039130861,+ "update": "__BINARY__14"+ },+ {+ "timestamp": 1697039130862,+ "update": "__BINARY__15"+ },+ {+ "timestamp": 1697039130866,+ "update": "__BINARY__16"+ },+ {+ "timestamp": 1697039131400,+ "update": "__BINARY__17"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:0N0WzwmtK_",+ "updates": [+ {+ "timestamp": 1697039130472,+ "update": "__BINARY__18"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:3R9X-gMh3m",+ "updates": [+ {+ "timestamp": 1697039130468,+ "update": "__BINARY__19"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:6gexHy-jto",+ "updates": [+ {+ "timestamp": 1697039130473,+ "update": "__BINARY__20"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:A4wBRdQZN0",+ "updates": [+ {+ "timestamp": 1697039130485,+ "update": "__BINARY__21"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:F1SX6cgNxy",+ "updates": [+ {+ "timestamp": 1697039130469,+ "update": "__BINARY__22"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:PqZ7MLlL_9",+ "updates": [+ {+ "timestamp": 1697039130478,+ "update": "__BINARY__23"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:Ra-VT4A8dt",+ "updates": [+ {+ "timestamp": 1697039130821,+ "update": "__BINARY__24"+ },+ {+ "timestamp": 1697039130823,+ "update": "__BINARY__25"+ },+ {+ "timestamp": 1697039130825,+ "update": "__BINARY__26"+ },+ {+ "timestamp": 1697039130827,+ "update": "__BINARY__27"+ },+ {+ "timestamp": 1697039130856,+ "update": "__BINARY__28"+ },+ {+ "timestamp": 1697039130857,+ "update": "__BINARY__29"+ },+ {+ "timestamp": 1697039130859,+ "update": "__BINARY__30"+ },+ {+ "timestamp": 1697039130860,+ "update": "__BINARY__31"+ },+ {+ "timestamp": 1697039130862,+ "update": "__BINARY__32"+ },+ {+ "timestamp": 1697039130863,+ "update": "__BINARY__33"+ },+ {+ "timestamp": 1697039130864,+ "update": "__BINARY__34"+ },+ {+ "timestamp": 1697039130913,+ "update": "__BINARY__35"+ },+ {+ "timestamp": 1697039130972,+ "update": "__BINARY__36"+ },+ {+ "timestamp": 1697039131030,+ "update": "__BINARY__37"+ },+ {+ "timestamp": 1697039131085,+ "update": "__BINARY__38"+ },+ {+ "timestamp": 1697039131140,+ "update": "__BINARY__39"+ },+ {+ "timestamp": 1697039131404,+ "update": "__BINARY__40"+ },+ {+ "timestamp": 1697039132167,+ "update": "__BINARY__41"+ },+ {+ "timestamp": 1697039132167,+ "update": "__BINARY__42"+ },+ {+ "timestamp": 1697039132189,+ "update": "__BINARY__43"+ },+ {+ "timestamp": 1697039132203,+ "update": "__BINARY__44"+ },+ {+ "timestamp": 1697039132219,+ "update": "__BINARY__45"+ },+ {+ "timestamp": 1697039132236,+ "update": "__BINARY__46"+ },+ {+ "timestamp": 1697039132251,+ "update": "__BINARY__47"+ },+ {+ "timestamp": 1697039132271,+ "update": "__BINARY__48"+ },+ {+ "timestamp": 1697039132287,+ "update": "__BINARY__49"+ },+ {+ "timestamp": 1697039132302,+ "update": "__BINARY__50"+ },+ {+ "timestamp": 1697039132321,+ "update": "__BINARY__51"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:bj_cuI1tN7",+ "updates": [+ {+ "timestamp": 1697039130476,+ "update": "__BINARY__52"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:fFoDX2J1Z5",+ "updates": [+ {+ "timestamp": 1697039130477,+ "update": "__BINARY__53"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:gc5FeppNDv-hello-world",+ "updates": [+ {+ "timestamp": 1697039130467,+ "update": "__BINARY__54"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:kBB4lzhm7C",+ "updates": [+ {+ "timestamp": 1697039130486,+ "update": "__BINARY__55"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:nQd2Bdvoqz",+ "updates": [+ {+ "timestamp": 1697039130479,+ "update": "__BINARY__56"+ }+ ]+ },+ {+ "id": "hsraMjtX5k:space:z_v6LOqNpp",+ "updates": [+ {+ "timestamp": 1697039130469,+ "update": "__BINARY__57"+ }+ ]+ }+ ]+ }+ ]+ },+ {+ "name": "hsraMjtX5k_blob",+ "version": 1,+ "stores": [+ {+ "name": "blob",+ "keyPath": null,+ "values": []+ }+ ]+ },+ {+ "name": "hsraMjtX5k_blob_mime",+ "version": 1,+ "stores": [+ {+ "name": "blob_mime",+ "keyPath": null,+ "values": []+ }+ ]+ },+ {+ "name": "page-view",+ "version": 1,+ "stores": [+ {+ "name": "view",+ "keyPath": "id",+ "values": []+ }+ ]+ }+]diff --git a/tests/fixtures/legacy/0.8.4/idb_index.json b/tests/fixtures/legacy/0.8.4/idb_index.jsonnew file mode 100644index 0000000000..abc630a465--- /dev/null+++ b/tests/fixtures/legacy/0.8.4/idb_index.json@@ -0,0 +1,287 @@+[+ {+ "name": "__BINARY__1",+ "start": 0,+ "end": 35+ },+ {+ "name": "__BINARY__2",+ "start": 35,+ "end": 4639+ },+ {+ "name": "__BINARY__3",+ "start": 4639,+ "end": 4802+ },+ {+ "name": "__BINARY__4",+ "start": 4802,+ "end": 4868+ },+ {+ "name": "__BINARY__5",+ "start": 4868,+ "end": 4909+ },+ {+ "name": "__BINARY__6",+ "start": 4909,+ "end": 4939+ },+ {+ "name": "__BINARY__7",+ "start": 4939,+ "end": 4969+ },+ {+ "name": "__BINARY__8",+ "start": 4969,+ "end": 4999+ },+ {+ "name": "__BINARY__9",+ "start": 4999,+ "end": 5029+ },+ {+ "name": "__BINARY__10",+ "start": 5029,+ "end": 5066+ },+ {+ "name": "__BINARY__11",+ "start": 5066,+ "end": 5097+ },+ {+ "name": "__BINARY__12",+ "start": 5097,+ "end": 5129+ },+ {+ "name": "__BINARY__13",+ "start": 5129,+ "end": 5162+ },+ {+ "name": "__BINARY__14",+ "start": 5162,+ "end": 5196+ },+ {+ "name": "__BINARY__15",+ "start": 5196,+ "end": 5231+ },+ {+ "name": "__BINARY__16",+ "start": 5231,+ "end": 5266+ },+ {+ "name": "__BINARY__17",+ "start": 5266,+ "end": 5303+ },+ {+ "name": "__BINARY__18",+ "start": 5303,+ "end": 9423+ },+ {+ "name": "__BINARY__19",+ "start": 9423,+ "end": 12533+ },+ {+ "name": "__BINARY__20",+ "start": 12533,+ "end": 14760+ },+ {+ "name": "__BINARY__21",+ "start": 14760,+ "end": 18476+ },+ {+ "name": "__BINARY__22",+ "start": 18476,+ "end": 158902+ },+ {+ "name": "__BINARY__23",+ "start": 158902,+ "end": 163325+ },+ {+ "name": "__BINARY__24",+ "start": 163325,+ "end": 163459+ },+ {+ "name": "__BINARY__25",+ "start": 163459,+ "end": 163620+ },+ {+ "name": "__BINARY__26",+ "start": 163620,+ "end": 163895+ },+ {+ "name": "__BINARY__27",+ "start": 163895,+ "end": 164079+ },+ {+ "name": "__BINARY__28",+ "start": 164079,+ "end": 164806+ },+ {+ "name": "__BINARY__29",+ "start": 164806,+ "end": 164825+ },+ {+ "name": "__BINARY__30",+ "start": 164825,+ "end": 164843+ },+ {+ "name": "__BINARY__31",+ "start": 164843,+ "end": 164861+ },+ {+ "name": "__BINARY__32",+ "start": 164861,+ "end": 164879+ },+ {+ "name": "__BINARY__33",+ "start": 164879,+ "end": 164897+ },+ {+ "name": "__BINARY__34",+ "start": 164897,+ "end": 165080+ },+ {+ "name": "__BINARY__35",+ "start": 165080,+ "end": 165099+ },+ {+ "name": "__BINARY__36",+ "start": 165099,+ "end": 165117+ },+ {+ "name": "__BINARY__37",+ "start": 165117,+ "end": 165135+ },+ {+ "name": "__BINARY__38",+ "start": 165135,+ "end": 165153+ },+ {+ "name": "__BINARY__39",+ "start": 165153,+ "end": 165171+ },+ {+ "name": "__BINARY__40",+ "start": 165171,+ "end": 165211+ },+ {+ "name": "__BINARY__41",+ "start": 165211,+ "end": 165469+ },+ {+ "name": "__BINARY__42",+ "start": 165469,+ "end": 165596+ },+ {+ "name": "__BINARY__43",+ "start": 165596,+ "end": 165732+ },+ {+ "name": "__BINARY__44",+ "start": 165732,+ "end": 165882+ },+ {+ "name": "__BINARY__45",+ "start": 165882,+ "end": 166044+ },+ {+ "name": "__BINARY__46",+ "start": 166044,+ "end": 166216+ },+ {+ "name": "__BINARY__47",+ "start": 166216,+ "end": 166404+ },+ {+ "name": "__BINARY__48",+ "start": 166404,+ "end": 166605+ },+ {+ "name": "__BINARY__49",+ "start": 166605,+ "end": 166819+ },+ {+ "name": "__BINARY__50",+ "start": 166819,+ "end": 167046+ },+ {+ "name": "__BINARY__51",+ "start": 167046,+ "end": 167286+ },+ {+ "name": "__BINARY__52",+ "start": 167286,+ "end": 177177+ },+ {+ "name": "__BINARY__53",+ "start": 177177,+ "end": 185089+ },+ {+ "name": "__BINARY__54",+ "start": 185089,+ "end": 190349+ },+ {+ "name": "__BINARY__55",+ "start": 190349,+ "end": 195939+ },+ {+ "name": "__BINARY__56",+ "start": 195939,+ "end": 284834+ },+ {+ "name": "__BINARY__57",+ "start": 284834,+ "end": 287903+ }+]diff --git a/tests/fixtures/legacy/0.8.4/local-storage.json b/tests/fixtures/legacy/0.8.4/local-storage.jsonnew file mode 100644index 0000000000..9c438dddbf--- /dev/null+++ b/tests/fixtures/legacy/0.8.4/local-storage.json@@ -0,0 +1,7 @@+{+ "jotai-workspaces": "[{\"id\":\"hsraMjtX5k\",\"flavour\":\"local\",\"version\":3}]",+ "last_page_id": "Ra-VT4A8dt",+ "last_workspace_id": "hsraMjtX5k",+ "affine-local-workspace": "[\"hsraMjtX5k\"]",+ "is-first-open": "false"+}diff --git a/tests/fixtures/legacy/README.md b/tests/fixtures/legacy/README.mdnew file mode 100644index 0000000000..cba4cda282--- /dev/null+++ b/tests/fixtures/legacy/README.md@@ -0,0 +1,4 @@+# fixtures/legacy++The legacy data of affine is stored here to do migration testing.+Running e2e testing in `tests/affine-legacy` will record data to here.diff --git a/tests/fixtures/tsconfig.json b/tests/fixtures/tsconfig.jsonindex bd90e03952..ea878080b3 100644--- a/tests/fixtures/tsconfig.json+++ b/tests/fixtures/tsconfig.json@@ -8,6 +8,6 @@"module": "NodeNext","resolveJsonModule": true},- "include": [".", "./*.json"],+ "include": [".", "./*.json", "./legacy/**/*.json"],"exclude": ["./tsconfig.json"]}diff --git a/tests/kit/e2e-enhance/initializer.ts b/tests/kit/e2e-enhance/initializer.tsnew file mode 100644index 0000000000..38779fd07f--- /dev/null+++ b/tests/kit/e2e-enhance/initializer.ts@@ -0,0 +1,18 @@+import { dirname, join } from 'node:path';++import type { Page } from '@playwright/test';++declare global {+ function readAffineDatabase(): Promise<any>;+ function writeAffineDatabase(data: any, binaries: any): Promise<void>;+ function readAffineLocalStorage(): Promise<any>;+ function writeAffineLocalStorage(data: any): Promise<void>;+}++export async function patchDataEnhancement(page: Page) {+ const idbPath = join(dirname(require.resolve('idb')), 'umd.js');+ await page.addInitScript({ path: idbPath });++ const patchPath = join(__dirname, './storage-patch.js');+ await page.addInitScript({ path: patchPath });+}diff --git a/tests/kit/e2e-enhance/snapshot.ts b/tests/kit/e2e-enhance/snapshot.tsnew file mode 100644index 0000000000..6ba0e3c416--- /dev/null+++ b/tests/kit/e2e-enhance/snapshot.ts@@ -0,0 +1,109 @@+import { readFile, writeFile } from 'node:fs/promises';+import { dirname, join } from 'node:path';++import { mkdirp, readJSON } from 'fs-extra';++interface SnapshotData {+ idbData: Record<string, any>;+ localStorageData: Record<string, string>;+ binaries: Record<string, number[]>;+}++interface BinaryIndexData {+ name: string;+ start: number;+ end: number;+}++export class SnapshotStorage {+ idbFilePath: string;+ localStorageFilePath: string;+ binaryIndexPath: string;+ binaryFilePath: string;++ constructor(version: string) {+ // The snapshots data is stored in "@affine-test/fixtures/legacy", just keep all fixtures in one place+ const legacyReadMeFilePath = require.resolve(+ '@affine-test/fixtures/legacy/README.md'+ );+ const dir = dirname(legacyReadMeFilePath);++ this.idbFilePath = join(dir, version, 'idb.json');+ this.binaryFilePath = join(dir, version, 'idb.bin');+ this.binaryIndexPath = join(dir, version, 'idb_index.json');+ this.localStorageFilePath = join(dir, version, 'local-storage.json');+ }++ async read(): Promise<SnapshotData> {+ const {+ idbFilePath,+ localStorageFilePath,+ binaryIndexPath,+ binaryFilePath,+ } = this;++ const [idbData, localStorageData, binaryIndexArr, binaryContent] =+ await Promise.all([+ readJSON(idbFilePath),+ readJSON(localStorageFilePath),+ readJSON(binaryIndexPath) as Promise<BinaryIndexData[]>,+ readFile(binaryFilePath),+ ]);++ const binaries: Record<string, number[]> = {};+ for (const index of binaryIndexArr) {+ const chunk = binaryContent.subarray(index.start, index.end);+ binaries[index.name] = Array.from(chunk);+ }++ return {+ binaries,+ idbData,+ localStorageData,+ };+ }++ async write(data: SnapshotData) {+ const {+ idbFilePath,+ localStorageFilePath,+ binaryIndexPath,+ binaryFilePath,+ } = this;+ const { idbData, localStorageData, binaries } = data;++ await mkdirp(dirname(idbFilePath));++ const binaryIndexData: BinaryIndexData[] = [];+ const binaryBuffers: Buffer[] = [];+ let currentIndex = 0;+ for (const [name, value] of Object.entries(binaries)) {+ const buffer = Buffer.from(value);+ const endIndex = currentIndex + buffer.length;++ binaryIndexData.push({+ name,+ start: currentIndex,+ end: endIndex,+ });+ binaryBuffers.push(buffer);++ currentIndex += buffer.length;+ }++ await Promise.all([+ writeFile(+ localStorageFilePath,+ JSON.stringify(localStorageData, null, 2),+ 'utf-8'+ ),+ writeFile(idbFilePath, JSON.stringify(idbData, null, 2), 'utf-8'),+ writeFile(+ binaryIndexPath,+ JSON.stringify(binaryIndexData, null, 2),+ 'utf-8'+ ),+ writeFile(binaryFilePath, Buffer.concat(binaryBuffers), 'utf-8'),+ ]);+ }+}diff --git a/tests/kit/e2e-enhance/storage-patch.js b/tests/kit/e2e-enhance/storage-patch.jsnew file mode 100644index 0000000000..e287a1f3d5--- /dev/null+++ b/tests/kit/e2e-enhance/storage-patch.js@@ -0,0 +1,141 @@+/**+ * @type {import('idb')}+ */+const idb = window.idb;++const createUniqueIndex = (() => {+ let index = 0;+ return () => ++index;+})();++function replaceBinary(value, binaries) {+ if (value instanceof Uint8Array) {+ const name = `__BINARY__${createUniqueIndex()}`;+ binaries[name] = Array.from(value);+ return name;+ }++ if (Array.isArray(value)) {+ return value.map(item => replaceBinary(item, binaries));+ }++ if (typeof value === 'object' && value !== null) {+ const replaced = {};+ for (const key of Object.keys(value)) {+ replaced[key] = replaceBinary(value[key], binaries);+ }+ return replaced;+ }++ return value;+}++function recoveryBinary(value, binaries) {+ if (typeof value === 'string') {+ const arr = binaries[value];+ if (arr) {+ return new Uint8Array(arr);+ }+ }++ if (Array.isArray(value)) {+ return value.map(item => recoveryBinary(item, binaries));+ }++ if (typeof value === 'object' && value !== null) {+ const result = {};+ for (const key of Object.keys(value)) {+ result[key] = recoveryBinary(value[key], binaries);+ }+ return result;+ }++ return value;+}++async function readAffineDatabase() {+ const idbData = [];+ const binaries = {};++ const databases = await indexedDB.databases();+ for (const databaseInfo of databases) {+ const idbDatabase = await idb.openDB(+ databaseInfo.name,+ databaseInfo.version+ );+ if (!idbDatabase) {+ throw new Error('idbDatabase is null');+ }++ const stores = [];+ const objectStoreNames = Array.from(idbDatabase.objectStoreNames);+ const transaction = idbDatabase.transaction(objectStoreNames, 'readonly');++ for (const storeName of objectStoreNames) {+ const objectStore = transaction.objectStore(storeName);+ const objectValues = await objectStore.getAll();++ stores.push({+ name: storeName,+ keyPath: objectStore.keyPath,+ values: replaceBinary(objectValues, binaries),+ });+ }++ idbData.push({ ...databaseInfo, stores });+ }++ return { idbData, binaries };+}++async function writeAffineDatabase(allDatabases, binaries) {+ for (const database of allDatabases) {+ const idbDatabase = await idb.openDB(database.name, database.version, {+ upgrade(db) {+ for (const objectStore of database.stores) {+ db.createObjectStore(objectStore.name, {+ keyPath: objectStore.keyPath,+ });+ }+ },+ });++ for (const store of database.stores) {+ const transaction = idbDatabase.transaction(store.name, 'readwrite');+ const objectStore = transaction.objectStore(store.name);++ for (const value of store.values) {+ await objectStore.add(recoveryBinary(value, binaries));+ }+ }+ }+}++async function readAffineLocalStorage() {+ const data = {};++ const keys = [+ 'jotai-workspaces',+ 'last_page_id',+ 'last_workspace_id',+ 'affine-local-workspace',+ 'is-first-open',+ ];+ for (const key of keys) {+ const value = window.localStorage.getItem(key);+ data[key] = value;+ }++ return data;+}++async function writeAffineLocalStorage(data) {+ for (const [key, value] of Object.entries(data)) {+ window.localStorage.setItem(key, value);+ }+}++window.readAffineDatabase = readAffineDatabase;+window.writeAffineDatabase = writeAffineDatabase;+window.readAffineLocalStorage = readAffineLocalStorage;+window.writeAffineLocalStorage = writeAffineLocalStorage;diff --git a/tests/kit/package.json b/tests/kit/package.jsonindex cb1118ea30..dc5224e2f3 100644--- a/tests/kit/package.json+++ b/tests/kit/package.json@@ -6,7 +6,8 @@"exports": {"./electron": "./electron.ts","./playwright": "./playwright.ts",- "./utils/*": "./utils/*.ts"+ "./utils/*": "./utils/*.ts",+ "./e2e-enhance/*": "./e2e-enhance/*.ts"},"devDependencies": {"@node-rs/argon2": "^1.5.2",diff --git a/tests/kit/tsconfig.json b/tests/kit/tsconfig.jsonindex cdcdf6248d..5a45b77b64 100644--- a/tests/kit/tsconfig.json+++ b/tests/kit/tsconfig.json@@ -5,5 +5,5 @@"noEmit": false,"outDir": "lib"},- "include": ["./*.ts", "utils"]+ "include": ["./*.ts", "utils", "e2e-enhance"]}diff --git a/tsconfig.json b/tsconfig.jsonindex ba9012c701..4d12fb9831 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -172,6 +172,9 @@{"path": "./tests/affine-plugin"},+ {+ "path": "./tests/affine-migration"+ },{"path": "./tests/affine-legacy/0.7.0-canary.18"},diff --git a/yarn.lock b/yarn.lockindex 89404e711d..6ea545ba3e 100644--- a/yarn.lock+++ b/yarn.lock@@ -115,6 +115,20 @@ __metadata:languageName: unknownlinkType: soft+"@affine-test/affine-migration@workspace:tests/affine-migration":+ version: 0.0.0-use.local+ resolution: "@affine-test/affine-migration@workspace:tests/affine-migration"+ dependencies:+ "@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+ languageName: unknown+ linkType: soft+"@affine-test/affine-plugin@workspace:tests/affine-plugin":version: 0.0.0-use.localresolution: "@affine-test/affine-plugin@workspace:tests/affine-plugin"