mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
feat: migrate to database v3 (#3528)
This commit is contained in:
@@ -63,24 +63,6 @@ test('init page', async ({ page, context }) => {
|
||||
const locator = page.locator('v-line').nth(0);
|
||||
await locator.fill('hello');
|
||||
|
||||
const currentWorkspaceId: string = await page.evaluate(
|
||||
() => (globalThis as any).currentWorkspace.id
|
||||
);
|
||||
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.evaluate(() => {
|
||||
const workspace = (globalThis as any).currentWorkspace.blockSuiteWorkspace;
|
||||
workspace.exportYDoc();
|
||||
});
|
||||
|
||||
const download = await downloadPromise;
|
||||
const output = resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'fixtures',
|
||||
currentWorkspaceId + '.ydoc'
|
||||
);
|
||||
await download.saveAs(output);
|
||||
await switchToNext();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.goto('http://localhost:8081/');
|
||||
|
||||
@@ -10,16 +10,14 @@
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@blocksuite/block-std": "0.0.0-20230731152415-fdd3d9b0-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230731152415-fdd3d9b0-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230731152415-fdd3d9b0-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230731152415-fdd3d9b0-nightly",
|
||||
"@blocksuite/block-std": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@playwright/test": "^1.36.2",
|
||||
"express": "^4.18.2",
|
||||
"http-proxy-middleware": "^3.0.0-beta.1",
|
||||
"serve": "^14.2.0",
|
||||
"vitest": "^0.33.0"
|
||||
"serve": "^14.2.0"
|
||||
},
|
||||
"version": "0.8.0-canary.7"
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import { readdir, readFile } from 'node:fs/promises';
|
||||
import { extname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { migrateToSubdoc } from '@affine/env/blocksuite';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { test } from 'vitest';
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
test('basic', async () => {
|
||||
const oldDoc = new Workspace.Y.Doc();
|
||||
const directory = resolve(__dirname, '..', 'fixtures');
|
||||
const files = await readdir(directory);
|
||||
for (const file of files) {
|
||||
if (extname(file) !== '.ydoc') {
|
||||
continue;
|
||||
}
|
||||
const filePath = resolve(directory, file);
|
||||
const buffer = await readFile(filePath);
|
||||
Workspace.Y.applyUpdate(oldDoc, buffer);
|
||||
const newDoc = migrateToSubdoc(oldDoc);
|
||||
const workspace = new Workspace({
|
||||
id: 'test',
|
||||
});
|
||||
Workspace.Y.applyUpdate(
|
||||
workspace.doc,
|
||||
Workspace.Y.encodeStateAsUpdate(newDoc)
|
||||
);
|
||||
newDoc.subdocs.forEach(subdoc => {
|
||||
workspace.doc.subdocs.forEach(workspaceSubDoc => {
|
||||
if (subdoc.guid === workspaceSubDoc.guid) {
|
||||
Workspace.Y.applyUpdate(
|
||||
workspaceSubDoc,
|
||||
Workspace.Y.encodeStateAsUpdate(subdoc)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -4,10 +4,5 @@
|
||||
"esModuleInterop": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["e2e"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
]
|
||||
"include": ["e2e"]
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "Node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"noEmit": false,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["tests"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../packages/env"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ['./tests/**/*.spec.ts'],
|
||||
},
|
||||
});
|
||||
3
tests/affine-legacy/0.8.0-canary.7/.gitignore
vendored
Normal file
3
tests/affine-legacy/0.8.0-canary.7/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
static
|
||||
fixtures/*.ydoc
|
||||
test-results
|
||||
7
tests/affine-legacy/0.8.0-canary.7/README.md
Normal file
7
tests/affine-legacy/0.8.0-canary.7/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# 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`
|
||||
BIN
tests/affine-legacy/0.8.0-canary.7/affine-core.zip
Normal file
BIN
tests/affine-legacy/0.8.0-canary.7/affine-core.zip
Normal file
Binary file not shown.
83
tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts
Normal file
83
tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { expect, test } from '@playwright/test';
|
||||
import express from 'express';
|
||||
import { createProxyMiddleware } from 'http-proxy-middleware';
|
||||
|
||||
let app: express.Express;
|
||||
let server: ReturnType<express.Express['listen']>;
|
||||
|
||||
process.env.DEBUG = 'http-proxy-middleware*';
|
||||
|
||||
async function switchToNext() {
|
||||
// close previous express server
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.close(err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
app = express();
|
||||
app.use(
|
||||
createProxyMiddleware({
|
||||
target: 'http://localhost:8080',
|
||||
pathFilter: ['**'],
|
||||
changeOrigin: true,
|
||||
})
|
||||
);
|
||||
return new Promise<void>(resolve => {
|
||||
server = app.listen(8081, () => {
|
||||
console.log('proxy to next.js server');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test.beforeEach(() => {
|
||||
app = express();
|
||||
app.use(express.static(resolve(__dirname, '..', 'static')));
|
||||
server = app.listen(8081);
|
||||
});
|
||||
|
||||
test.afterEach(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
test('database migration', async ({ page, context }) => {
|
||||
{
|
||||
// make sure 8080 is ready
|
||||
const page = await context.newPage();
|
||||
await page.goto('http://localhost:8080/');
|
||||
await page.waitForSelector('v-line', {
|
||||
timeout: 10000,
|
||||
});
|
||||
await page.close();
|
||||
}
|
||||
await page.goto('http://localhost:8081/');
|
||||
await page.waitForSelector('v-line', {
|
||||
timeout: 10000,
|
||||
});
|
||||
await page.getByTestId('new-page-button').click();
|
||||
const title = page.locator('.affine-default-page-block-title');
|
||||
await title.type('hello');
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
await page.keyboard.press('/', { delay: 50 });
|
||||
await page.keyboard.press('d');
|
||||
await page.keyboard.press('a');
|
||||
await page.keyboard.press('t');
|
||||
await page.keyboard.press('a');
|
||||
await page.keyboard.press('b');
|
||||
await page.keyboard.press('a', { delay: 50 });
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
|
||||
await switchToNext();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.goto('http://localhost:8081/');
|
||||
await page.waitForSelector('v-line', {
|
||||
timeout: 10000,
|
||||
});
|
||||
expect(await page.locator('v-line').nth(0).textContent()).toBe('hello');
|
||||
expect(await page.locator('affine-database').isVisible()).toBe(true);
|
||||
});
|
||||
22
tests/affine-legacy/0.8.0-canary.7/package.json
Normal file
22
tests/affine-legacy/0.8.0-canary.7/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@affine-legacy/0.8.0-canary.7",
|
||||
"description": "AFFiNE 0.8.0-canary.7 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-20230802200139-381599c0-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230802200139-381599c0-nightly",
|
||||
"@playwright/test": "^1.36.2",
|
||||
"express": "^4.18.2",
|
||||
"http-proxy-middleware": "^3.0.0-beta.1",
|
||||
"serve": "^14.2.0"
|
||||
},
|
||||
"version": "0.8.0-canary.7"
|
||||
}
|
||||
45
tests/affine-legacy/0.8.0-canary.7/playwright.config.ts
Normal file
45
tests/affine-legacy/0.8.0-canary.7/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;
|
||||
8
tests/affine-legacy/0.8.0-canary.7/tsconfig.json
Normal file
8
tests/affine-legacy/0.8.0-canary.7/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["e2e"]
|
||||
}
|
||||
Reference in New Issue
Block a user