From 075ad83a2643dac931508f963749bb244abff827 Mon Sep 17 00:00:00 2001 From: Per-Kristian Nordnes Date: Fri, 27 Oct 2023 00:35:58 +0200 Subject: [PATCH] ci: move pte e2e collaborationtests out in own workflow test(portable-text-editor): adjust timings ci: remove playwright from unit tests test(portable-text-editor): prefix ignore path with rootDir test(portable-text-editor): only include server setup when in e2e mode test(portable-text-editor): move e2e tests to other folder --- .github/workflows/e2e-pte.yml | 63 +++++++++++++++++++ .github/workflows/test.yml | 38 ----------- package.json | 5 +- .../{test => e2e-tests}/__tests__/.eslintrc | 0 .../__tests__/pasting.collaborative.test.ts | 2 +- .../selectionAdjustment.collaborative.test.ts | 2 +- .../__tests__/undoRedo.collborative.test.ts | 2 +- .../writingTogether.collaborative.test.ts | 2 +- .../{test => e2e-tests}/schema.ts | 0 .../{test => e2e-tests}/serve.ts | 0 .../{test => e2e-tests}/setup/afterEnv.ts | 0 .../setup/collaborative.jest.env.ts | 0 .../{test => e2e-tests}/setup/globalSetup.ts | 0 .../setup/globalTeardown.ts | 0 .../{test => e2e-tests}/setup/globals.jest.ts | 0 .../{test => e2e-tests}/tsconfig.json | 0 .../{test => e2e-tests}/web-server/app.tsx | 0 .../web-server/components/Editor.tsx | 0 .../web-server/components/Value.tsx | 0 .../{test => e2e-tests}/web-server/entry.tsx | 0 .../{test => e2e-tests}/web-server/index.html | 0 .../web-server/keyGenerator.ts | 0 .../web-server/vite.config.js | 0 .../{test => e2e-tests}/ws-server/index.ts | 0 .../portable-text-editor/jest.config.cjs | 19 +++++- .../@sanity/portable-text-editor/package.json | 1 + .../src/editor/components/Synchronizer.tsx | 2 +- 27 files changed, 89 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/e2e-pte.yml rename packages/@sanity/portable-text-editor/{test => e2e-tests}/__tests__/.eslintrc (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/__tests__/pasting.collaborative.test.ts (98%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/__tests__/selectionAdjustment.collaborative.test.ts (99%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/__tests__/undoRedo.collborative.test.ts (99%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/__tests__/writingTogether.collaborative.test.ts (99%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/schema.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/serve.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/setup/afterEnv.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/setup/collaborative.jest.env.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/setup/globalSetup.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/setup/globalTeardown.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/setup/globals.jest.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/tsconfig.json (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/app.tsx (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/components/Editor.tsx (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/components/Value.tsx (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/entry.tsx (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/index.html (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/keyGenerator.ts (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/web-server/vite.config.js (100%) rename packages/@sanity/portable-text-editor/{test => e2e-tests}/ws-server/index.ts (100%) diff --git a/.github/workflows/e2e-pte.yml b/.github/workflows/e2e-pte.yml new file mode 100644 index 00000000000..c2611de8fe4 --- /dev/null +++ b/.github/workflows/e2e-pte.yml @@ -0,0 +1,63 @@ +name: End-to-End PTE collaboration tests +on: + # Build on pushes branches that have a PR (including drafts) + pull_request: + # Build on commits pushed to branches without a PR if it's in the allowlist + push: + branches: [next] +jobs: + playwright-test: + timeout-minutes: 30 + runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + strategy: + fail-fast: false + matrix: + project: [chromium] + # Add more shards here if needed + shardIndex: [1, 2] + shardTotal: [2] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-modules-${{ env.cache-name }}- + ${{ runner.os }}-modules- + ${{ runner.os }}- + + - name: Install project dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: yarn install --frozen-lockfile + + - name: Store Playwright's Version + run: | + PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //') + echo "Playwright's Version: $PLAYWRIGHT_VERSION" + echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV + + - name: Cache Playwright Browsers for Playwright's Version + id: cache-playwright-browsers + uses: actions/cache@v3 + with: + path: ~/.cache/ms-playwright + key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} + + - name: Install Playwright Browsers + if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' + run: npx playwright install --with-deps + + - name: Run end-to-end tests + run: cd packages/@sanity/portable-text-editor && yarn test:e2e --silent --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 990aa2ef775..6f0b01bb763 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,27 +63,6 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - - name: Install project dependencies - if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: yarn install --frozen-lockfile - - - name: Store Playwright's Version - run: | - PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //') - echo "Playwright's Version: $PLAYWRIGHT_VERSION" - echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV - - - name: Cache Playwright Browsers for Playwright's Version - id: cache-playwright-browsers - uses: actions/cache@v3 - with: - path: ~/.cache/ms-playwright - key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} - - - name: Install Playwright Browsers - if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' - run: npx playwright install --with-deps - - name: Build CLI run: yarn build:cli # Needed for CLI tests @@ -140,23 +119,6 @@ jobs: if: steps.cache-node-modules.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile - - name: Store Playwright's Version - run: | - PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //') - echo "Playwright's Version: $PLAYWRIGHT_VERSION" - echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV - - - name: Cache Playwright Browsers for Playwright's Version - id: cache-playwright-browsers - uses: actions/cache@v3 - with: - path: ~/.cache/ms-playwright - key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} - - - name: Install Playwright Browsers - if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' - run: npx playwright install --with-deps - - name: Test id: test run: | diff --git a/package.json b/package.json index 21bae3b54c0..649889b1894 100644 --- a/package.json +++ b/package.json @@ -150,5 +150,8 @@ "node-notifier": "^10.0.0" }, "packageManager": "yarn@1.22.19", - "isSanityMonorepo": true + "isSanityMonorepo": true, + "dependencies": { + "yarn": "^1.22.19" + } } diff --git a/packages/@sanity/portable-text-editor/test/__tests__/.eslintrc b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/.eslintrc similarity index 100% rename from packages/@sanity/portable-text-editor/test/__tests__/.eslintrc rename to packages/@sanity/portable-text-editor/e2e-tests/__tests__/.eslintrc diff --git a/packages/@sanity/portable-text-editor/test/__tests__/pasting.collaborative.test.ts b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/pasting.collaborative.test.ts similarity index 98% rename from packages/@sanity/portable-text-editor/test/__tests__/pasting.collaborative.test.ts rename to packages/@sanity/portable-text-editor/e2e-tests/__tests__/pasting.collaborative.test.ts index 75abba26133..55b243998ca 100644 --- a/packages/@sanity/portable-text-editor/test/__tests__/pasting.collaborative.test.ts +++ b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/pasting.collaborative.test.ts @@ -1,4 +1,4 @@ -/** @jest-environment ./test/setup/collaborative.jest.env.ts */ +/** @jest-environment ./e2e-tests/setup/collaborative.jest.env.ts */ import os from 'os' import '../setup/globals.jest' import {noop} from 'lodash' diff --git a/packages/@sanity/portable-text-editor/test/__tests__/selectionAdjustment.collaborative.test.ts b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/selectionAdjustment.collaborative.test.ts similarity index 99% rename from packages/@sanity/portable-text-editor/test/__tests__/selectionAdjustment.collaborative.test.ts rename to packages/@sanity/portable-text-editor/e2e-tests/__tests__/selectionAdjustment.collaborative.test.ts index e2bdd77f6b0..584ae360422 100644 --- a/packages/@sanity/portable-text-editor/test/__tests__/selectionAdjustment.collaborative.test.ts +++ b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/selectionAdjustment.collaborative.test.ts @@ -1,4 +1,4 @@ -/** @jest-environment ./test/setup/collaborative.jest.env.ts */ +/** @jest-environment ./e2e-tests/setup/collaborative.jest.env.ts */ import '../setup/globals.jest' diff --git a/packages/@sanity/portable-text-editor/test/__tests__/undoRedo.collborative.test.ts b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/undoRedo.collborative.test.ts similarity index 99% rename from packages/@sanity/portable-text-editor/test/__tests__/undoRedo.collborative.test.ts rename to packages/@sanity/portable-text-editor/e2e-tests/__tests__/undoRedo.collborative.test.ts index ef5a07010b3..2eff838e6ab 100644 --- a/packages/@sanity/portable-text-editor/test/__tests__/undoRedo.collborative.test.ts +++ b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/undoRedo.collborative.test.ts @@ -1,4 +1,4 @@ -/** @jest-environment ./test/setup/collaborative.jest.env.ts */ +/** @jest-environment ./e2e-tests/setup/collaborative.jest.env.ts */ import {toPlainText} from '@portabletext/toolkit' import '../setup/globals.jest' import type {PortableTextBlock} from '@sanity/types' diff --git a/packages/@sanity/portable-text-editor/test/__tests__/writingTogether.collaborative.test.ts b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/writingTogether.collaborative.test.ts similarity index 99% rename from packages/@sanity/portable-text-editor/test/__tests__/writingTogether.collaborative.test.ts rename to packages/@sanity/portable-text-editor/e2e-tests/__tests__/writingTogether.collaborative.test.ts index 18a3a163c14..733a4a6e8a4 100644 --- a/packages/@sanity/portable-text-editor/test/__tests__/writingTogether.collaborative.test.ts +++ b/packages/@sanity/portable-text-editor/e2e-tests/__tests__/writingTogether.collaborative.test.ts @@ -1,4 +1,4 @@ -/** @jest-environment ./test/setup/collaborative.jest.env.ts */ +/** @jest-environment ./e2e-tests/setup/collaborative.jest.env.ts */ import '../setup/globals.jest' import type {PortableTextBlock} from '@sanity/types' diff --git a/packages/@sanity/portable-text-editor/test/schema.ts b/packages/@sanity/portable-text-editor/e2e-tests/schema.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/schema.ts rename to packages/@sanity/portable-text-editor/e2e-tests/schema.ts diff --git a/packages/@sanity/portable-text-editor/test/serve.ts b/packages/@sanity/portable-text-editor/e2e-tests/serve.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/serve.ts rename to packages/@sanity/portable-text-editor/e2e-tests/serve.ts diff --git a/packages/@sanity/portable-text-editor/test/setup/afterEnv.ts b/packages/@sanity/portable-text-editor/e2e-tests/setup/afterEnv.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/setup/afterEnv.ts rename to packages/@sanity/portable-text-editor/e2e-tests/setup/afterEnv.ts diff --git a/packages/@sanity/portable-text-editor/test/setup/collaborative.jest.env.ts b/packages/@sanity/portable-text-editor/e2e-tests/setup/collaborative.jest.env.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/setup/collaborative.jest.env.ts rename to packages/@sanity/portable-text-editor/e2e-tests/setup/collaborative.jest.env.ts diff --git a/packages/@sanity/portable-text-editor/test/setup/globalSetup.ts b/packages/@sanity/portable-text-editor/e2e-tests/setup/globalSetup.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/setup/globalSetup.ts rename to packages/@sanity/portable-text-editor/e2e-tests/setup/globalSetup.ts diff --git a/packages/@sanity/portable-text-editor/test/setup/globalTeardown.ts b/packages/@sanity/portable-text-editor/e2e-tests/setup/globalTeardown.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/setup/globalTeardown.ts rename to packages/@sanity/portable-text-editor/e2e-tests/setup/globalTeardown.ts diff --git a/packages/@sanity/portable-text-editor/test/setup/globals.jest.ts b/packages/@sanity/portable-text-editor/e2e-tests/setup/globals.jest.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/setup/globals.jest.ts rename to packages/@sanity/portable-text-editor/e2e-tests/setup/globals.jest.ts diff --git a/packages/@sanity/portable-text-editor/test/tsconfig.json b/packages/@sanity/portable-text-editor/e2e-tests/tsconfig.json similarity index 100% rename from packages/@sanity/portable-text-editor/test/tsconfig.json rename to packages/@sanity/portable-text-editor/e2e-tests/tsconfig.json diff --git a/packages/@sanity/portable-text-editor/test/web-server/app.tsx b/packages/@sanity/portable-text-editor/e2e-tests/web-server/app.tsx similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/app.tsx rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/app.tsx diff --git a/packages/@sanity/portable-text-editor/test/web-server/components/Editor.tsx b/packages/@sanity/portable-text-editor/e2e-tests/web-server/components/Editor.tsx similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/components/Editor.tsx rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/components/Editor.tsx diff --git a/packages/@sanity/portable-text-editor/test/web-server/components/Value.tsx b/packages/@sanity/portable-text-editor/e2e-tests/web-server/components/Value.tsx similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/components/Value.tsx rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/components/Value.tsx diff --git a/packages/@sanity/portable-text-editor/test/web-server/entry.tsx b/packages/@sanity/portable-text-editor/e2e-tests/web-server/entry.tsx similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/entry.tsx rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/entry.tsx diff --git a/packages/@sanity/portable-text-editor/test/web-server/index.html b/packages/@sanity/portable-text-editor/e2e-tests/web-server/index.html similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/index.html rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/index.html diff --git a/packages/@sanity/portable-text-editor/test/web-server/keyGenerator.ts b/packages/@sanity/portable-text-editor/e2e-tests/web-server/keyGenerator.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/keyGenerator.ts rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/keyGenerator.ts diff --git a/packages/@sanity/portable-text-editor/test/web-server/vite.config.js b/packages/@sanity/portable-text-editor/e2e-tests/web-server/vite.config.js similarity index 100% rename from packages/@sanity/portable-text-editor/test/web-server/vite.config.js rename to packages/@sanity/portable-text-editor/e2e-tests/web-server/vite.config.js diff --git a/packages/@sanity/portable-text-editor/test/ws-server/index.ts b/packages/@sanity/portable-text-editor/e2e-tests/ws-server/index.ts similarity index 100% rename from packages/@sanity/portable-text-editor/test/ws-server/index.ts rename to packages/@sanity/portable-text-editor/e2e-tests/ws-server/index.ts diff --git a/packages/@sanity/portable-text-editor/jest.config.cjs b/packages/@sanity/portable-text-editor/jest.config.cjs index 7f8d54348cc..7386955f5d3 100644 --- a/packages/@sanity/portable-text-editor/jest.config.cjs +++ b/packages/@sanity/portable-text-editor/jest.config.cjs @@ -2,9 +2,22 @@ const {createJestConfig} = require('../../../test/config.cjs') +const PTE_E2E = process.env.PTE_E2E + +if (!PTE_E2E) { + module.exports = createJestConfig({ + displayName: require('./package.json').name, + modulePathIgnorePatterns: ['/e2e-tests'], + }) + return +} + +// eslint-disable-next-line no-console +console.info('Running collaborate editing tests for the Portable Text Editor') + module.exports = createJestConfig({ displayName: require('./package.json').name, - globalSetup: '/test/setup/globalSetup.ts', - globalTeardown: '/test/setup/globalTeardown.ts', - setupFilesAfterEnv: ['/test/setup/afterEnv.ts'], + globalSetup: '/e2e-tests/setup/globalSetup.ts', + globalTeardown: '/e2e-tests/setup/globalTeardown.ts', + setupFilesAfterEnv: ['/e2e-tests/setup/afterEnv.ts'], }) diff --git a/packages/@sanity/portable-text-editor/package.json b/packages/@sanity/portable-text-editor/package.json index 661780fd35f..27a1df061dc 100644 --- a/packages/@sanity/portable-text-editor/package.json +++ b/packages/@sanity/portable-text-editor/package.json @@ -59,6 +59,7 @@ "prettier": "prettier --write './**/*.{ts,tsx,js,css,html}'", "dev": "cd ./test/ && ts-node serve", "test": "jest", + "test:e2e": "PTE_E2E=true jest e2e-tests/__tests__", "test:watch": "jest --watch", "watch": "pkg-utils watch --tsconfig tsconfig.lib.json" }, diff --git a/packages/@sanity/portable-text-editor/src/editor/components/Synchronizer.tsx b/packages/@sanity/portable-text-editor/src/editor/components/Synchronizer.tsx index 3ced445d860..a2d0c3b0f1a 100644 --- a/packages/@sanity/portable-text-editor/src/editor/components/Synchronizer.tsx +++ b/packages/@sanity/portable-text-editor/src/editor/components/Synchronizer.tsx @@ -28,7 +28,7 @@ const debugVerbose = debug.enabled && false // The editor will commit changes in a throttled fashion in order // not to overload the network and degrade performance while typing. -const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === 'test' ? 100 : 1000 +const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === 'test' ? 500 : 1000 /** * @internal