Skip to content
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

test: adding playwright chromatic + initial test #2986

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,79 @@ on:
paths:
- "stories/**"
- "packages/**"
- "website/**"
deployment_status:
permissions:
id-token: write
contents: read


jobs:
playwright:
name: Playwright Tests with Chromatic on ${{ github.event.deployment_status.environment }}
if: github.event.pull_request.draft == false && github.repository == 'FormidableLabs/victory' && github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.49.0-jammy
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup
with:
node-version: 18.x

- name: Build Victory
run: pnpm run build:lib:esm

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Install Test Dependencies
run: pnpm install

- name: Install Playwright
run: pnpm playwright install --with-deps

- name: Run Playwright Tests
run: npx playwright test
env:
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-results
path: ./playwright-report
retention-days: 30

chromatic:
name: Run Chromatic
needs: playwright
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ./.github/actions/setup
with:
node-version: 18.x

- name: Build Victory
run: pnpm run build:lib:esm

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Install dependencies
run: pnpm install

- name: Run Chromatic
uses: chromaui/action@latest
with:
playwright: true
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

storybook:
name: Storybook Publish
if: github.event.pull_request.draft == false && github.repository == 'FormidableLabs/victory'
runs-on: ubuntu-latest
Expand All @@ -32,6 +102,12 @@ jobs:
- name: Build Victory
run: pnpm run build:lib:esm

- name: Download Playwright test results
uses: actions/download-artifact@v4
with:
name: playwright-results
path: ./playwright-report

- name: Publish to Chromatic
uses: chromaui/action@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ tmp
.yarn/*
.yarnrc*
.pnp.*
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
11 changes: 11 additions & 0 deletions e2e/introduction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test, expect } from '@chromatic-com/playwright'
import { IntroPage } from './pages/IntroductionPage';

test('should load intro page', async ({ page }) => {
const introPage = new IntroPage(page)
await introPage.goto()
await expect(introPage.pageTitle).toBeVisible()
await expect(introPage.homePageIcon).toBeVisible()
await expect(introPage.breadcrumbsLabel('Introduction')).toBeVisible()
await expect(introPage.breadcrumbsLabel('Getting Started')).toBeVisible()
})
20 changes: 20 additions & 0 deletions e2e/pages/IntroductionPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Locator, Page } from '@playwright/test'

export class IntroPage {
readonly page: Page
readonly breadcrumbsLabel: (labelName: string) => Locator
readonly homePageIcon: Locator
readonly pageTitle: Locator

constructor(page: Page) {
this.page = page
this.breadcrumbsLabel = (labelname: string) =>
this.page.getByLabel('Breadcrumbs').getByText(labelname)
this.homePageIcon = this.page.getByLabel('Home page')
this.pageTitle = this.page.getByRole('heading', { name: 'Getting Started with Victory' })
}

async goto() {
await this.page.goto('/open-source/victory/docs/introduction/')
}
}
13 changes: 13 additions & 0 deletions e2e/pages/components/FooterArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Locator, Page } from '@playwright/test'

export class FooterPage {
readonly page: Page
readonly nearformLogo: Locator
readonly copyrightText: Locator

constructor(page: Page) {
this.page = page
this.nearformLogo = this.page.getByRole('link', { name: 'Nearform logo' })
this.copyrightText = this.page.getByText('Copyright © 2013-2024 Nearform')
}
}
17 changes: 17 additions & 0 deletions e2e/pages/components/HeaderArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Locator, Page } from '@playwright/test'

export class HeaderPage {
readonly page: Page
readonly leftSideNavLink: (linkName: string) => Locator
readonly rightSideNavLink: (linkName: string) => Locator
readonly searchInput: Locator

constructor(page: Page) {
this.page = page
this.leftSideNavLink = (linkName: string) =>
this.page.getByRole('link', { name: linkName })
this.rightSideNavLink = (linkName: string) =>
this.page.getByLabel(linkName)
this.searchInput = this.page.getByPlaceholder('Search')
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"@babel/preset-react": "7.23.3",
"@babel/preset-typescript": "7.23.3",
"@changesets/cli": "^2.24.1",
"@chromatic-com/playwright": "^0.10.0",
"@chromatic-com/storybook": "^3.2.2",
"@eslint/js": "^9.14.0",
"@playwright/test": "^1.49.0",
"@storybook/addon-essentials": "^8.4.1",
"@storybook/addon-storysource": "^8.4.1",
"@storybook/addon-webpack5-compiler-swc": "1.0.5",
Expand All @@ -55,7 +57,7 @@
"babel-loader": "9.1.3",
"babel-plugin-module-resolver": "5.0.0",
"babel-preset-react-native": "4.0.1",
"chromatic": "^11.16.3",
"chromatic": "^11.16.4",
"concurrently": "^9.0.1",
"cpx2": "^4.2.0",
"cross-env": "^7.0.3",
Expand Down Expand Up @@ -133,6 +135,7 @@
"start:docs": "wireit",
"check": "wireit",
"check:debug": "cross-env WIREIT_PARALLEL=1 pnpm check",
"chromatic": "chromatic --playwright --exit-zero-on-changes",
"clean:build": "rimraf coverage \"packages/*/{dist,es,lib}\"",
"clean:cache": "wireit",
"clean:cache:lint": "rimraf .eslintcache \"{demo,packages}/*/.eslintcache\"",
Expand Down
79 changes: 79 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

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

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
/* 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: process.env.PLAYWRIGHT_TEST_BASE_URL ?? "http://localhost:5855",

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

/* Configure projects for major browsers */
projects: [
{
testDir: './e2e',
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,
// },
});
Loading
Loading