Skip to content

Commit

Permalink
ci: move PTE e2e tests into own worker and folder
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Oct 27, 2023
1 parent fd7db60 commit 3bd4884
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 47 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/e2e-pte.yml
Original file line number Diff line number Diff line change
@@ -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 }}
40 changes: 1 addition & 39 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @jest-environment ./test/setup/collaborative.jest.env.ts */
/** @jest-environment ./setup/collaborative.jest.env.ts */

import '../setup/globals.jest'

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
13 changes: 13 additions & 0 deletions packages/@sanity/portable-text-editor/e2e-tests/e2e.config.cjs
Original file line number Diff line number Diff line change
@@ -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'],
})
4 changes: 1 addition & 3 deletions packages/@sanity/portable-text-editor/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ const {createJestConfig} = require('../../../test/config.cjs')

module.exports = createJestConfig({
displayName: require('./package.json').name,
globalSetup: '<rootDir>/test/setup/globalSetup.ts',
globalTeardown: '<rootDir>/test/setup/globalTeardown.ts',
setupFilesAfterEnv: ['<rootDir>/test/setup/afterEnv.ts'],
modulePathIgnorePatterns: ['<rootDir>/e2e-tests'],
})
1 change: 1 addition & 0 deletions packages/@sanity/portable-text-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions shardSequencer.cjs
Original file line number Diff line number Diff line change
@@ -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'))
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3bd4884

Please sign in to comment.