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

Testing setup #1850

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d6df75d
chore: setup playwright
sankalp2110 Jan 24, 2024
4c36bff
chore: setup test flow from json
sankalp2110 Feb 5, 2024
2c59008
chore: modified json file according to the stories of correcponding e…
sankalp2110 Feb 6, 2024
763a90b
chore: the data loop from the json file is executed
sankalp2110 Feb 9, 2024
602cb45
fix: only test on chrome and not on 3 browsers
akash3gtm Feb 23, 2024
e2d82f4
fix: ts-ignore temp solution
akash3gtm Feb 23, 2024
7f8cea0
chore: update test snapshot and folder name
akash3gtm Feb 28, 2024
5fdfd8d
fix: filename ts -> js
akash3gtm Feb 28, 2024
f303e53
chore: new scripts for test and update
akash3gtm Feb 28, 2024
0bc9cbc
chore: update package json for scripts
akash3gtm Feb 28, 2024
a96d415
chore: added playwright test git action
akash3gtm Feb 28, 2024
3d6f1a2
fix: spelling
akash3gtm Feb 28, 2024
f6f0651
fix: folder dir
akash3gtm Feb 28, 2024
72932cf
fix: os dir
akash3gtm Feb 28, 2024
7528a7f
fix: os support
akash3gtm Feb 28, 2024
71f9faa
Merge branch 'patch' of github.com:gluestack/gluestack-ui into testin…
akash3gtm Feb 28, 2024
5e88c92
fix: nativewind build issue
akash3gtm Feb 28, 2024
8a94c57
fix: yarn lock update
akash3gtm Feb 28, 2024
d041593
fix: git actions cli
akash3gtm Feb 29, 2024
4f6048a
fix: typing
akash3gtm Feb 29, 2024
85a337f
chore: convert bash to node scripts
akash3gtm Feb 29, 2024
ecfc9a4
fix: update readme for text
akash3gtm Feb 29, 2024
3d549c5
fix: update script commands
akash3gtm Feb 29, 2024
8d0abd2
fix: update git actions
akash3gtm Feb 29, 2024
c754971
chore: need empty dir for playwright test result
akash3gtm Feb 29, 2024
aad55ad
fix: correct path to folder for report
akash3gtm Feb 29, 2024
2a43121
fix: correct path to folder for report
akash3gtm Feb 29, 2024
92d808a
fix: test failure report
akash3gtm Feb 29, 2024
e40328b
fix: test failure report
akash3gtm Feb 29, 2024
0ff978a
chore: added max pixel difference to test
sankalp2110 Mar 5, 2024
2b8d494
chore: added max pixel difference to test with different function
sankalp2110 Mar 5, 2024
0077e26
chore: added max pixel difference to test with different function
sankalp2110 Mar 5, 2024
25b0859
chore: added max pixel difference to test with different function
sankalp2110 Mar 5, 2024
20b7df5
chore: added code to remove the name of file
sankalp2110 Mar 5, 2024
4db4de4
chore: added code to remove the name of file
sankalp2110 Mar 5, 2024
db3d413
fix: ratio of all pixels diff pass
akash3gtm Mar 6, 2024
59e5067
Merge branch 'patch' of github.com:gluestack/gluestack-ui into testin…
akash3gtm Mar 6, 2024
95df0a6
fix: test setup
akash3gtm Mar 6, 2024
aa02386
fix: test setup
akash3gtm Mar 6, 2024
a463d85
fix: test setup
akash3gtm Mar 6, 2024
79ffdea
fix: test setup
akash3gtm Mar 6, 2024
443ece0
chore: changed the max difference ratio to test the github action
sankalp2110 Mar 6, 2024
5db6ce7
chore: snapshot.test.js file updated
sankalp2110 Mar 8, 2024
d788086
chore: snapshot test and snapshot update file completed
sankalp2110 Mar 12, 2024
c34bfa7
chore: snapshot test and snapshot updade done and also added a if con…
sankalp2110 Mar 15, 2024
9d6e8e0
Merge branch 'patch' of github.com:gluestack/gluestack-ui into testin…
akash3gtm Apr 5, 2024
d288b7b
fix: data and gitignore for playwright logs
akash3gtm Apr 5, 2024
975e49e
fix: update test snapshots --default
akash3gtm Apr 5, 2024
21bc8db
fix: updated git action default --all components
akash3gtm Apr 5, 2024
02a5a7f
fix: updated git action default --all components
akash3gtm Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
76 changes: 76 additions & 0 deletions .github/workflows/test-playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Visual Regression Tests

