Skip to content

Commit 97258d3

Browse files
authored
test(e2e): introduce cypress for web components & react storybook (#7096)
### Related Ticket(s) Refs #6139 ### Description This PR fully moves the existing `test-e2e` package to a dedicated cypress test setup for web components and react storybooks. A few tests have been included for `masthead`, `locale-modal`, and `leadspace`. They are largely focused on snapshot testing, though percy has been disabled for now as rendering of dynamic states are still not supported in percy for web components (see percy/cli#280). Actual cypress tests can be created now though, and also the current tests uses the built-in cypress screenshot feature: ![image](https://user-images.githubusercontent.com/1641214/132697052-2943ccdf-81c5-450d-999e-c39e557a3d05.png) And video that shows how the tests are run: https://user-images.githubusercontent.com/1641214/132697174-a778c055-d3d8-4e01-877d-bd58c2aa7491.mp4 ### Changelog **New** - Cypress testing for web components and react storybook **Changed** - disabled video recording by default to speed up tests **Removed** - Removed `test-e2e` package
1 parent 8641ad2 commit 97258d3

File tree

48 files changed

+1979
-1512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1979
-1512
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ packages/react/ssr-tests/nextjs/.next
1212
packages/react/src/internal/vendor
1313
packages/react/tests/e2e/dist
1414
packages/react/tests/e2e/cypress
15+
packages/react/tests/e2e-storybook/cypress
1516

1617
# storybook-addon-theme
1718
packages/storybook-addon-theme/es
@@ -59,3 +60,5 @@ packages/web-components/storybook-static
5960
packages/web-components/storybook-static-react
6061
packages/web-components/src/internal/vendor
6162
packages/web-components/tests/e2e/dist
63+
packages/web-components/tests/e2e/cypress
64+
packages/web-components/tests/e2e-storybook/cypress

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
{
106106
"files": [
107107
"packages/react/tests/e2e/**/*.e2e.js",
108-
"packages/react/tests/e2e/**/*.cdn.e2e.js"
108+
"packages/react/tests/e2e/**/*.cdn.e2e.js",
109+
"packages/react/src/components/**/*.e2e.js"
109110
],
110111
"extends": [
111112
"plugin:cypress/recommended"

packages/react/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ DDS_AUDIO_PLAYER=<Boolean flag to turn on/off the Audio Player>
2727

2828
# Selenium
2929
SELENIUM_HOST=<Host URL to test, e.g. https://www.ibm.com/standards/carbon/react>
30+
31+
# Storybook e2e host
32+
C4IBM_E2E_STORYBOOK_HOST=<Host to prepend to e2e tests>

packages/react/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ src/internal/vendor
1414
# e2e tests
1515
tests/e2e/cypress/screenshots
1616
tests/e2e/cypress/videos
17+
tests/e2e-storybook/cypress/screenshots
18+
tests/e2e-storybook/cypress/videos

packages/react/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@
3737
"storybook": "start-storybook -p 9000",
3838
"test:e2e:build": "node ./tests/e2e/build/build-examples.js",
3939
"test:e2e:run": "http-server -c-1 tests/e2e/dist --silent",
40-
"test:e2e:test": "start-server-and-test 'yarn test:e2e:run' 8080 'percy exec --config tests/e2e/.percy.json -- cypress run --config-file tests/e2e/cypress.json'",
41-
"test:e2e:test:no-percy": "start-server-and-test 'yarn test:e2e:run' 8080 'cypress run --config-file tests/e2e/cypress.json'",
40+
"test:e2e:test": "start-server-and-test 'yarn test:e2e:run' 8080 'percy exec --config tests/e2e/.percy.json -- cypress run --config video=false --config-file tests/e2e/cypress.json'",
41+
"test:e2e:test:no-percy": "start-server-and-test 'yarn test:e2e:run' 8080 'cypress run --config video=false --config-file tests/e2e/cypress.json'",
42+
"test:e2e-storybook:run": "http-server -c-1 storybook-static --silent -p 8081",
43+
"test:e2e-storybook:test": "start-server-and-test 'yarn test:e2e-storybook:run' 8081 'percy exec --config tests/e2e-storybook/.percy.json -- cypress run --config video=false --config-file tests/e2e-storybook/cypress.json'",
44+
"test:e2e-storybook:test:no-percy": "start-server-and-test 'yarn test:e2e-storybook:run' 8081 'cypress run --config video=false --config-file tests/e2e-storybook/cypress.json'",
45+
"test:e2e-storybook:test:no-percy:with-video": "start-server-and-test 'yarn test:e2e-storybook:run' 8081 'cypress run --config-file tests/e2e-storybook/cypress.json'",
4246
"test:unit": "jest",
4347
"test:unit:updateSnapshot": "jest -u",
4448
"test:a11y": "gulp test:a11y",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Copyright IBM Corp. 2021
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/**
9+
* Sets the host to run tests
10+
*
11+
* @type {string|string}
12+
* @private
13+
*/
14+
const _host =
15+
(process && process.env.C4IBM_E2E_STORYBOOK_HOST) || 'http://localhost:8081';
16+
17+
/**
18+
* Sets the correct path
19+
*
20+
* @type {string}
21+
* @private
22+
*/
23+
const _path = '/iframe.html?id=components-callout-quote--default';
24+
25+
/* eslint-disable cypress/no-unnecessary-waiting */
26+
describe('CalloutQuote | default', () => {
27+
it('should load the g100 theme', () => {
28+
cy.visit(`${_host}/${_path}&theme=g100`);
29+
cy.viewport(1280, 780);
30+
31+
cy.window().then(win => {
32+
win.document.documentElement.setAttribute(
33+
'storybook-carbon-theme',
34+
'g100'
35+
);
36+
cy.wait(500);
37+
cy.screenshot();
38+
39+
// Take a snapshot for visual diffing
40+
cy.percySnapshot('CalloutQuote | default | g100 theme', {
41+
widths: [1280],
42+
});
43+
});
44+
});
45+
46+
it('should load the g90 theme', () => {
47+
cy.visit(`${_host}/${_path}&theme=g90`);
48+
cy.viewport(1280, 780);
49+
50+
cy.window().then(win => {
51+
win.document.documentElement.setAttribute(
52+
'storybook-carbon-theme',
53+
'g90'
54+
);
55+
cy.wait(500);
56+
57+
cy.screenshot();
58+
// Take a snapshot for visual diffing
59+
cy.percySnapshot('CalloutQuote | default | g90 theme', {
60+
widths: [1280],
61+
});
62+
});
63+
});
64+
65+
it('should load the g10 theme', () => {
66+
cy.visit(`${_host}/${_path}&theme=g10`);
67+
cy.viewport(1280, 780);
68+
69+
cy.window().then(win => {
70+
win.document.documentElement.setAttribute(
71+
'storybook-carbon-theme',
72+
'g10'
73+
);
74+
cy.wait(500);
75+
76+
cy.screenshot();
77+
// Take a snapshot for visual diffing
78+
cy.percySnapshot('CalloutQuote | default | g10 theme', {
79+
widths: [1280],
80+
});
81+
});
82+
});
83+
});

0 commit comments

Comments
 (0)