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(e2e): introduce cypress for web components & react storybook #7096

Merged
merged 14 commits into from
Sep 10, 2021
Merged
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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ packages/react/ssr-tests/nextjs/.next
packages/react/src/internal/vendor
packages/react/tests/e2e/dist
packages/react/tests/e2e/cypress
packages/react/tests/e2e-storybook/cypress

# storybook-addon-theme
packages/storybook-addon-theme/es
Expand Down Expand Up @@ -59,3 +60,5 @@ packages/web-components/storybook-static
packages/web-components/storybook-static-react
packages/web-components/src/internal/vendor
packages/web-components/tests/e2e/dist
packages/web-components/tests/e2e/cypress
packages/web-components/tests/e2e-storybook/cypress
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
{
"files": [
"packages/react/tests/e2e/**/*.e2e.js",
"packages/react/tests/e2e/**/*.cdn.e2e.js"
"packages/react/tests/e2e/**/*.cdn.e2e.js",
"packages/react/src/components/**/*.e2e.js"
],
"extends": [
"plugin:cypress/recommended"
Expand Down
3 changes: 3 additions & 0 deletions packages/react/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ DDS_AUDIO_PLAYER=<Boolean flag to turn on/off the Audio Player>

# Selenium
SELENIUM_HOST=<Host URL to test, e.g. https://www.ibm.com/standards/carbon/react>

# Storybook e2e host
C4IBM_E2E_STORYBOOK_HOST=<Host to prepend to e2e tests>
2 changes: 2 additions & 0 deletions packages/react/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ src/internal/vendor
# e2e tests
tests/e2e/cypress/screenshots
tests/e2e/cypress/videos
tests/e2e-storybook/cypress/screenshots
tests/e2e-storybook/cypress/videos
8 changes: 6 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
"storybook": "start-storybook -p 9000",
"test:e2e:build": "node ./tests/e2e/build/build-examples.js",
"test:e2e:run": "http-server -c-1 tests/e2e/dist --silent",
"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'",
"test:e2e:test:no-percy": "start-server-and-test 'yarn test:e2e:run' 8080 'cypress run --config-file tests/e2e/cypress.json'",
"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'",
"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'",
"test:e2e-storybook:run": "http-server -c-1 storybook-static --silent -p 8081",
"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'",
"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'",
"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'",
"test:unit": "jest",
"test:unit:updateSnapshot": "jest -u",
"test:a11y": "gulp test:a11y",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright IBM Corp. 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* Sets the host to run tests
*
* @type {string|string}
* @private
*/
const _host =
(process && process.env.C4IBM_E2E_STORYBOOK_HOST) || 'http://localhost:8081';

/**
* Sets the correct path
*
* @type {string}
* @private
*/
const _path = '/iframe.html?id=components-callout-quote--default';

/* eslint-disable cypress/no-unnecessary-waiting */
describe('CalloutQuote | default', () => {
it('should load the g100 theme', () => {
cy.visit(`${_host}/${_path}&theme=g100`);
cy.viewport(1280, 780);

cy.window().then(win => {
win.document.documentElement.setAttribute(
'storybook-carbon-theme',
'g100'
);
cy.wait(500);
cy.screenshot();

// Take a snapshot for visual diffing
cy.percySnapshot('CalloutQuote | default | g100 theme', {
widths: [1280],
});
});
});

it('should load the g90 theme', () => {
cy.visit(`${_host}/${_path}&theme=g90`);
cy.viewport(1280, 780);

cy.window().then(win => {
win.document.documentElement.setAttribute(
'storybook-carbon-theme',
'g90'
);
cy.wait(500);

cy.screenshot();
// Take a snapshot for visual diffing
cy.percySnapshot('CalloutQuote | default | g90 theme', {
widths: [1280],
});
});
});

it('should load the g10 theme', () => {
cy.visit(`${_host}/${_path}&theme=g10`);
cy.viewport(1280, 780);

cy.window().then(win => {
win.document.documentElement.setAttribute(
'storybook-carbon-theme',
'g10'
);
cy.wait(500);

cy.screenshot();
// Take a snapshot for visual diffing
cy.percySnapshot('CalloutQuote | default | g10 theme', {
widths: [1280],
});
});
});
});
Loading