-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: test examples in real browsers #242
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
834ce1e
feat: shared example tests
olizilla cffdaab
feat: drive tests with @playwright/test
olizilla 54e7db5
chore: make tests pass
olizilla a13ef94
chore: only test examples if examples change
olizilla e6a5fe0
chore: ignore build failures for now
olizilla dd94b66
chore: lint and doc
olizilla 091937d
Merge remote-tracking branch 'origin/main' into shared-example-tests
olizilla b3da802
Merge remote-tracking branch 'origin/main' into shared-example-tests
olizilla 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 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,30 @@ | ||
name: Examples | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "examples/**" | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- "examples/**" | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/actions/pnpm | ||
- run: pnpm build:examples | ||
- run: pnpx playwright install --with-deps # install browsers | ||
- run: pnpm test:examples | ||
|
||
# save test report | ||
# - uses: actions/upload-artifact@v3 | ||
# if: always() | ||
# with: | ||
# name: playwright-report | ||
# path: playwright-report/ | ||
# 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
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
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,14 @@ | ||
{ | ||
"unlisted": [ | ||
"README.md", | ||
"test", | ||
"serve.json", | ||
"template" | ||
], | ||
"rewrites": [ | ||
{ "source": "/:ui/:eg", "destination": "/:ui/:eg/dist/index.html" }, | ||
{ "source": "/:ui/:eg/", "destination": "/:ui/:eg/dist/index.html" }, | ||
{ "source": "/:ui/:eg/favicon.ico", "destination": "/:ui/:eg/dist/favicon.ico" }, | ||
{ "source": "/:ui/:eg/assets/:x", "destination": "/:ui/:eg/dist/assets/:x" } | ||
] | ||
} |
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
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,4 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
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,61 @@ | ||
# W3UI Playwright tests | ||
|
||
_Test our examples across all UI libraties we support, in real browsers!_ | ||
|
||
## Getting started | ||
|
||
Install the deps and the browsers from the root of the monorepo | ||
|
||
```bash | ||
# update deps | ||
$ pnpm i | ||
|
||
# fetch test browsers | ||
$ pnpx playwright install | ||
``` | ||
|
||
Build the examples to their many dist folders | ||
|
||
```bash | ||
$ pnpm build:examples | ||
``` | ||
|
||
Run the tests | ||
|
||
```bash | ||
$ pnpm test:examples | ||
|
||
examples/test/playwright test$ playwright test | ||
[30 lines collapsed] | ||
│ [30/33] [webkit] › sign-up-in.spec.ts:4:3 › vue: sign in | ||
│ [31/33] [webkit] › uploads-list.spec.ts:4:3 › react: uploads list | ||
│ [32/33] [webkit] › uploads-list.spec.ts:4:3 › solid: uploads list | ||
│ [33/33] [webkit] › uploads-list.spec.ts:4:3 › vue: uploads list | ||
│ | ||
│ 33 passed (7s) | ||
│ To open last HTML report run: | ||
│ | ||
│ npx playwright show-report | ||
│ | ||
└─ Done in 7.6s | ||
``` | ||
|
||
## Debugging | ||
|
||
You can run the test server manually to see what requests are made, and the tests will re-use your running server on http://localhost:1337 - it's powered by `serve` a static webserver running over the examples dir, configured in `examples/serve.json` | ||
|
||
```bash | ||
$ pnpm serve:examples | ||
``` | ||
|
||
You can also run the tests locally from this project, and have it show you the browser as the tests run to aid debugging | ||
|
||
```bash | ||
$ cd examples/test/playwright | ||
$ pnpm test | ||
|
||
# or to see what's going on in the browser as the test runs | ||
$ pnpm test:debug | ||
``` | ||
|
||
|
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,16 @@ | ||
{ | ||
"name": "@w3ui/example-test-playwright", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"serve": "serve ../../", | ||
"test": "playwright test", | ||
"test:debug": "playwright test --project=chromium --headed" | ||
}, | ||
"author": "olzilla", | ||
"license": "Apache-2.0 OR MIT", | ||
"devDependencies": { | ||
"@playwright/test": "^1.29.2", | ||
"serve": "^14.1.2" | ||
} | ||
} |
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,101 @@ | ||
import type { PlaywrightTestConfig } from '@playwright/test' | ||
import { devices } from '@playwright/test' | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
const config: PlaywrightTestConfig = { | ||
testDir: './src', | ||
timeout: 30 * 1000, | ||
expect: { | ||
/** | ||
* Maximum time expect() should wait for the condition to be met. | ||
* For example in `await expect(locator).toHaveText();` | ||
*/ | ||
timeout: 5000 | ||
}, | ||
/* 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, // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* 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: 0, | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: 'http://localhost:1337', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry' | ||
}, | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
reuseExistingServer: !process.env.CI, // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
command: 'pnpm run serve -p 1337', | ||
port: 1337 | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'] | ||
} | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { | ||
...devices['Desktop Firefox'] | ||
} | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { | ||
...devices['Desktop Safari'] | ||
} | ||
} | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { | ||
// ...devices['Pixel 5'], | ||
// }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { | ||
// ...devices['iPhone 12'], | ||
// }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { | ||
// channel: 'msedge', | ||
// }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { | ||
// channel: 'chrome', | ||
// }, | ||
// }, | ||
] | ||
|
||
/* Folder for test artifacts such as screenshots, videos, traces, etc. */ | ||
// outputDir: 'test-results/', | ||
} | ||
|
||
export default config |
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,13 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
for (const ui of ['react', 'solid', 'vue'/* 'vanilla' not work atm */]) { | ||
test(`${ui}: file upload`, async ({ page }) => { | ||
await page.goto(`/${ui}/file-upload/`) | ||
await expect(page).toHaveTitle('W3UI File Upload Example App') | ||
|
||
const input = page.getByRole('textbox', { name: 'Email address:' }) | ||
await input.fill('[email protected]') | ||
await input.press('Enter') | ||
await expect(page.getByText('Verify your email address!')).toBeVisible() | ||
}) | ||
} |
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,13 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
for (const ui of ['react', 'solid'/* `vue` not exit yet, 'vanilla' not work atm */]) { | ||
test(`${ui}: multi file upload`, async ({ page }) => { | ||
await page.goto(`/${ui}/multi-file-upload/`) | ||
await expect(page).toHaveTitle('W3UI Multi File Upload Example App') | ||
|
||
const input = page.getByRole('textbox', { name: 'Email address:' }) | ||
await input.fill('[email protected]') | ||
await input.press('Enter') | ||
await expect(page.getByText('Verify your email address!')).toBeVisible() | ||
}) | ||
} |
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.
this is dope af