Skip to content

Commit

Permalink
Add e2e test with playwright (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
eXon committed Dec 30, 2023
1 parent 87e4a8c commit 838bf49
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ jobs:

- name: Run tests
run: yarn test

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run Playwright tests
run: npx playwright test

- name: Save Playwright report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ dist
.DS_Store
package-lock.json
coverage

/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
23 changes: 23 additions & 0 deletions e2e/cookies.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test, expect } from '@playwright/test';

test('load and save cookies', async ({ page }) => {
await page.goto('/');
await expect(
page.getByRole('heading', { name: 'Hello Pacman' }),
).toBeHidden();

await page.getByRole('textbox').fill('Pacman');
await expect(
page.getByRole('heading', { name: 'Hello Pacman' }),
).toBeVisible();

await page.reload();
await expect(
page.getByRole('heading', { name: 'Hello Pacman' }),
).toBeVisible();

await page.getByRole('button', { name: 'Clear' }).click();
await expect(
page.getByRole('heading', { name: 'Hello Pacman' }),
).toBeHidden();
});
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/setup-tests.ts'],
modulePathIgnorePatterns: ['<rootDir>/e2e/'],
collectCoverageFrom: [
'packages/react-cookie/src/**/*.{js,jsx,ts,tsx}',
'packages/universal-cookie/src/**/*.{js,jsx,ts,tsx}',
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@babel/preset-env": "^7.23.7",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@playwright/test": "^1.40.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down Expand Up @@ -38,6 +39,7 @@
"scripts": {
"test": "jest --coverage",
"watch": "jest --watch",
"e2e": "npx playwright test --ui",
"build": "yarn build-universal && yarn build-react && yarn build-express && yarn build-koa && yarn build-demo",
"build-universal": "cd packages/universal-cookie && yarn build",
"build-react": "cd packages/react-cookie && yarn build",
Expand Down
37 changes: 37 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:8080',
trace: 'on-first-retry',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],

webServer: {
command: 'yarn --cwd packages/react-cookie-demo start',
url: 'http://localhost:8080',
reuseExistingServer: !process.env.CI,
},
});
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,13 @@
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@playwright/test@^1.40.1":
version "1.40.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.40.1.tgz#9e66322d97b1d74b9f8718bacab15080f24cde65"
integrity sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==
dependencies:
playwright "1.40.1"

"@rollup/plugin-babel@^6.0.4":
version "6.0.4"
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-6.0.4.tgz#bd698e351fa9aa9619fcae780aea2a603d98e4c4"
Expand Down Expand Up @@ -3271,6 +3278,11 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

[email protected]:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
Expand Down Expand Up @@ -4884,6 +4896,20 @@ pkg-dir@^7.0.0:
dependencies:
find-up "^6.3.0"

[email protected]:
version "1.40.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.40.1.tgz#442d15e86866a87d90d07af528e0afabe4c75c05"
integrity sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==

[email protected]:
version "1.40.1"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.40.1.tgz#a11bf8dca15be5a194851dbbf3df235b9f53d7ae"
integrity sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==
dependencies:
playwright-core "1.40.1"
optionalDependencies:
fsevents "2.3.2"

prettier@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.1.tgz#6ba9f23165d690b6cbdaa88cb0807278f7019848"
Expand Down

0 comments on commit 838bf49

Please sign in to comment.