Skip to content

Commit

Permalink
adds playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
luanrv00 committed Sep 2, 2024
1 parent a5a2039 commit 36ab50f
Show file tree
Hide file tree
Showing 9 changed files with 8,531 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

*storybook.log
*storybook.log
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
3 changes: 3 additions & 0 deletions bin/test_e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
docker compose -f docker/docker-compose.dev.yml --project-directory ivewatched up -d
docker compose -f docker/docker-compose.e2e.yml --project-directory ivewatched up --abort-on-exit
4 changes: 1 addition & 3 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ services:
- 6006:6006
volumes:
- ..:/app
command: sh -c "
\ npm install
\ && npm run dev"
command: sh -c "yarn install && yarn dev"
8 changes: 8 additions & 0 deletions docker/docker-compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
e2e:
image: mcr.microsoft.com/playwright:v1.46.0-jammy
container_name: ivewatched-e2e
working_dir: /app
volumes:
- ..:/app
command: yarn test:e2e
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "next start",
"lint": "next lint",
"storybook": "storybook dev -p 6006 --no-open",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"test:e2e": "playwright test"
},
"dependencies": {
"next": "14.2.7",
Expand All @@ -17,6 +18,7 @@
},
"devDependencies": {
"@chromatic-com/storybook": "^1.8.0",
"@playwright/test": "^1.46.1",
"@storybook/addon-essentials": "^8.2.9",
"@storybook/addon-interactions": "^8.2.9",
"@storybook/addon-links": "^8.2.9",
Expand Down
80 changes: 80 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* 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://127.0.0.1:3000',

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

/* Configure projects for major browsers */
projects: [
// TODO: fix net::ERR_SSL_PROTOCOL_ERROR
// {
// 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: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
18 changes: 18 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('http://app:3000');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Create Next App/);
});

// test('get started link', async ({ page }) => {
// await page.goto('http://app:3000');

// Click the get started link.
//await page.getByRole('link', { name: 'Get started' }).click();

// Expects page to have a heading with the name of Installation.
//await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
//});
Loading

0 comments on commit 36ab50f

Please sign in to comment.