on:
pull_request:
branches:
- patch

concurrency: ${{ github.workflow }}-${{ github.ref || github.run_id }}

jobs:
visual-tests:
name: Test for all components' default story
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies and build the project
run: |
yarn
yarn playwright install --with-deps
yarn build

- name: Create storybook build
run: |
cd example/storybook
yarn build-storybook

- name: Run test
run: |
cd example/storybook
yarn test:screenshot

- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: example/storybook/playwright-report/
overwrite: true
retention-days: 10

- name: Download artifact
if: failure()
uses: actions/download-artifact@v2
with:
name: playwright-report

- name: Extract files
if: failure()
run: unzip playwright-report.zip

- name: Push to GitHub Pages
if: failure()
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./playwright-report

- name: Comment PR
if: failure()
uses: actions/github-script@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueComment = `Playwright report is available [here](https://${{ github.repository }}.github.io/playwright-report/index.html)`
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: issueComment,
})
8 changes: 7 additions & 1 deletion example/storybook/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ lib
.DS_Store

#build
storybook-static/
storybook-static/
/test-results/
/blob-report/

#test-playwright
/playwright-report
/playwright/.cache/``
28 changes: 28 additions & 0 deletions example/storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ Note that this is only necessary for when you add or remove a story file.
```
yarn storybook
```

# Testing

You need to install the playwright browsers using this

```
yarn playwright install --with-deps
```

Then you need create the storybook build using

```
yarn build-storybook
```

Then you can run the tests like this

```
yarn test:screenshot --componentName
```

it takes 2 extra agruments like

```
--componentName=single
and
--componentName=multiple
```
22 changes: 22 additions & 0 deletions example/storybook/__visualTests__/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from '@playwright/test';

test('has box', async ({ page }) => {
// await page.goto('http://localhost:6007/?path=/story/stories-layout-box--box');
await page.goto(
'http://localhost:6007/iframe.html?args=&id=stories-layout-box--box&viewMode=story'
);
expect(await page.screenshot()).toMatchSnapshot();

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

// test('get started link', async ({ page }) => {
// await page.goto('https://playwright.dev/');

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

// // Expects the URL to contain intro.
// await expect(page).toHaveURL(/.*intro/);
// });
6 changes: 5 additions & 1 deletion example/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"build-storybook": "build-storybook",
"release": "release-it",
"test": "jest",
"update-snapshot": "jest -u"
"update-snapshot": "jest -u",
"test:screenshot": "node ./tests/scripts/snapshotTest.js",
"update:screenshot": "node ./tests/scripts/snapshotUpdate.js",
"test:show-report": "yarn playwright show-report"
},
"dependencies": {
"@expo/html-elements": "^0.4.2",
Expand Down Expand Up @@ -75,6 +78,7 @@
"@babel/preset-typescript": "^7.18.6",
"@babel/traverse": "^7.20.13",
"@babel/types": "^7.20.7",
"@playwright/test": "^1.41.0",
"@storybook/addon-actions": "^6.5.14",
"@storybook/addon-controls": "^6.5.14",
"@storybook/addon-docs": "^6.5.15",
Expand Down
92 changes: 92 additions & 0 deletions example/storybook/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* 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',
},

/* 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: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
// expect: {
// // Maximum time expect() should wait for the condition to be met.
// timeout: 5000,

// toHaveScreenshot: {
// // An acceptable amount of pixels that could be different, unset by default.
// maxDiffPixels: 10,
// },

// toMatchSnapshot: {
// // An acceptable ratio of pixels that are different to the
// // total amount of pixels, between 0 and 1.
// maxDiffPixelRatio: 0.011,
// },
// },

/* 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