Skip to content

Commit

Permalink
feat: playwright e2e testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hmerritt committed Jan 31, 2024
1 parent 22561f3 commit 8f61b92
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- run: corepack enable && corepack prepare yarn@stable --activate && yarn set version 3.5.0
- run: yarn install
- run: yarn test:e2e:setup
- run: yarn test:coverage
- run: yarn test:e2e
- run: yarn build
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ dist-ssr
*.local

vite-app

# e2e playwright tests
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ test:
before_script:
- apk update && apk add git bash
- yarn install --cache-folder .npm --prefer-offline
- yarn test:e2e:setup
script:
- yarn test:coverage
- yarn test:e2e
- unset CI
- yarn build
coverage: /All\sfiles.*?\s+(\d+.\d+)/
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"preview": "node bootstrap.cjs vite preview",
"start": "node bootstrap.cjs vite",
"test": "node bootstrap.cjs vitest run",
"test:e2e": "node bootstrap.cjs yarn playwright test",
"test:e2e:setup": "yarn playwright install --with-deps",
"test:bench": "node bootstrap.cjs vitest bench",
"test:coverage": "node bootstrap.cjs vitest run --coverage",
"test:ui": "node bootstrap.cjs vitest --ui",
Expand Down Expand Up @@ -39,6 +41,7 @@
"devDependencies": {
"@babel/core": "^7.23.9",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@playwright/test": "^1.41.1",
"@rollup/pluginutils": "^5.1.0",
"@testing-library/jest-dom": "^6.3.0",
"@testing-library/react": "^14.1.2",
Expand Down
47 changes: 47 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { defineConfig, devices } from "@playwright/test";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests-e2e",
/* 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: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://localhost:5173",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry"
},

/* Configure projects for major browsers */
projects: [
{
name: "webkit",
use: { ...devices["Desktop Safari"] }
},

/* Test against mobile viewports. */
{
name: "Mobile Chrome",
use: { ...devices["Pixel 6"] }
}
],

/* Run your local dev server before starting the tests */
webServer: {
command: "yarn dev",
url: "http://localhost:5173",
reuseExistingServer: !process.env.CI
}
});
13 changes: 13 additions & 0 deletions tests-e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "@playwright/test";

test.beforeEach(async ({ page }) => {
await page.goto("/");
});

test("has title", async ({ page }) => {
await expect(page).toHaveTitle(/Adrift/i);

await expect(
page.getByText(/Template react app with batteries included/i)
).toBeVisible();
});
40 changes: 38 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,17 @@ __metadata:
languageName: node
linkType: hard

"@playwright/test@npm:^1.41.1":
version: 1.41.1
resolution: "@playwright/test@npm:1.41.1"
dependencies:
playwright: 1.41.1
bin:
playwright: cli.js
checksum: d9877e777a1a7f60f097df57b6abc2478e2ae342930a409c8546c8aa40d6e206cbc16bf1c71b23414ac3fbad36dcae1ad79635d7f4eb705ab54d3c705e82ea04
languageName: node
linkType: hard

"@polka/url@npm:^1.0.0-next.24":
version: 1.0.0-next.24
resolution: "@polka/url@npm:1.0.0-next.24"
Expand Down Expand Up @@ -3245,6 +3256,7 @@ __metadata:
"@dnd-kit/utilities": ^3.2.2
"@linaria/core": 6.0.0
"@linaria/react": 6.0.0
"@playwright/test": ^1.41.1
"@reduxjs/toolkit": ^2.1.0
"@rollup/pluginutils": ^5.1.0
"@tanstack/react-router": ^1.15.5
Expand Down Expand Up @@ -4567,7 +4579,7 @@ __metadata:
languageName: node
linkType: hard

"fsevents@npm:~2.3.2":
"fsevents@npm:2.3.2, fsevents@npm:~2.3.2":
version: 2.3.2
resolution: "fsevents@npm:2.3.2"
dependencies:
Expand All @@ -4587,7 +4599,7 @@ __metadata:
languageName: node
linkType: hard

"fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
"fsevents@patch:fsevents@2.3.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
version: 2.3.2
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=df0bf1"
dependencies:
Expand Down Expand Up @@ -6245,6 +6257,30 @@ __metadata:
languageName: node
linkType: hard

"playwright-core@npm:1.41.1":
version: 1.41.1
resolution: "playwright-core@npm:1.41.1"
bin:
playwright-core: cli.js
checksum: c83446a560c6bd85f6f0cd586ff8c643b77e2005567386e12f85890936cc370673114b94cd883246018797cc1580e93b0296ade7d07275bb611b8962f5bb9693
languageName: node
linkType: hard

"playwright@npm:1.41.1":
version: 1.41.1
resolution: "playwright@npm:1.41.1"
dependencies:
fsevents: 2.3.2
playwright-core: 1.41.1
dependenciesMeta:
fsevents:
optional: true
bin:
playwright: cli.js
checksum: 3da7fb929abdec6adbdd8829f840580f5f210713214a8d230b130127f2270403eb2113c6c1418012221149707250fff896794c7c22c260dd09a92bf800227f31
languageName: node
linkType: hard

"postcss@npm:^8.4.32":
version: 8.4.33
resolution: "postcss@npm:8.4.33"
Expand Down

0 comments on commit 8f61b92

Please sign in to comment.