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..1c38fc89293 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,29 +119,12 @@ 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: | node -v npm -v - yarn test --silent --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }} + yarn test --silent --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }} --testSequencer=../../../shardSequencer.cjs env: SANITY_CI_CLI_AUTH_TOKEN: ${{ secrets.SANITY_CI_CLI_AUTH_TOKEN }} GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }} diff --git a/package.json b/package.json index 21bae3b54c0..0d5bf821861 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "@babel/preset-react": "^7.22.15", "@babel/preset-typescript": "^7.23.0", "@bjoerge/mutiny": "^0.0.2", + "@jest/test-sequencer": "^29.7.0", "@optimize-lodash/rollup-plugin": "^4.0.4", "@playwright/test": "^1.38.1", "@sanity/client": "^6.7.0", 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 diff --git a/shardSequencer.cjs b/shardSequencer.cjs new file mode 100644 index 00000000000..c56152b98bb --- /dev/null +++ b/shardSequencer.cjs @@ -0,0 +1,9 @@ +'use strict' + +const Sequencer = require('@jest/test-sequencer').default + +module.exports = class JestShardSequencer extends Sequencer { + shard(tests) { + return tests.filter((test) => !test.path.includes('e2e')) + } +} diff --git a/yarn.lock b/yarn.lock index 18464094fba..932530882e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15999,6 +15999,11 @@ yargs@^17.3.0, yargs@^17.3.1: y18n "^5.0.5" yargs-parser "^21.1.1" +yarn@^1.22.19: + version "1.22.19" + resolved "https://registry.npmjs.org/yarn/-/yarn-1.22.19.tgz#4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" + integrity sha512-/0V5q0WbslqnwP91tirOvldvYISzaqhClxzyUKXYxs07yUILIs5jx/k6CFe8bvKSkds5w+eiOqta39Wk3WxdcQ== + yauzl@^2.4.2: version "2.10.0" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"