forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(project): add e2e test support with playwright (carbon-design-sy…
…stem#11302) * test(project): add e2e test support with playwright * ci(workflows): add vrt-next job to ci workflow * ci(workflows): update percy to be parallel * test(playwright): update config * chore(project): update percy cli * chore(project): update @percy/storybook * chore(project): remove cypress from react * ci(workflows): move vrt-next to vrt * test(e2e): add snapshotStory utility * test(e2e): update vrt job to run only in chromium and on vrt tests * test(breadcrumb): add playwright tests, percy snapshots * refactor(e2e): update test-utils for snapshots and stories * test(e2e): add percy config * docs(testing): add docs for e2e vrt * refactor(snapshot): update id for percy snapshots * refactor(snapshot): update id for percy snapshots * chore(ci): add vrt task to summarize matrix jobs Co-authored-by: Taylor Jones <[email protected]>
- Loading branch information
1 parent
4f855c4
commit 2270ef7
Showing
146 changed files
with
928 additions
and
1,237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,6 @@ package-lock.json | |
|
||
# Accessibility Verification Testing | ||
.avt/ | ||
|
||
# Playwright | ||
.playwright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
snapshot: | ||
widths: | ||
- 360 | ||
- 672 | ||
- 1366 | ||
minHeight: 1024 |
Binary file not shown.
Binary file renamed
BIN
+31.2 KB
...ator-npm-7.17.7-43f079aca0-e7344b9b45.zip → ...ator-npm-7.17.9-314134f0b2-afbdd4afbf.zip
Binary file not shown.
Binary file removed
BIN
-3.79 KB
.yarn/cache/@babel-helper-function-name-npm-7.16.7-aa24c7b296-fc77cbe7b1.zip
Binary file not shown.
Binary file added
BIN
+3.84 KB
.yarn/cache/@babel-helper-function-name-npm-7.17.9-baf558fead-a59b2e5af5.zip
Binary file not shown.
Binary file removed
BIN
-2.66 KB
.yarn/cache/@babel-helper-get-function-arity-npm-7.16.7-987b1b1bed-25d969fb20.zip
Binary file not shown.
Binary file renamed
BIN
+28.8 KB
...pers-npm-7.17.8-eac3af0452-463dad5811.zip → ...pers-npm-7.17.9-68ae2c1f37-3c6db861e4.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.74 KB
.yarn/cache/@babel-plugin-transform-modules-commonjs-npm-7.16.8-b70dd72ac5-c0ac00f545.zip
Binary file not shown.
Binary file renamed
BIN
+48.8 KB
...erse-npm-7.17.3-c2bff3e671-780d7ecf71.zip → ...erse-npm-7.17.9-5a1b3f046c-d907c71d16.zip
Binary file not shown.
Binary file removed
BIN
-4.08 KB
.yarn/cache/@cypress-mount-utils-npm-1.0.2-2bab03bc63-fc3ad2d4bb.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-21.6 KB
.yarn/cache/@cypress-webpack-dev-server-npm-1.8.4-8a9506e39c-cfe2638b95.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-7.47 KB
.yarn/cache/@percy-cli-build-npm-1.0.0-beta.71-a2b755f0b5-e6e8e15989.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-6.21 KB
.yarn/cache/@percy-cli-command-npm-1.0.0-beta.71-be4a50a36f-8efa06765b.zip
Binary file not shown.
Binary file removed
BIN
-20.6 KB
.yarn/cache/@percy-cli-command-npm-1.0.0-beta.76-f00a36cc70-a6506178db.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-7.99 KB
.yarn/cache/@percy-cli-config-npm-1.0.0-beta.71-3f45186076-31d670f799.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-10.9 KB
.yarn/cache/@percy-cli-exec-npm-1.0.0-beta.71-eef9fff77a-bacf458bc4.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-14.4 KB
.yarn/cache/@percy-cli-snapshot-npm-1.0.0-beta.71-d54f36af6b-b026219478.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-8.4 KB
.yarn/cache/@percy-cli-upload-npm-1.0.0-beta.71-8c1f89039b-b28f68703a.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-13.6 KB
.yarn/cache/@percy-client-npm-1.0.0-beta.71-5bfd648afc-77065f8c9d.zip
Binary file not shown.
Binary file removed
BIN
-14 KB
.yarn/cache/@percy-client-npm-1.0.0-beta.76-e1ffd9303b-c09f3e134d.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-14.4 KB
.yarn/cache/@percy-config-npm-1.0.0-beta.71-3e74fe4fc5-ac09e5e884.zip
Binary file not shown.
Binary file removed
BIN
-14.7 KB
.yarn/cache/@percy-config-npm-1.0.0-beta.76-45c084649f-98b1c8544c.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-39.9 KB
.yarn/cache/@percy-core-npm-1.0.0-beta.71-0f8574f2ea-a9e71ddb4d.zip
Binary file not shown.
Binary file removed
BIN
-45.5 KB
.yarn/cache/@percy-core-npm-1.0.0-beta.76-8168473146-2794e3f336.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-16.2 KB
.yarn/cache/@percy-logger-npm-1.0.0-beta.71-cac38d4169-9e279cbdc4.zip
Binary file not shown.
Binary file removed
BIN
-16.3 KB
.yarn/cache/@percy-logger-npm-1.0.0-beta.76-771fca1eae-9d5744fd8c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-21.4 KB
.yarn/cache/@percy-sdk-utils-npm-1.0.0-beta.76-f44b230d66-f32ead2b54.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-8.52 KB
.yarn/cache/@storybook-client-logger-npm-6.4.19-7602ad8f31-06eb583d05.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-12.4 KB
.yarn/cache/@testing-library-cypress-npm-8.0.2-146130f856-41561f68d3.zip
Binary file not shown.
Binary file removed
BIN
-5.56 KB
.yarn/cache/@types-sinonjs__fake-timers-npm-8.1.1-95ac9b59b5-ca09d54d47.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-7.63 KB
.yarn/cache/content-disposition-npm-0.5.2-1f3e0caef2-298d7da632.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-29.2 KB
.yarn/cache/cypress-real-events-npm-1.7.0-f90a03f040-92981b05c4.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-7.36 KB
.yarn/cache/find-yarn-workspace-root-npm-1.2.1-91f28f6b79-a8f4565fb1.zip
Binary file not shown.
Binary file removed
BIN
-7.43 KB
.yarn/cache/find-yarn-workspace-root-npm-2.0.0-e58a501607-fa5ca8f9d0.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-2.82 KB
.yarn/cache/is-installed-globally-npm-0.4.0-a30dd056c7-3359840d59.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# Testing | ||
|
||
<!-- prettier-ignore-start --> | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
## Table of Contents | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> <!-- prettier-ignore-end --> | ||
|
||
## Overview | ||
|
||
| Task | Command | | ||
| :---------------------------------------------------- | :------------------------------------------------- | | ||
| Run package test | `yarn test:e2e` | | ||
| Run playwright tests | `yarn playwright test` | | ||
| Run a specific playwright test | `yarn playwright test path/to/test-e2e.js` | | ||
| Run playwright tests in a specific browser | `yarn playwright test --browser=chromium` | | ||
| Run playwright tests in a specific project | `yarn playwright test --project=chromium` | | ||
| Debug playwright tests | `yarn playwright test --debug` | | ||
| Run playwright with browser visible | `yarn playwright test --project=chromium --headed` | | ||
| Run playwright tests that match a specific tag | `yarn playwright test --grep @tag-name` | | ||
| Run playwright tests that do not match a specific tag | `yarn playwright test --grep-invert @tag-name` | | ||
|
||
## End-to-end | ||
|
||
We use our end-to-end tests to verify the packaging of libraries along with the | ||
look and behavior of components in our design system. End-to-end tests for | ||
packages are run using Jest, components are run using Playwright. | ||
|
||
### Playwright | ||
|
||
We use Playwright to run end-to-end tests against our components in our Design | ||
System. We also use it in other situations to prevent visual regressions, like | ||
in our elements site. | ||
|
||
These tests are authored within the `e2e` directory and match the file pattern: | ||
`*-test.e2e.js`. | ||
|
||
#### Developing | ||
|
||
When working with Playwright locally, it's important to start up the service | ||
that you're testing against. For components in React, this will mean starting up | ||
the React storybook locally by doing the following from the root of the project: | ||
|
||
```bash | ||
cd packages/react | ||
yarn storybook | ||
``` | ||
|
||
One the storybook is loaded, you can run tests against is using the storybook | ||
test-utils found in `e2e/test-utils/storybook`. A common use-case for testing a | ||
component is to use Percy to take a snapshot of a component in a particular | ||
theme from a specific story in storybook. | ||
|
||
You can do this by writing the following: | ||
|
||
```js | ||
// e2e/components/component/component-test.e2e.js | ||
|
||
'use strict'; | ||
|
||
const { test } = require('@playwright/test'); | ||
const { themes } = require('../../test-utils/env'); | ||
const { snapshotStory } = require('../../test-utils/storybook'); | ||
|
||
test('component-name @vrt', ({ page }) => { | ||
await snapshotStory(page, { | ||
component: 'component', | ||
story: 'story-name', | ||
theme: 'white', | ||
}); | ||
}); | ||
``` | ||
|
||
You can test this component in multiple themes by writing the following: | ||
|
||
```js | ||
// e2e/components/component/component-test.e2e.js | ||
|
||
'use strict'; | ||
|
||
const { test } = require('@playwright/test'); | ||
const { themes } = require('../../test-utils/env'); | ||
const { snapshotStory } = require('../../test-utils/storybook'); | ||
|
||
test.describe('component-name @vrt', () => { | ||
themes.forEach((theme) => { | ||
test(theme, async ({ page }) => { | ||
await snapshotStory(page, { | ||
component: 'component', | ||
story: 'story-name', | ||
theme, | ||
}); | ||
}); | ||
}); | ||
}); | ||
``` | ||
|
||
If you would like to debug or interact with the test suite, you can use | ||
Playwright's VS Code integration or run `yarn playwright test` with the | ||
`--debug` flag to open up the inspector. This will allow you to go through the | ||
test step-by-step to debug what's going on. It will also allow you to interact | ||
with the page to quickly find selectors you can use to find items to run tests | ||
against. | ||
|
||
#### Working with snapshots locally | ||
|
||
Sometimes you'll want to debug snapshots locally instead of relying on an | ||
externaly service to get feedback. To do so, you can use the | ||
`ENABLE_LOCAL_SNAPSHOTS` environment variable to store snapshots locally. Almost | ||
any playwright command you run can be prefixed with this value in order to store | ||
screenshots locally. | ||
|
||
```bash | ||
ENABLE_LOCAL_SNAPSHOTS=1 yarn playwright test --project chromium --grep @vrt component-test.e2e.js | ||
``` | ||
|
||
**Note: it's important to narrow down tests in order to not generate a lot of | ||
screenshots locally** | ||
|
||
The first time you'll run this command, it will need to generate the baseline | ||
snapshots for this component. The second time you run it, it will compare the | ||
snapshots for the current page with what is stored in the screenshot. If the two | ||
do not match, playwright will report a failure and will provide a link to the | ||
diff image on your machine. | ||
|
||
## FAQ | ||
|
||
### Why am I seeing `browserType.launch: Executable doesn't exist at ../path`? | ||
|
||
The browser executables need to be installed so that playwright can run tests | ||
inside chromium, firefox, etc. They can be installed by running | ||
`yarn playwright install` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { test } = require('@playwright/test'); | ||
const { themes } = require('../../test-utils/env'); | ||
const { snapshotStory } = require('../../test-utils/storybook'); | ||
|
||
test.describe('accordion @vrt', () => { | ||
themes.forEach((theme) => { | ||
test(theme, async ({ page }) => { | ||
await snapshotStory(page, { | ||
component: 'accordion', | ||
story: 'accordion-story', | ||
theme, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { test } = require('@playwright/test'); | ||
const { themes } = require('../../test-utils/env'); | ||
const { snapshot } = require('../../test-utils/snapshot'); | ||
const { snapshotStory, visitStory } = require('../../test-utils/storybook'); | ||
|
||
test.describe('breadcrumb @vrt', () => { | ||
themes.forEach((theme) => { | ||
test.describe(theme, () => { | ||
test('breadcrumb', async ({ page }) => { | ||
await snapshotStory(page, { | ||
component: 'breadcrumb', | ||
story: 'breadcrumb-story', | ||
theme, | ||
}); | ||
}); | ||
|
||
test('breadcrumb with overflow menu', async ({ page }) => { | ||
await visitStory(page, { | ||
component: 'breadcrumb', | ||
story: 'breadcrumb-with-overflow-menu', | ||
theme, | ||
}); | ||
await page | ||
.locator('button[aria-haspopup="true"][aria-expanded="false"]') | ||
.click(); | ||
await snapshot(page, { | ||
component: 'breadcrumb', | ||
story: 'breadcrumb-with-overflow-menu', | ||
theme, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const themes = ['white', 'g10', 'g90', 'g100']; | ||
|
||
module.exports = { | ||
themes, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const percySnapshot = require('@percy/playwright'); | ||
const { expect } = require('@playwright/test'); | ||
|
||
/** | ||
* Snapshot a page and report it either to Percy or record these snapshots | ||
* locally to compare manually | ||
*/ | ||
async function snapshot(page, context) { | ||
const id = getSnapshotId(context); | ||
|
||
if (process.env.ENABLE_LOCAL_SNAPSHOTS) { | ||
expect(await page.screenshot()).toMatchSnapshot(`${id}.png`); | ||
} else { | ||
await percySnapshot(page, id); | ||
} | ||
} | ||
|
||
/** | ||
* Get a unique identifier for the given context. If the context is a string, it | ||
* already represents a valid identifier and will be returned | ||
*/ | ||
function getSnapshotId(context) { | ||
if (typeof context === 'string') { | ||
return context; | ||
} | ||
|
||
const { component, story, theme } = context; | ||
return serialize({ | ||
theme, | ||
component, | ||
story, | ||
}); | ||
} | ||
|
||
/** | ||
* Serialize a flat object into a string | ||
*/ | ||
function serialize(object) { | ||
// If local snapshots are enabled, encode this object into a valid filename | ||
if (process.env.ENABLE_LOCAL_SNAPSHOTS) { | ||
return Object.keys(object).reduce((acc, key, index) => { | ||
if (index === 0) { | ||
return `${key}=${object[key]}`; | ||
} | ||
return `${acc}-${key}=${object[key]}`; | ||
}, ''); | ||
} | ||
|
||
return Object.keys(object).reduce((acc, key, index) => { | ||
if (index === 0) { | ||
return `${key}: ${object[key]}`; | ||
} | ||
return `${acc}, ${key}: ${object[key]}`; | ||
}, ''); | ||
} | ||
|
||
module.exports = { | ||
snapshot, | ||
getSnapshotId, | ||
}; |
Oops, something went wrong.