From a807406e343fecc375c0d5f230058b6c4bfd5968 Mon Sep 17 00:00:00 2001 From: Per-Kristian Nordnes Date: Fri, 27 Oct 2023 22:32:44 +0200 Subject: [PATCH] ci: move PTE e2e tests out in own workflow (#5080) * ci: move PTE e2e tests into own worker and folder * ci: remove shard sequencer, it was GitHub cache :tableflip: --- .github/workflows/e2e-pte.yml | 63 +++++++++++++++++++ .github/workflows/test.yml | 38 ----------- .../{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 +- .../e2e-tests/e2e.config.cjs | 13 ++++ .../{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 | 4 +- .../@sanity/portable-text-editor/package.json | 1 + .../src/editor/components/Synchronizer.tsx | 2 +- 27 files changed, 83 insertions(+), 46 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 (99%) 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%) create mode 100644 packages/@sanity/portable-text-editor/e2e-tests/e2e.config.cjs 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/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 99% 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..c207bfce3f7 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 ./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..f60ab3d1c06 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 ./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..725c06eb631 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 ./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..505dd69c36d 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 ./setup/collaborative.jest.env.ts */ import '../setup/globals.jest' import type {PortableTextBlock} from '@sanity/types' diff --git a/packages/@sanity/portable-text-editor/e2e-tests/e2e.config.cjs b/packages/@sanity/portable-text-editor/e2e-tests/e2e.config.cjs new file mode 100644 index 00000000000..aea2aa4af79 --- /dev/null +++ b/packages/@sanity/portable-text-editor/e2e-tests/e2e.config.cjs @@ -0,0 +1,13 @@ +'use strict' + +const {createJestConfig} = require('../../../../test/config.cjs') + +// 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: './setup/globalSetup.ts', + globalTeardown: './setup/globalTeardown.ts', + setupFilesAfterEnv: ['./setup/afterEnv.ts'], +}) 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..eadf800d82a 100644 --- a/packages/@sanity/portable-text-editor/jest.config.cjs +++ b/packages/@sanity/portable-text-editor/jest.config.cjs @@ -4,7 +4,5 @@ const {createJestConfig} = require('../../../test/config.cjs') module.exports = createJestConfig({ displayName: require('./package.json').name, - globalSetup: '/test/setup/globalSetup.ts', - globalTeardown: '/test/setup/globalTeardown.ts', - setupFilesAfterEnv: ['/test/setup/afterEnv.ts'], + modulePathIgnorePatterns: ['/e2e-tests'], }) diff --git a/packages/@sanity/portable-text-editor/package.json b/packages/@sanity/portable-text-editor/package.json index 661780fd35f..15275672e27 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": "cd e2e-tests && jest --config=e2e.config.cjs", "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