-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GSOC-E2E-1 (remake): Init Playwright, Sketch execution test, and new E2e Test workflow #4199
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
clairep94
wants to merge
7
commits into
processing:develop
Choose a base branch
from
clairep94:clairep-gsoc_e2e_testing_setup
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.
+340
−3
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f10c4e
init playwright with 'init playwright@latest'
clairep94 1386cbd
add tsconfig for e2e tests folder
653dcf7
add e2e testing commands to package.json
b39431b
configure playwright for local vs CI
2adcf64
add editor.spec.ts with 'can run code written in the editor'
9913751
add e2e testing workflow:
9c0d55a
e2e.yml: add caching for npm & playwright browers
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
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,98 @@ | ||
| name: E2E Testing | ||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: [develop] | ||
| issue_comment: | ||
| types: [created] | ||
| jobs: | ||
| test-e2e: | ||
| # temporary while new e2e environment is not yet created: | ||
| # only trigger on workflow_dispatch, maintainer comment, or if PR is from GSOC project mentor or mentee | ||
| if: > | ||
| github.event_name == 'workflow_dispatch' || | ||
| ( | ||
| github.event_name == 'pull_request' && | ||
| contains(fromJSON('["Geethegreat", "clairep94"]'), github.event.pull_request.user.login) | ||
| ) || | ||
| ( | ||
| 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' | ||
| cache: 'npm' | ||
|
|
||
| - name: Create .env file | ||
| run: cp .env.example .env | ||
|
|
||
| - name: Start MongoDB | ||
| uses: supercharge/mongodb-github-action@1.10.0 | ||
| with: | ||
| mongodb-version: '6.0' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Cache Playwright browsers | ||
| uses: actions/cache@v4 | ||
| id: playwright-cache | ||
| with: | ||
| path: ~/.cache/ms-playwright | ||
| key: playwright-${{ hashFiles('package-lock.json') }} | ||
|
|
||
| - name: Install Playwright Browsers | ||
| if: steps.playwright-cache.outputs.cache-hit != 'true' | ||
| run: npx playwright install --with-deps chromium | ||
|
|
||
| - name: Install Playwright deps (OS libraries) | ||
| if: steps.playwright-cache.outputs.cache-hit == 'true' | ||
| run: npx playwright install-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
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,60 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| test.describe('editor page', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/'); | ||
|
|
||
| // initial pageload check to fail fast: | ||
| await expect(page.locator('a.skip_link[href="#play-sketch"]')).toHaveText( | ||
| 'Skip to Play Sketch' | ||
| ); | ||
|
|
||
| // Dismiss cookie banner if it appears | ||
| // Note: we do document.querySelectorAll instead of page.locator as workaround due to the buttons on the banner being beyond the viewport | ||
| 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(); | ||
| }); | ||
|
|
||
| // wait for page to fully load with all main IDE components: | ||
| await expect(page.locator('#play-sketch')).toBeVisible(); // play button | ||
| await expect(page.locator('iframe[title="sketch preview"]')).toBeVisible(); // sketch preview | ||
| await expect(page.locator('.preview-console')).toBeVisible(); // editor console | ||
| await expect(page.locator('.editor-holder')).toBeVisible(); // editor -- NOTE: .editor-holder .CodeMirror cannot be found on CI for some reason, so we are using .editor-holder instead. | ||
| }); | ||
|
|
||
| test('can run sketch code written in the editor', async ({ page }) => { | ||
| const newCode = [ | ||
| 'function setup() {', | ||
| ' createCanvas(400, 400);', | ||
| '}', | ||
| '', | ||
| 'function draw() {', | ||
| ' background(220);', | ||
| " console.log('hi from sketch');", | ||
| ' noLoop();', | ||
| '}' | ||
| ].join(''); // Purposely joining without '\n' to avoid triggering the autocomplete with keyboard.type & creating extra brackets | ||
|
|
||
| // Find editor text area, clear default code & type in the new code | ||
| const editor = page.locator('.editor-holder'); | ||
| await editor.click(); | ||
| await page.keyboard.press('ControlOrMeta+A'); | ||
| await page.keyboard.type(newCode, { delay: 5 }); // Purposely using .type instead of .insert (.insert does not work with the redux state management) | ||
|
|
||
| // Click Play | ||
| await page.locator('#play-sketch').click({ force: true }); | ||
|
|
||
| // Wait for the sketch iframe src to confirm the sketch actually started | ||
| await expect( | ||
| page.locator('iframe[title="sketch preview"]') | ||
| ).toHaveAttribute('src', /8002/, { timeout: 10_000 }); | ||
|
|
||
| // Assert console output | ||
| await expect( | ||
| page.locator('.preview-console__messages') | ||
| ).toContainText('hi from sketch', { timeout: 15_000 }); | ||
| }); | ||
| }); |
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,11 @@ | ||
| { | ||
| "extends": "../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "target": "ES2022", | ||
| "module": "commonjs", | ||
| "lib": ["ES2022", "dom"], | ||
| "types": ["node"] | ||
| }, | ||
| "include": ["./**/*", "../playwright.config.ts"], | ||
| "exclude": ["../node_modules"] | ||
| } |
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
Oops, something went wrong.
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.
Could we add a new
e2eenvironment to the github repo?So that we can add
environment: 'e2e'here --> would gate workflow runs on maintainer approval