-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GSOC-E2E-1: Add Playwright CI workflow and sketch execution test #4172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Geethegreat
wants to merge
19
commits into
processing:develop
Choose a base branch
from
Geethegreat:feat/e2e-clean
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+280
−0
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
389dfef
Add playwright CI workflow
Geethegreat 617c4e4
Add Playwright sketch execution test
Geethegreat 630199e
improve e2e CI startup
Geethegreat 85fbbd9
add playwright dependency
Geethegreat 97b5b6e
Update .github/workflows/e2e.yml
Geethegreat 666fb32
Update .github/workflows/e2e.yml
Geethegreat eb569d9
Update playwright.config.ts
Geethegreat 44fb350
apply remaining review suggestions
Geethegreat 3667d1d
remove open console action
Geethegreat daa2359
replace redux state injection with keyboard.type
Geethegreat be5932b
make the codemirror selection more consistent and increase timeout
Geethegreat 924e4ee
increase wait time for the app to build
Geethegreat 4cfe4ec
increase timeout even more
Geethegreat 9d9bc88
update code mirror selector for click, update ctrl-all command to use…
clairep94 8f5b8e0
use cross-platform select-all shortcut
Geethegreat 24bc621
swap .CodeMirror for .CodeMirror-code
clairep94 fd1c6b0
use cross-platform select-all shortcut
Geethegreat 1d60c99
use skip link to wait for app render in CI
Geethegreat 30991c4
remove wait for codemirror
Geethegreat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,39 @@ | ||
| API_URL=/editor | ||
| CORS_ALLOW_LOCALHOST=true | ||
| TRANSLATIONS_ENABLED=true | ||
| UI_ACCESS_TOKEN_ENABLED=false | ||
| UPLOAD_LIMIT=250000000 | ||
| PORT=8000 | ||
| PREVIEW_PORT=8002 | ||
| EDITOR_URL=http://localhost:8000 | ||
| PREVIEW_URL=http://localhost:8002 | ||
| MONGO_URL=mongodb://localhost:27017/p5js-web-editor | ||
| SESSION_SECRET=ci-session-secret | ||
| EMAIL_VERIFY_SECRET_TOKEN=ci-verify-token | ||
| # These accounts are used by the app to serve examples. | ||
| # Real values not needed for E2E tests — dummy strings prevent crashes. | ||
| EMAIL_SENDER=ci@example.com | ||
| EXAMPLE_USER_EMAIL=examples@p5js.org | ||
| EXAMPLE_USER_PASSWORD=hellop5js | ||
| GG_EXAMPLES_USERNAME=generativedesign | ||
| GG_EXAMPLES_EMAIL=benedikt.gross@generative-gestaltung.de | ||
| GG_EXAMPLES_PASS=generativedesign | ||
| ML5_LIBRARY_USERNAME=ml5 | ||
| ML5_LIBRARY_EMAIL=examples@ml5js.org | ||
| ML5_LIBRARY_PASS=helloml5 | ||
| # Mailgun — non-empty string required to pass the startup check in | ||
| # server/utils/mail.ts. No emails are sent during E2E tests. | ||
| MAILGUN_KEY=dummy-mailgun-key | ||
| MAILGUN_DOMAIN=dummy.mailgun.org | ||
| # AWS S3 — non-empty strings required. No file uploads in E2E tests. | ||
| AWS_ACCESS_KEY=dummy-aws-access-key | ||
| AWS_SECRET_KEY=dummy-aws-secret-key | ||
| AWS_REGION=us-east-1 | ||
| S3_BUCKET=dummy-bucket | ||
| S3_BUCKET_URL_BASE=https://dummy-bucket.s3.amazonaws.com | ||
| # GitHub OAuth — not tested in E2E suite, dummy values prevent crash. | ||
| GITHUB_ID=dummy-github-id | ||
| GITHUB_SECRET=dummy-github-secret | ||
| # Google OAuth — not tested in E2E suite, dummy values prevent crash. | ||
| GOOGLE_ID=dummy-google-id | ||
| GOOGLE_SECRET=dummy-google-secret |
This file contains hidden or 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,80 @@ | ||
| name: E2E Testing | ||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: [develop] | ||
| issue_comment: | ||
| types: [created] | ||
| jobs: | ||
| test-e2e: | ||
| if: > | ||
| github.event_name == 'workflow_dispatch' || | ||
| github.event_name == 'pull_request' || | ||
| ( | ||
| github.event.issue.pull_request && | ||
| github.event.comment.body == '/e2e' && | ||
| contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) | ||
| ) | ||
| timeout-minutes: 60 | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Resolve PR head ref | ||
| if: github.event_name == 'issue_comment' | ||
| id: pr | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number | ||
| }); | ||
| core.setOutput('sha', pr.head.sha); | ||
|
|
||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event_name == 'issue_comment' && steps.pr.outputs.sha || github.ref }} | ||
|
|
||
| - name: Set up node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18.20.x' | ||
|
|
||
| - name: Create .env file | ||
| run: cp .env.e2e .env | ||
|
|
||
| - name: Start MongoDB | ||
| uses: supercharge/mongodb-github-action@1.10.0 | ||
| with: | ||
| mongodb-version: '6.0' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Install Playwright Browsers | ||
| run: npx playwright install --with-deps chromium | ||
|
|
||
| - name: Start app | ||
| run: npm start > app.log 2>&1 & | ||
|
|
||
| - name: Wait for app to be ready | ||
| run: | | ||
| npx wait-on@7 http://localhost:8000 --timeout 180000 || { | ||
| echo "::error::App failed to become ready at http://localhost:8000 within 180s" | ||
| echo "----- app.log -----" | ||
| cat app.log | ||
| exit 1 | ||
| } | ||
|
|
||
| - name: Run Playwright tests | ||
| run: npm run e2e:ci | ||
|
|
||
| - name: Upload artifacts | ||
| if: failure() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: playwright-report | ||
| path: playwright-report/ | ||
| retention-days: 30 |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,18 @@ | ||
| import { defineConfig, devices } from '@playwright/test'; | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './tests/playwright', | ||
| testMatch: '**/*.spec.ts', | ||
| timeout: 600_000, | ||
|
|
||
| use: { | ||
| baseURL: 'http://localhost:8000' | ||
| }, | ||
|
|
||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] } | ||
| } | ||
| ] | ||
| }); |
This file contains hidden or 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,61 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| test.describe('p5.js Editor – Playwright E2E', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/'); | ||
|
|
||
| // Wait for app to fully render — skip link only appears after React mounts | ||
| await expect( | ||
| page.locator('a.skip_link[href="#play-sketch"]') | ||
| ).toHaveText('Skip to Play Sketch', { timeout: 60_000 }); | ||
|
|
||
| // Dismiss cookie banner via JS — handles the case where the button | ||
| // is outside the viewport due to the Redux DevTools sidebar | ||
| await page.evaluate(() => { | ||
| const btn = Array.from(document.querySelectorAll('button')).find((b) => | ||
| /allow essential|allow all/i.test(b.textContent ?? '') | ||
| ) as HTMLElement | undefined; | ||
| btn?.click(); | ||
| }); | ||
|
|
||
| await page.waitForTimeout(400); | ||
| }); | ||
|
|
||
| test('can execute code from the editor by clicking the Play button', async ({ | ||
| page | ||
| }) => { | ||
| const newCode = [ | ||
| 'function setup() {', | ||
| ' createCanvas(400, 400);', | ||
| '}', | ||
| '', | ||
| 'function draw() {', | ||
| ' background(220);', | ||
| " console.log('hi from sketch');", | ||
| ' noLoop();', | ||
| '}' | ||
| ].join(''); // Avoid newlines to prevent autocomplete from inserting unnecessary brackets | ||
|
|
||
| await page.click('.CodeMirror-code', { force: true }); | ||
|
|
||
| await page.keyboard.press('ControlOrMeta+A'); | ||
| await page.keyboard.type(newCode, { delay: 5 }); | ||
|
|
||
| // Click Play | ||
| await page.locator('#play-sketch').click({ force: true }); | ||
|
|
||
| // Wait for the sketch iframe to confirm the sketch actually started | ||
| await page.waitForFunction( | ||
| () => | ||
| Array.from(document.querySelectorAll('iframe')).some((f) => | ||
| (f as HTMLIFrameElement).src.includes('8002') | ||
| ), | ||
| { timeout: 10_000 } | ||
| ); | ||
|
|
||
| // Assert console output | ||
| await expect( | ||
| page.locator('.preview-console__messages') | ||
| ).toContainText('hi from sketch', { timeout: 15_000 }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is page.evaluate necessary?
does the below not work?
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.
Thanks for the suggestion! I tried this approach initially but the "Allow Essential" button is pushed outside the viewport by the Redux DevTools sidebar that's present in the dev build, it exists in the DOM but locator.click() throws "element is outside of the viewport". The JS evaluate approach bypasses the geometry check entirely. Happy to add a comment explaining this if that helps.