-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(playwright): initial component testing with playwright-ct (#4779)
* chore(deps): update playwright * text(playwright): initial playwright-ct setup * refactor(playwright): co-locate playwright-ct with sanity package * chore(deps): use @playwright/test in perf studio and @sanity/portable-text-editor * refactor(playwright): simplify stories, add data-attr for activate overlay * refactor(playwright): re-add typeWithDelay helper, temporarily disable context menu keyboard interactions * refactor(playwright): fix e2e-ct action paths, use default delay when unbolding text * refactor(playwright): split up megastory test, fix flakyness * fix(playwright): fix import for validateDocument * fix(playwright): workaround memory issue with max_old_space_size * fix(playwright): fix report json path * refactor(playwright): update test folder structure, add simple array input test, fix minor template rendering issues (#4797) * fix(playwright): use correct doctype, add font-smoothing * refactor(playwright): separate TestForm, co-locate script types, remove unnecessary exports, wrap tests in panes, add placeholder array input spec * refactor(playwright): rename TestProvider to TestWrapper, don't accept children * refactor(playwright): refactor test report to pr comment conversion * chore(playwright): pin workflow deps * fix(playwright): fix playwright cache issue in ci * fix(playwright): fix artifact paths in workflow * chore(playwright): setup e2e-ct workflow to use remote caching * chore(playwright): linting * fix(playwright): remove breaking keypresses after upgrading slate --------- Co-authored-by: Robin Pyon <[email protected]> Co-authored-by: Robin Pyon <[email protected]>
- Loading branch information
1 parent
08e73ad
commit f44593e
Showing
29 changed files
with
1,498 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: End-to-End Component 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: | ||
test: | ||
timeout-minutes: 30 | ||
runs-on: ubuntu-latest | ||
env: | ||
TURBO_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
TURBO_TEAM: sanity-io | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
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 --immutable --immutable-cache --check-cache | ||
|
||
- 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 | ||
run: npx playwright install --with-deps | ||
- name: Build CLI | ||
run: yarn build:cli # Needed for CLI tests | ||
- name: Run end-to-end tests | ||
run: yarn workspace sanity test:ct | ||
env: | ||
NODE_OPTIONS: --max_old_space_size=8192 | ||
- name: Get Current Job Log URL | ||
uses: Tiryoh/gha-jobid-action@603885a199c331cc2f828bcebeb1c4a275f4d6e1 # v0 | ||
id: job_html_url | ||
if: always() | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
job_name: 'test' | ||
- name: Parse playwright report | ||
id: parse-playwright-report | ||
if: always() | ||
run: yarn workspace sanity write:playwright-report-as-pr-comment | ||
env: | ||
GITHUB_WORKFLOW_URL: '${{ steps.job_html_url.outputs.html_url }}' | ||
- name: PR comment with report | ||
uses: thollander/actions-comment-pull-request@d61db783da9abefc3437960d0cce08552c7c004f # v2 | ||
if: ${{ always() && steps.parse-playwright-report.conclusion == 'success' && github.event_name == 'pull_request' }} | ||
with: | ||
comment_tag: 'playwright-ct-report' | ||
filePath: ${{ github.workspace }}/packages/sanity/playwright-ct/results/playwright-report-pr-comment.md | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-ct-report | ||
path: | | ||
${{ github.workspace }}/packages/sanity/playwright-ct/report | ||
${{ github.workspace }}/packages/sanity/playwright-ct/results | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@sanity/portable-text-editor/test/setup/collaborative.jest.env.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import path from 'path' | ||
import {defineConfig, devices} from '@playwright/experimental-ct-react' | ||
|
||
// Paths | ||
const TESTS_PATH = path.join(__dirname, 'playwright-ct', 'tests') | ||
const HTML_REPORT_PATH = path.join(__dirname, 'playwright-ct', 'report') | ||
const ARTIFACT_OUTPUT_PATH = path.join(__dirname, 'playwright-ct', 'results') | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: TESTS_PATH, | ||
|
||
outputDir: ARTIFACT_OUTPUT_PATH, | ||
|
||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: [ | ||
['list'], | ||
['html', {outputFolder: HTML_REPORT_PATH}], | ||
[ | ||
'json', | ||
{ | ||
outputFile: path.join(ARTIFACT_OUTPUT_PATH, 'playwright-ct-test-results.json'), | ||
}, | ||
], | ||
], | ||
|
||
/* Maximum time one test can run for. */ | ||
timeout: 120 * 1000, | ||
expect: { | ||
// Maximum time expect() should wait for the condition to be met. | ||
timeout: 20 * 1000, | ||
}, | ||
|
||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ | ||
actionTimeout: 40 * 1000, | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
/* Port to use for Playwright component endpoint. */ | ||
ctPort: 3100, | ||
/* Configure Playwright vite config */ | ||
/* | ||
ctViteConfig: { | ||
resolve: { | ||
alias: { | ||
'@sanity/util/content': path.join( | ||
__dirname, | ||
'./packages/@sanity/util/src/content/index.ts' | ||
), | ||
}, | ||
}, | ||
}, | ||
*/ | ||
/* Where to find playwright-ct template files */ | ||
ctTemplateDir: './playwright-ct/template', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{name: 'chromium', use: {...devices['Desktop Chrome']}}, | ||
{name: 'firefox', use: {...devices['Desktop Firefox']}}, | ||
{name: 'webkit', use: {...devices['Desktop Safari']}}, | ||
], | ||
}) |
48 changes: 48 additions & 0 deletions
48
packages/sanity/playwright-ct/scripts/parsePlaywrightReportJson.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env node -r esbuild-register | ||
|
||
import {writeFileSync} from 'fs' | ||
import {inspect} from 'util' | ||
import path from 'path' | ||
import _ from 'lodash' | ||
import {readJsonFile, generateOutput, groupTests} from './utils' | ||
|
||
const DEBUG = Boolean(parseInt(process.env.DEBUG || '0', 2)) | ||
const DEFAULT_ARTIFACT_OUTPUT_PATH = path.resolve(path.join(__dirname, '..', 'results')) | ||
|
||
/** | ||
* Summarize the Playwright report JSON into a Markdown string that can be posted as a comment to PRs | ||
*/ | ||
function main() { | ||
const workflowUrl = process.env.GITHUB_WORKFLOW_URL || '' | ||
const jsonPath = | ||
process.env.REPORT_JSON_PATH! || | ||
path.join(DEFAULT_ARTIFACT_OUTPUT_PATH, 'playwright-ct-test-results.json') | ||
const testOutput = readJsonFile(jsonPath) | ||
|
||
if (testOutput) { | ||
const groups = groupTests(testOutput) | ||
const markdownTable = generateOutput(groups, workflowUrl) | ||
|
||
if (DEBUG) { | ||
const result = inspect(groups, { | ||
depth: Infinity, | ||
breakLength: 80, | ||
colors: true, | ||
}) | ||
// eslint-disable-next-line no-console | ||
console.log(result) | ||
// eslint-disable-next-line no-console | ||
console.log(markdownTable) | ||
} | ||
|
||
writeFileSync( | ||
path.join(DEFAULT_ARTIFACT_OUTPUT_PATH, 'playwright-report-pr-comment.md'), | ||
markdownTable, | ||
'utf8', | ||
) | ||
} | ||
|
||
process.stdout.write('Processing Playwright report JSON complete\n') | ||
} | ||
|
||
main() |
Oops, something went wrong.
f44593e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
performance-studio – ./
performance-studio-git-next.sanity.build
performance-studio.sanity.build
f44593e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
test-studio – ./
test-studio.sanity.build
test-studio-git-next.sanity.build