From 9eec8d0f1e6e1aa9d9986e6a1f0688ef3f7f21c8 Mon Sep 17 00:00:00 2001 From: Himself65 Date: Thu, 23 Mar 2023 17:15:40 -0500 Subject: [PATCH] refactor: test directory structure (#1677) --- apps/web/next.config.mjs | 2 +- packages/env/src/index.ts | 1 + playwright.config.ts | 2 +- scripts/vitest/next-config-mock.ts | 1 + tests/libs/load-page.ts | 13 +++--------- .../{ => parallels}/change-page-mode.spec.ts | 9 ++++---- tests/{ => parallels}/contact-us.spec.ts | 7 +++---- .../debug-page-broadcast.spec.ts | 2 +- tests/{ => parallels}/exception-page.spec.ts | 6 +----- .../{ => parallels}/invite-code-page.spec.ts | 6 +----- tests/{ => parallels}/layout.spec.ts | 8 +++---- .../local-first-avatar.spec.ts | 11 +++++----- .../local-first-delete-page.spec.ts | 11 +++++----- .../local-first-delete-workspace.spec.ts | 11 +++++----- .../local-first-export-page.spec.ts | 10 ++++----- .../local-first-favorite-page.spec.ts | 11 +++++----- .../local-first-favorites-items.spec.ts | 11 +++++----- .../local-first-new-page.spec.ts | 11 +++++----- .../local-first-openpage-newtab.spec.ts | 10 ++++----- .../local-first-restore-page.spec.ts | 13 ++++++------ .../local-first-show-delete-modal.spec.ts | 11 +++++----- .../local-first-trash-page.spec.ts | 10 ++++----- .../local-first-workspace-list.spec.ts | 12 ++++++----- .../local-first-workspace.spec.ts | 12 +++++------ tests/{ => parallels}/open-affine.spec.ts | 9 ++++---- tests/{ => parallels}/quick-search.spec.ts | 21 ++++++++++++++----- tests/{ => parallels}/shortcuts.spec.ts | 7 +++---- tests/{ => parallels}/subpage.spec.ts | 7 +++---- tests/{ => parallels}/theme.spec.ts | 10 +++------ tests/unit/compare-config.spec.ts | 21 +++++++++++++++++++ vitest.config.ts | 3 +++ 31 files changed, 149 insertions(+), 130 deletions(-) rename tests/{ => parallels}/change-page-mode.spec.ts (78%) rename tests/{ => parallels}/contact-us.spec.ts (83%) rename tests/{ => parallels}/debug-page-broadcast.spec.ts (94%) rename tests/{ => parallels}/exception-page.spec.ts (71%) rename tests/{ => parallels}/invite-code-page.spec.ts (72%) rename tests/{ => parallels}/layout.spec.ts (81%) rename tests/{ => parallels}/local-first-avatar.spec.ts (86%) rename tests/{ => parallels}/local-first-delete-page.spec.ts (85%) rename tests/{ => parallels}/local-first-delete-workspace.spec.ts (78%) rename tests/{ => parallels}/local-first-export-page.spec.ts (90%) rename tests/{ => parallels}/local-first-favorite-page.spec.ts (90%) rename tests/{ => parallels}/local-first-favorites-items.spec.ts (89%) rename tests/{ => parallels}/local-first-new-page.spec.ts (74%) rename tests/{ => parallels}/local-first-openpage-newtab.spec.ts (76%) rename tests/{ => parallels}/local-first-restore-page.spec.ts (82%) rename tests/{ => parallels}/local-first-show-delete-modal.spec.ts (87%) rename tests/{ => parallels}/local-first-trash-page.spec.ts (82%) rename tests/{ => parallels}/local-first-workspace-list.spec.ts (86%) rename tests/{ => parallels}/local-first-workspace.spec.ts (78%) rename tests/{ => parallels}/open-affine.spec.ts (84%) rename tests/{ => parallels}/quick-search.spec.ts (91%) rename tests/{ => parallels}/shortcuts.spec.ts (82%) rename tests/{ => parallels}/subpage.spec.ts (71%) rename tests/{ => parallels}/theme.spec.ts (87%) create mode 100644 tests/unit/compare-config.spec.ts diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs index 1dfd744225..5dcfcf13d1 100644 --- a/apps/web/next.config.mjs +++ b/apps/web/next.config.mjs @@ -75,7 +75,7 @@ const nextConfig = { '@affine/templates', ], publicRuntimeConfig: { - PROJECT_NAME: process.env.npm_package_name, + PROJECT_NAME: process.env.npm_package_name ?? 'AFFiNE', BUILD_DATE: new Date().toISOString(), gitVersion: getGitVersion(), hash: getCommitHash(), diff --git a/packages/env/src/index.ts b/packages/env/src/index.ts index a34066151e..62cc584b26 100644 --- a/packages/env/src/index.ts +++ b/packages/env/src/index.ts @@ -110,6 +110,7 @@ export const publicRuntimeConfigSchema = z.object({ enableIndexedDBProvider: z.boolean(), enableBroadCastChannelProvider: z.boolean(), prefetchWorkspace: z.boolean(), + enableDebugPage: z.boolean(), // expose internal api to globalThis, **development only** exposeInternal: z.boolean(), enableSubpage: z.boolean(), diff --git a/playwright.config.ts b/playwright.config.ts index 6a5605c62d..c7d1ac0d43 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -16,7 +16,7 @@ import type { * See https://playwright.dev/docs/test-configuration. */ const config: PlaywrightTestConfig = { - testDir: './tests', + testDir: './tests/parallels', fullyParallel: true, timeout: process.env.CI ? 50_000 : 30_000, use: { diff --git a/scripts/vitest/next-config-mock.ts b/scripts/vitest/next-config-mock.ts index a1403bb6bf..4e809a6ace 100644 --- a/scripts/vitest/next-config-mock.ts +++ b/scripts/vitest/next-config-mock.ts @@ -9,6 +9,7 @@ export default function getConfig() { serverAPI: 'http://localhost:3000/api', enableBroadCastChannelProvider: true, enableIndexedDBProvider: true, + enableDebugPage: true, prefetchWorkspace: false, exposeInternal: true, enableSubpage: true, diff --git a/tests/libs/load-page.ts b/tests/libs/load-page.ts index 2765042728..b999d80156 100644 --- a/tests/libs/load-page.ts +++ b/tests/libs/load-page.ts @@ -1,13 +1,6 @@ import type { Page } from '@playwright/test'; -import { test } from '@playwright/test'; -interface IType { - page: Page; -} -export function loadPage() { - test.beforeEach(async ({ page }: IType) => { - await page.goto('http://localhost:8080'); - // waiting for page loading end - await page.waitForSelector('#__next'); - }); +export async function openHomePage(page: Page) { + await page.goto('http://localhost:8080'); + await page.waitForSelector('#__next'); } diff --git a/tests/change-page-mode.spec.ts b/tests/parallels/change-page-mode.spec.ts similarity index 78% rename from tests/change-page-mode.spec.ts rename to tests/parallels/change-page-mode.spec.ts index 1a1295390b..2a129ee533 100644 --- a/tests/change-page-mode.spec.ts +++ b/tests/parallels/change-page-mode.spec.ts @@ -1,12 +1,12 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { clickPageMoreActions } from './libs/page-logic'; -import { test } from './libs/playwright'; -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { clickPageMoreActions } from '../libs/page-logic'; +import { test } from '../libs/playwright'; test.describe('Change page mode(Page or Edgeless)', () => { test('Switch to edgeless by switch edgeless item', async ({ page }) => { + await openHomePage(page); const btn = await page.getByTestId('switch-edgeless-mode-button'); await btn.click(); @@ -15,6 +15,7 @@ test.describe('Change page mode(Page or Edgeless)', () => { }); test('Convert to edgeless by editor header items', async ({ page }) => { + await openHomePage(page); await clickPageMoreActions(page); const menusEdgelessItem = page.getByTestId('editor-option-menu-edgeless'); await menusEdgelessItem.click({ delay: 100 }); diff --git a/tests/contact-us.spec.ts b/tests/parallels/contact-us.spec.ts similarity index 83% rename from tests/contact-us.spec.ts rename to tests/parallels/contact-us.spec.ts index 9ba3e2edf1..1b3d0f623f 100644 --- a/tests/contact-us.spec.ts +++ b/tests/parallels/contact-us.spec.ts @@ -1,12 +1,11 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; test.describe('Open contact us', () => { test('Click right-bottom corner contact icon', async ({ page }) => { + await openHomePage(page); await page.locator('[data-testid=help-island]').click(); const rightBottomContactUs = page.locator( '[data-testid=right-bottom-contact-us-icon]' diff --git a/tests/debug-page-broadcast.spec.ts b/tests/parallels/debug-page-broadcast.spec.ts similarity index 94% rename from tests/debug-page-broadcast.spec.ts rename to tests/parallels/debug-page-broadcast.spec.ts index a4cbc5f975..bcf3232e41 100644 --- a/tests/debug-page-broadcast.spec.ts +++ b/tests/parallels/debug-page-broadcast.spec.ts @@ -1,6 +1,6 @@ import { expect } from '@playwright/test'; -import { test } from './libs/playwright'; +import { test } from '../libs/playwright'; test.describe('Debug page broadcast', () => { test('should broadcast a message to all debug pages', async ({ diff --git a/tests/exception-page.spec.ts b/tests/parallels/exception-page.spec.ts similarity index 71% rename from tests/exception-page.spec.ts rename to tests/parallels/exception-page.spec.ts index 3fac866667..e7f51b515f 100644 --- a/tests/exception-page.spec.ts +++ b/tests/parallels/exception-page.spec.ts @@ -1,11 +1,7 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; +import { test } from '../libs/playwright'; -loadPage(); - -// ps aux | grep 8080 test.describe('exception page', () => { test('visit 404 page', async ({ page }) => { await page.goto('http://localhost:8080/404'); diff --git a/tests/invite-code-page.spec.ts b/tests/parallels/invite-code-page.spec.ts similarity index 72% rename from tests/invite-code-page.spec.ts rename to tests/parallels/invite-code-page.spec.ts index 8d69889aaf..18499165af 100644 --- a/tests/invite-code-page.spec.ts +++ b/tests/parallels/invite-code-page.spec.ts @@ -1,11 +1,7 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; +import { test } from '../libs/playwright'; -loadPage(); - -// ps aux | grep 8080 test.describe('invite code page', () => { test('the link has expired', async ({ page }) => { await page.goto('http://localhost:8080//invite/abc'); diff --git a/tests/layout.spec.ts b/tests/parallels/layout.spec.ts similarity index 81% rename from tests/layout.spec.ts rename to tests/parallels/layout.spec.ts index d8984b0bac..59cc4ceca6 100644 --- a/tests/layout.spec.ts +++ b/tests/parallels/layout.spec.ts @@ -1,18 +1,18 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; test.describe('Layout ui', () => { test('Collapse Sidebar', async ({ page }) => { + await openHomePage(page); await page.getByTestId('sliderBar-arrowButton-collapse').click(); const sliderBarArea = page.getByTestId('sliderBar'); await expect(sliderBarArea).not.toBeVisible(); }); test('Expand Sidebar', async ({ page }) => { + await openHomePage(page); await page.getByTestId('sliderBar-arrowButton-collapse').click(); const sliderBarArea = page.getByTestId('sliderBar'); await expect(sliderBarArea).not.toBeVisible(); diff --git a/tests/local-first-avatar.spec.ts b/tests/parallels/local-first-avatar.spec.ts similarity index 86% rename from tests/local-first-avatar.spec.ts rename to tests/parallels/local-first-avatar.spec.ts index 90946a90e0..d30e72803a 100644 --- a/tests/local-first-avatar.spec.ts +++ b/tests/parallels/local-first-avatar.spec.ts @@ -1,14 +1,13 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first create page', () => { test('should create a page with a local first avatar', async ({ page }) => { + await openHomePage(page); await newPage(page); await page.getByTestId('workspace-name').click(); await page.getByTestId('new-workspace').click({ delay: 50 }); diff --git a/tests/local-first-delete-page.spec.ts b/tests/parallels/local-first-delete-page.spec.ts similarity index 85% rename from tests/local-first-delete-page.spec.ts rename to tests/parallels/local-first-delete-page.spec.ts index 08d461bbe1..9ce181271d 100644 --- a/tests/local-first-delete-page.spec.ts +++ b/tests/parallels/local-first-delete-page.spec.ts @@ -1,16 +1,15 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { getBlockSuiteEditorTitle, newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { getBlockSuiteEditorTitle, newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first delete page', () => { test('New a page , then delete it in all pages, permanently delete it', async ({ page, }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to restore'); diff --git a/tests/local-first-delete-workspace.spec.ts b/tests/parallels/local-first-delete-workspace.spec.ts similarity index 78% rename from tests/local-first-delete-workspace.spec.ts rename to tests/parallels/local-first-delete-workspace.spec.ts index aa6dc47630..a17e107b42 100644 --- a/tests/local-first-delete-workspace.spec.ts +++ b/tests/parallels/local-first-delete-workspace.spec.ts @@ -1,16 +1,15 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; -import { clickSideBarSettingButton } from './libs/sidebar'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; +import { clickSideBarSettingButton } from '../libs/sidebar'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first delete workspace', () => { test('New a workspace , then delete it in all workspaces, permanently delete it', async ({ page, }) => { + await openHomePage(page); await clickSideBarSettingButton(page); await page.getByTestId('delete-workspace-button').click(); const workspaceNameDom = await page.getByTestId('workspace-name'); diff --git a/tests/local-first-export-page.spec.ts b/tests/parallels/local-first-export-page.spec.ts similarity index 90% rename from tests/local-first-export-page.spec.ts rename to tests/parallels/local-first-export-page.spec.ts index a2d2fe34a8..6b4395c133 100644 --- a/tests/local-first-export-page.spec.ts +++ b/tests/parallels/local-first-export-page.spec.ts @@ -1,17 +1,17 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; +import { openHomePage } from '../libs/load-page'; import { clickPageMoreActions, getBlockSuiteEditorTitle, newPage, -} from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +} from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first export page', () => { test.skip('New a page ,then open it and export html', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await page diff --git a/tests/local-first-favorite-page.spec.ts b/tests/parallels/local-first-favorite-page.spec.ts similarity index 90% rename from tests/local-first-favorite-page.spec.ts rename to tests/parallels/local-first-favorite-page.spec.ts index 867affe63a..415c7f601d 100644 --- a/tests/local-first-favorite-page.spec.ts +++ b/tests/parallels/local-first-favorite-page.spec.ts @@ -1,17 +1,17 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; +import { openHomePage } from '../libs/load-page'; import { clickPageMoreActions, getBlockSuiteEditorTitle, newPage, -} from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +} from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first favorite and cancel favorite page', () => { test('New a page and open it ,then favorite it', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite'); @@ -28,6 +28,7 @@ test.describe('Local first favorite and cancel favorite page', () => { await assertCurrentWorkspaceFlavour('local', page); }); test('Cancel favorite', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite'); diff --git a/tests/local-first-favorites-items.spec.ts b/tests/parallels/local-first-favorites-items.spec.ts similarity index 89% rename from tests/local-first-favorites-items.spec.ts rename to tests/parallels/local-first-favorites-items.spec.ts index 126aa46514..b1f3827061 100644 --- a/tests/local-first-favorites-items.spec.ts +++ b/tests/parallels/local-first-favorites-items.spec.ts @@ -1,17 +1,17 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; +import { openHomePage } from '../libs/load-page'; import { clickPageMoreActions, getBlockSuiteEditorTitle, newPage, -} from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +} from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first favorite items ui', () => { test('Show favorite items in sidebar', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite'); @@ -35,6 +35,7 @@ test.describe('Local first favorite items ui', () => { }); test('Show favorite items in favorite list', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite'); diff --git a/tests/local-first-new-page.spec.ts b/tests/parallels/local-first-new-page.spec.ts similarity index 74% rename from tests/local-first-new-page.spec.ts rename to tests/parallels/local-first-new-page.spec.ts index e086ad5c57..d60d541bb3 100644 --- a/tests/local-first-new-page.spec.ts +++ b/tests/parallels/local-first-new-page.spec.ts @@ -1,13 +1,13 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { getBlockSuiteEditorTitle, newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { getBlockSuiteEditorTitle, newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('local first new page', () => { test('click btn new page', async ({ page }) => { + await openHomePage(page); const originPageId = page.url().split('/').reverse()[0]; await newPage(page); const newPageId = page.url().split('/').reverse()[0]; @@ -16,6 +16,7 @@ test.describe('local first new page', () => { }); test('click btn bew page and find it in all pages', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page'); diff --git a/tests/local-first-openpage-newtab.spec.ts b/tests/parallels/local-first-openpage-newtab.spec.ts similarity index 76% rename from tests/local-first-openpage-newtab.spec.ts rename to tests/parallels/local-first-openpage-newtab.spec.ts index 425d132cf7..0299e1fb8f 100644 --- a/tests/local-first-openpage-newtab.spec.ts +++ b/tests/parallels/local-first-openpage-newtab.spec.ts @@ -1,13 +1,13 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { getBlockSuiteEditorTitle, newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { getBlockSuiteEditorTitle, newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('local first new page', () => { test('click btn bew page and open in tab', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page'); diff --git a/tests/local-first-restore-page.spec.ts b/tests/parallels/local-first-restore-page.spec.ts similarity index 82% rename from tests/local-first-restore-page.spec.ts rename to tests/parallels/local-first-restore-page.spec.ts index f337b81cfa..ecb76a9f5a 100644 --- a/tests/local-first-restore-page.spec.ts +++ b/tests/parallels/local-first-restore-page.spec.ts @@ -1,15 +1,15 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { getBlockSuiteEditorTitle, newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { getBlockSuiteEditorTitle, newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first delete page', () => { test('New a page , then delete it in all pages, restore it', async ({ page, }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to restore'); @@ -33,7 +33,8 @@ test.describe('Local first delete page', () => { await page.getByRole('button', { name: 'Delete' }).click(); await page.getByRole('link', { name: 'Trash' }).click(); - const trashPage = await page.url(); + await page.waitForTimeout(50); + const trashPage = page.url(); // restore it await page .getByTestId('more-actions-' + newPageId) diff --git a/tests/local-first-show-delete-modal.spec.ts b/tests/parallels/local-first-show-delete-modal.spec.ts similarity index 87% rename from tests/local-first-show-delete-modal.spec.ts rename to tests/parallels/local-first-show-delete-modal.spec.ts index edd5b0eeb3..d9274c31d5 100644 --- a/tests/local-first-show-delete-modal.spec.ts +++ b/tests/parallels/local-first-show-delete-modal.spec.ts @@ -1,17 +1,17 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; +import { openHomePage } from '../libs/load-page'; import { clickPageMoreActions, getBlockSuiteEditorTitle, newPage, -} from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +} from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first delete page', () => { test('New a page ,then open it and show delete modal', async ({ page }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to delete'); @@ -33,6 +33,7 @@ test.describe('Local first delete page', () => { test('New a page ,then go to all pages and show delete modal', async ({ page, }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to delete'); diff --git a/tests/local-first-trash-page.spec.ts b/tests/parallels/local-first-trash-page.spec.ts similarity index 82% rename from tests/local-first-trash-page.spec.ts rename to tests/parallels/local-first-trash-page.spec.ts index b347d0ab1e..6540373c2b 100644 --- a/tests/local-first-trash-page.spec.ts +++ b/tests/parallels/local-first-trash-page.spec.ts @@ -1,15 +1,15 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { getBlockSuiteEditorTitle, newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { getBlockSuiteEditorTitle, newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first trash page', () => { test('New a page , then delete it in all pages, finally find it in trash', async ({ page, }) => { + await openHomePage(page); await newPage(page); await getBlockSuiteEditorTitle(page).click(); await getBlockSuiteEditorTitle(page).fill('this is a new page to delete'); diff --git a/tests/local-first-workspace-list.spec.ts b/tests/parallels/local-first-workspace-list.spec.ts similarity index 86% rename from tests/local-first-workspace-list.spec.ts rename to tests/parallels/local-first-workspace-list.spec.ts index abac9a4d63..076836f738 100644 --- a/tests/local-first-workspace-list.spec.ts +++ b/tests/parallels/local-first-workspace-list.spec.ts @@ -1,13 +1,13 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; -import { clickSideBarAllPageButton } from './libs/sidebar'; -import { createWorkspace } from './libs/workspace'; -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; +import { clickSideBarAllPageButton } from '../libs/sidebar'; +import { createWorkspace } from '../libs/workspace'; test.describe('Local first workspace list', () => { test('just one item in the workspace list at first', async ({ page }) => { + await openHomePage(page); const workspaceName = page.getByTestId('workspace-name'); await workspaceName.click(); expect( @@ -19,6 +19,7 @@ test.describe('Local first workspace list', () => { }); test('create one workspace in the workspace list', async ({ page }) => { + await openHomePage(page); const newWorkspaceNameStr = 'New Workspace'; await createWorkspace({ name: newWorkspaceNameStr }, page); @@ -46,6 +47,7 @@ test.describe('Local first workspace list', () => { }); test('create multi workspace in the workspace list', async ({ page }) => { + await openHomePage(page); await createWorkspace({ name: 'New Workspace 2' }, page); await createWorkspace({ name: 'New Workspace 3' }, page); diff --git a/tests/local-first-workspace.spec.ts b/tests/parallels/local-first-workspace.spec.ts similarity index 78% rename from tests/local-first-workspace.spec.ts rename to tests/parallels/local-first-workspace.spec.ts index 680a0286dc..1fd37c5f78 100644 --- a/tests/local-first-workspace.spec.ts +++ b/tests/parallels/local-first-workspace.spec.ts @@ -1,14 +1,13 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; -import { clickSideBarCurrentWorkspaceBanner } from './libs/sidebar'; -import { assertCurrentWorkspaceFlavour } from './libs/workspace'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; +import { clickSideBarCurrentWorkspaceBanner } from '../libs/sidebar'; +import { assertCurrentWorkspaceFlavour } from '../libs/workspace'; test.describe('Local first default workspace', () => { test('preset workspace name', async ({ page }) => { + await openHomePage(page); const workspaceName = page.getByTestId('workspace-name'); expect(await workspaceName.textContent()).toBe('Demo Workspace'); await assertCurrentWorkspaceFlavour('local', page); @@ -23,6 +22,7 @@ test.describe('Local first default workspace', () => { }); test.describe('Language switch', () => { test('Open language switch menu', async ({ page }) => { + await openHomePage(page); await clickSideBarCurrentWorkspaceBanner(page); const languageMenuButton = page.getByTestId('language-menu-button'); await expect(languageMenuButton).toBeVisible(); diff --git a/tests/open-affine.spec.ts b/tests/parallels/open-affine.spec.ts similarity index 84% rename from tests/open-affine.spec.ts rename to tests/parallels/open-affine.spec.ts index bda671f131..37aa5f163d 100644 --- a/tests/open-affine.spec.ts +++ b/tests/parallels/open-affine.spec.ts @@ -1,13 +1,12 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; -import { createWorkspace } from './libs/workspace'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; +import { createWorkspace } from '../libs/workspace'; test.describe('Open AFFiNE', () => { test('Open last workspace when back to affine', async ({ page }) => { + await openHomePage(page); await createWorkspace({ name: 'New Workspace 2' }, page); // FIXME: can not get when the new workspace is surely created, hack a timeout to wait // waiting for page loading end diff --git a/tests/quick-search.spec.ts b/tests/parallels/quick-search.spec.ts similarity index 91% rename from tests/quick-search.spec.ts rename to tests/parallels/quick-search.spec.ts index 3b4fee50ae..77d80f9ad9 100644 --- a/tests/quick-search.spec.ts +++ b/tests/parallels/quick-search.spec.ts @@ -1,10 +1,9 @@ import { expect, type Page } from '@playwright/test'; -import { withCtrlOrMeta } from './libs/keyboard'; -import { loadPage } from './libs/load-page'; -import { newPage } from './libs/page-logic'; -import { test } from './libs/playwright'; -loadPage(); +import { withCtrlOrMeta } from '../libs/keyboard'; +import { openHomePage } from '../libs/load-page'; +import { newPage } from '../libs/page-logic'; +import { test } from '../libs/playwright'; const openQuickSearchByShortcut = async (page: Page) => await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 })); @@ -32,6 +31,7 @@ async function titleIsFocused(page: Page) { test.describe('Open quick search', () => { test('Click slider bar button', async ({ page }) => { + await openHomePage(page); await newPage(page); const quickSearchButton = page.locator( '[data-testid=slider-bar-quick-search-button]' @@ -42,6 +42,7 @@ test.describe('Open quick search', () => { }); test('Click arrowDown icon after title', async ({ page }) => { + await openHomePage(page); await newPage(page); const quickSearchButton = page.locator( '[data-testid=slider-bar-quick-search-button]' @@ -52,6 +53,7 @@ test.describe('Open quick search', () => { }); test('Press the shortcut key cmd+k', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); const quickSearch = page.locator('[data-testid=quickSearch]'); @@ -61,6 +63,7 @@ test.describe('Open quick search', () => { test.describe('Add new page in quick search', () => { test('Create a new page without keyword', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); const addNewPage = page.locator('[data-testid=quick-search-add-new-page]'); @@ -70,6 +73,7 @@ test.describe('Add new page in quick search', () => { }); test('Create a new page with keyword', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); await page.keyboard.insertText('test123456'); @@ -82,6 +86,7 @@ test.describe('Add new page in quick search', () => { test.describe('Search and select', () => { test('Enter a keyword to search for', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); await page.keyboard.insertText('test123456'); @@ -89,6 +94,7 @@ test.describe('Search and select', () => { expect(actual).toBe('test123456'); }); test('Create a new page and search this page', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); await page.keyboard.insertText('test123456'); @@ -119,6 +125,7 @@ test.describe('Disable search on 404 page', () => { }); test.describe('Open quick search on the published page', () => { test('Open quick search on local page', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); const publishedSearchResults = page.locator('[publishedSearchResults]'); @@ -128,6 +135,7 @@ test.describe('Open quick search on the published page', () => { test.describe('Focus event for quick search', () => { test('Autofocus input after opening quick search', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); const locator = page.locator('[cmdk-input]'); @@ -135,6 +143,7 @@ test.describe('Focus event for quick search', () => { await expect(locator).toBeFocused(); }); test('Autofocus input after select', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); await page.keyboard.press('ArrowUp'); @@ -143,6 +152,7 @@ test.describe('Focus event for quick search', () => { await expect(locator).toBeFocused(); }); test('Focus title after creating a new page', async ({ page }) => { + await openHomePage(page); await newPage(page); await openQuickSearchByShortcut(page); const addNewPage = page.locator('[data-testid=quick-search-add-new-page]'); @@ -154,6 +164,7 @@ test.describe('Novice guidance for quick search', () => { test('When opening the website for the first time, the first folding sidebar will appear novice guide', async ({ page, }) => { + await openHomePage(page); const quickSearchTips = page.locator('[data-testid=quick-search-tips]'); await expect(quickSearchTips).not.toBeVisible(); await page.getByTestId('sliderBar-arrowButton-collapse').click(); diff --git a/tests/shortcuts.spec.ts b/tests/parallels/shortcuts.spec.ts similarity index 82% rename from tests/shortcuts.spec.ts rename to tests/parallels/shortcuts.spec.ts index d9576789f1..55b5ee54e9 100644 --- a/tests/shortcuts.spec.ts +++ b/tests/parallels/shortcuts.spec.ts @@ -1,12 +1,11 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; test.describe('Shortcuts Modal', () => { test('Open shortcuts modal', async ({ page }) => { + await openHomePage(page); await page.locator('[data-testid=help-island]').click(); const shortcutsIcon = page.locator('[data-testid=shortcuts-icon]'); diff --git a/tests/subpage.spec.ts b/tests/parallels/subpage.spec.ts similarity index 71% rename from tests/subpage.spec.ts rename to tests/parallels/subpage.spec.ts index e30e6d18a8..2522351251 100644 --- a/tests/subpage.spec.ts +++ b/tests/parallels/subpage.spec.ts @@ -1,12 +1,11 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; test.describe('subpage', () => { test('Create subpage', async ({ page }) => { + await openHomePage(page); await page.getByTestId('sliderBar-arrowButton-collapse').click(); const sliderBarArea = page.getByTestId('sliderBar'); await expect(sliderBarArea).not.toBeVisible(); diff --git a/tests/theme.spec.ts b/tests/parallels/theme.spec.ts similarity index 87% rename from tests/theme.spec.ts rename to tests/parallels/theme.spec.ts index 554efff3b6..d8ad74b88c 100644 --- a/tests/theme.spec.ts +++ b/tests/parallels/theme.spec.ts @@ -1,9 +1,7 @@ import { expect } from '@playwright/test'; -import { loadPage } from './libs/load-page'; -import { test } from './libs/playwright'; - -loadPage(); +import { openHomePage } from '../libs/load-page'; +import { test } from '../libs/playwright'; test.describe('Change Theme', () => { // default could be anything according to the system @@ -12,9 +10,7 @@ test.describe('Change Theme', () => { colorScheme: 'light', }); const page = await context.newPage(); - await page.goto('http://localhost:8080'); - // waiting for page loading end - await page.waitForSelector('#__next'); + await openHomePage(page); await page.waitForSelector('html'); const root = page.locator('html'); const themeMode = await root.evaluate(element => diff --git a/tests/unit/compare-config.spec.ts b/tests/unit/compare-config.spec.ts new file mode 100644 index 0000000000..da3adcbea8 --- /dev/null +++ b/tests/unit/compare-config.spec.ts @@ -0,0 +1,21 @@ +import { expect, test } from 'vitest'; + +test('compare config', async () => { + const { default: nextConfigMock } = await import( + '../../scripts/vitest/next-config-mock' + ); + const mockConfig = nextConfigMock().publicRuntimeConfig; + const { default: nextConfig } = await import( + '../../apps/web/next.config.mjs' + ); + const config = nextConfig.publicRuntimeConfig; + + Object.keys(config).forEach(key => { + expect(key in mockConfig, `${key} should be in the mockConfig`).toBe(true); + expect(typeof config[key], `${key}`).toBe(typeof mockConfig[key]); + }); + Object.keys(mockConfig).forEach(key => { + expect(key in config, `${key} should be in the config`).toBe(true); + expect(typeof config[key], `${key}`).toBe(typeof mockConfig[key]); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts index 3df280f3c3..21ac44591c 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -15,8 +15,11 @@ export default defineConfig({ test: { include: [ 'packages/**/*.spec.ts', + 'packages/**/*.spec.tsx', 'apps/web/**/*.spec.ts', 'apps/web/**/*.spec.tsx', + 'tests/unit/**/*.spec.ts', + 'tests/unit/**/*.spec.tsx', ], testTimeout: 5000, coverage: {