mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08:00
test: migration test in real world (#2885)
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
static
|
||||
tests/fixtures/*.ydoc
|
||||
fixtures/*.ydoc
|
||||
test-results
|
||||
|
||||
87
tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts
Normal file
87
tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { 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('init page', 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,
|
||||
});
|
||||
|
||||
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/');
|
||||
await page.waitForSelector('v-line', {
|
||||
timeout: 10000,
|
||||
});
|
||||
});
|
||||
@@ -3,15 +3,23 @@
|
||||
"description": "AFFiNE 0.7.0-canary.18 static output",
|
||||
"scripts": {
|
||||
"unzip": "unzip affine-web -d static",
|
||||
"start": "yarn exec serve -s static -l 8081",
|
||||
"e2e": "playwright test"
|
||||
"start": "yarn exec serve -s static -l 8082",
|
||||
"e2e": "playwright test && vitest --run"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
"@affine-test/kit": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@blocksuite/block-std": "0.0.0-20230627165830-836e6fd1-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230627165830-836e6fd1-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230627165830-836e6fd1-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230627165830-836e6fd1-nightly",
|
||||
"@playwright/test": "=1.33.0",
|
||||
"express": "^4.18.2",
|
||||
"http-proxy-middleware": "^3.0.0-beta.1",
|
||||
"playwright": "=1.33.0",
|
||||
"serve": "^14.2.0"
|
||||
"serve": "^14.2.0",
|
||||
"vitest": "^0.32.2"
|
||||
},
|
||||
"version": "0.7.0-canary.23"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
} from '@playwright/test';
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
testDir: './tests',
|
||||
testDir: './e2e',
|
||||
fullyParallel: true,
|
||||
timeout: process.env.CI ? 50_000 : 30_000,
|
||||
use: {
|
||||
@@ -24,11 +24,15 @@ 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 start',
|
||||
port: 8081,
|
||||
command: 'yarn -T run start:web-static',
|
||||
port: 8080,
|
||||
timeout: 120 * 1000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
env: {
|
||||
COVERAGE: process.env.COVERAGE || 'false',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,24 +1,41 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { readdir, readFile } from 'node:fs/promises';
|
||||
import { extname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { test } from '@playwright/test';
|
||||
import { migrateToSubdoc } from '@affine/env/blocksuite';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { test } from 'vitest';
|
||||
|
||||
test('init page', async ({ page }) => {
|
||||
await page.goto('http://localhost:8081/');
|
||||
await page.waitForSelector('v-line', {
|
||||
timeout: 10000,
|
||||
});
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
const currentWorkspaceId: string = await page.evaluate(
|
||||
() => (globalThis.currentWorkspace as any).id
|
||||
);
|
||||
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.evaluate(() => {
|
||||
const workspace = (globalThis.currentWorkspace as any).blockSuiteWorkspace;
|
||||
workspace.exportYDoc();
|
||||
});
|
||||
|
||||
const download = await downloadPromise;
|
||||
const output = resolve(__dirname, 'fixtures', currentWorkspaceId + '.ydoc');
|
||||
await download.saveAs(output);
|
||||
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)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
13
tests/affine-legacy/0.7.0-canary.18/tsconfig.json
Normal file
13
tests/affine-legacy/0.7.0-canary.18/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["e2e"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
19
tests/affine-legacy/0.7.0-canary.18/tsconfig.node.json
Normal file
19
tests/affine-legacy/0.7.0-canary.18/tsconfig.node.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
7
tests/affine-legacy/0.7.0-canary.18/vitest.config.ts
Normal file
7
tests/affine-legacy/0.7.0-canary.18/vitest.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ['./tests/**/*.spec.ts'],
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user