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

Experiment/add cypress for e2e tests #8282

Merged
merged 35 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2419d3f
chore(react): add cypress and initial accordion test
joshblack Feb 26, 2021
443c020
Merge branch 'master' of github.com:carbon-design-system/carbon into …
joshblack Feb 26, 2021
978d2bd
wip: check in work
tay1orjones Apr 1, 2021
c15166e
wip: check in work
tay1orjones Apr 1, 2021
b021aa0
chore: check in work
tay1orjones Apr 22, 2021
018074c
chore(project): run cypress in ci
tay1orjones Apr 23, 2021
37765bf
testing(accordion): enable percy snapshots, configure cypress eslint …
tay1orjones Apr 23, 2021
ceb4b6e
chore(eslint): revert readme changes
tay1orjones Apr 23, 2021
3c2f564
chore(cli): move '@percy/cli' dep from react to cli package
tay1orjones Apr 23, 2021
0222256
chore(yarn): include cache from '@percy/cli' install
tay1orjones Apr 23, 2021
e436cc3
Merge branch 'main' of github.com:carbon-design-system/carbon into ex…
tay1orjones Apr 23, 2021
efb7b0c
Merge branch 'main' into experiment/add-cypress-for-e2e-tests
tay1orjones Apr 23, 2021
0e32658
chore(project): update yarn cache checksums
tay1orjones Apr 23, 2021
c8cc628
chore: clear cache
tay1orjones Apr 23, 2021
5307b80
chore: add cache
tay1orjones Apr 23, 2021
691b7d5
chore: fix yarn cache
tay1orjones Apr 23, 2021
6a93184
chore: i think i finally fixed the cache
tay1orjones Apr 23, 2021
ee90ef2
fix(cli): modify command for percy e2e
tay1orjones Apr 26, 2021
c610735
fix(project): update to cypress v7, retool configuration
tay1orjones Apr 27, 2021
0e63819
chore(project): move percy cli dep to root
tay1orjones Apr 28, 2021
960bfb2
Merge branch 'main' into experiment/add-cypress-for-e2e-tests
tay1orjones Apr 28, 2021
a179e6b
chore(project): turn off cypress videos and snapshots in CI
tay1orjones Apr 28, 2021
b9040e8
Merge branch 'experiment/add-cypress-for-e2e-tests' of github.com:car…
tay1orjones Apr 28, 2021
93e75bf
Merge branch 'main' of github.com:carbon-design-system/carbon into ex…
tay1orjones Apr 29, 2021
3d44462
chore(cypress): update command syntax
tay1orjones May 3, 2021
2b5a792
chore(cypress): update command syntax
tay1orjones May 3, 2021
3517357
Merge branch 'main' of github.com:carbon-design-system/carbon into ex…
tay1orjones May 4, 2021
f61baa3
fix(ci): correct command for jest e2e tests
tay1orjones May 5, 2021
5cc52ce
Merge branch 'main' into experiment/add-cypress-for-e2e-tests
tay1orjones May 5, 2021
26eb55f
Merge branch 'main' into experiment/add-cypress-for-e2e-tests
tay1orjones May 11, 2021
5b37942
Merge branch 'main' of github.com:carbon-design-system/carbon into ex…
tay1orjones May 13, 2021
2005c89
Merge branch 'main' of github.com:carbon-design-system/carbon into ex…
tay1orjones May 14, 2021
6f88b6d
Merge branch 'main' into experiment/add-cypress-for-e2e-tests
tay1orjones May 14, 2021
47a2b48
chore: run yarn dedupe
tay1orjones May 14, 2021
18b87f2
Merge branch 'experiment/add-cypress-for-e2e-tests' of github.com:car…
tay1orjones May 14, 2021
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
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.
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.
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.
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.
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.
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.
1 change: 1 addition & 0 deletions config/eslint-config-carbon/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'eslint:recommended',
require.resolve('./rules/best-practices'),
require.resolve('./plugins/jsdoc'),
require.resolve('./plugins/cypress'),
],
rules: {
// Handle cases where we are destructuring but may not be using the initial
Expand Down
1 change: 1 addition & 0 deletions config/eslint-config-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"eslint-config-airbnb": "^18.0.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-jsdoc": "^20.3.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
Expand Down
18 changes: 18 additions & 0 deletions config/eslint-config-carbon/plugins/cypress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright IBM Corp. 2018, 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';

module.exports = {
plugins: ['eslint-plugin-cypress'],
overrides: [
{
files: ['*-test.e2e.js'],
extends: ['plugin:cypress/recommended'],
},
],
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"lint:styles": "stylelint '**/*.{css,scss}' --report-needless-disables --report-invalid-scope-disables",
"sync": "carbon-cli sync",
"test": "cross-env BABEL_ENV=test jest",
"test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'"
"test:e2e:jest": "cross-env BABEL_ENV=test jest --testPathPattern='e2e/' --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'",
"test:e2e:cypress": "lerna run test:e2e:cypress"
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved
},
"resolutions": {
"ast-types": "^0.14.0",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@octokit/plugin-retry": "^3.0.7",
"@octokit/plugin-throttling": "^2.6.0",
"@octokit/rest": "^16.28.1",
"@percy/cli": "^1.0.0-beta.48",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/ci-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async function check(args, env) {
const tasks = [
`yarn carbon-cli check --ignore '**/@(node_modules|examples|components|react|fixtures)/**' 'packages/**/*.scss'`,
`cross-env BABEL_ENV=test yarn test --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
`cross-env BABEL_ENV=test yarn test:e2e --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
`cross-env BABEL_ENV=test yarn test:e2e:jest --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
`cross-env PERCY_TOKEN=dd3392142006a6483c8f524697f39f052755fa9dc087ff4437cac3d64227abdd yarn run percy exec -- yarn test:e2e:cypress`,
];

try {
Expand Down
6 changes: 5 additions & 1 deletion packages/react/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
storybook-static

# Generated metadata
react-docgen.json
react-docgen.json

# Cypress artifacts
cypress/videos
cypress/screenshots
10 changes: 10 additions & 0 deletions packages/react/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"componentFolder": "src",
"experimentalComponentTesting": true,
"env": {
"coverage": false
},
"fixturesFolder": false,
"nodeVersion": "system",
"testFiles": "**/*-test.e2e.js"
}
22 changes: 22 additions & 0 deletions packages/react/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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 preprocessor = require('@cypress/react/plugins/load-webpack');
const percyHealthCheck = require('@percy/cypress/task');

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
config.env.webpackFilename = 'webpack.config.js';
preprocessor(on, config);

on('task', percyHealthCheck);
return config;
};
17 changes: 17 additions & 0 deletions packages/react/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 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.
*/

import '@cypress/react/support';

// https://github.com/dmtrKovalenko/cypress-real-events
import 'cypress-real-events/support';

// https://github.com/testing-library/cypress-testing-library
import '@testing-library/cypress/add-commands';

// https://github.com/percy/percy-cypress
import '@percy/cypress';
8 changes: 7 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"prepublish": "yarn build",
"start": "yarn storybook",
"storybook": "rimraf node_modules/.cache/storybook && start-storybook -p 9000 -s ./.storybook/assets",
"snapshot": "build-storybook && percy-storybook --widths=320,1280"
"snapshot": "build-storybook && percy-storybook --widths=320,1280",
"test:e2e:cypress": "cypress run"
},
"peerDependencies": {
"carbon-components": "^10.30.0",
Expand Down Expand Up @@ -74,6 +75,8 @@
"@babel/preset-env": "^7.10.0",
"@babel/preset-react": "^7.10.0",
"@carbon/test-utils": "^10.15.0",
"@cypress/react": "^4.16.4",
"@percy/cypress": "^2.3.4",
"@percy/storybook": "^3.3.1",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^17.0.0",
Expand All @@ -84,6 +87,7 @@
"@storybook/react": "^5.3.19",
"@storybook/source-loader": "^5.3.19",
"@storybook/theming": "^6.1.18",
"@testing-library/cypress": "^7.0.5",
"babel-core": "^7.0.0-bridge.0",
"babel-loader": "^8.1.0",
"babel-plugin-dev-expression": "^0.2.2",
Expand All @@ -97,6 +101,8 @@
"core-js": "^3.6.5",
"cross-env": "^5.2.0",
"css-loader": "^3.4.2",
"cypress": "^6.5.0",
"cypress-real-events": "^1.3.0",
"gzip-size": "^6.0.0",
"lcov2badge": "^0.1.0",
"mini-css-extract-plugin": "^0.9.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* 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.
*/

import 'carbon-components/scss/components/accordion/_accordion.scss';

import React from 'react';
import { mount } from '@cypress/react';
import { default as Accordion, AccordionItem } from '..';

describe('Accordion', () => {
beforeEach(() => {
mount(
<Accordion>
<AccordionItem title="Section 1">Panel 1</AccordionItem>
<AccordionItem title="Section 2">Panel 2</AccordionItem>
<AccordionItem title="Section 3">Panel 3</AccordionItem>
</Accordion>
);
});

it('should render', () => {
cy.findByText(/Section 1/).should('be.visible');
cy.findByText(/Section 2/).should('be.visible');
cy.findByText(/Section 3/).should('be.visible');

cy.findByText(/Panel 1/).should('not.be.visible');
cy.findByText(/Panel 2/).should('not.be.visible');
cy.findByText(/Panel 3/).should('not.be.visible');

// snapshots should always be taken _after_ an assertion that
// a element/component should be visible. This is to ensure
// the DOM has settled and the element has fully loaded.
cy.percySnapshot();
});

it('should tab between items and open on space', () => {
// in order for realPress('Tab') to work, something must be focused first.
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved
// cy.get('body').focus() does not work
// cy.get('body').realClick() does not work because the click seems to be happen at the center of the element, which opens an accordion item
cy.findByRole('button', { name: /Section 1/i }).focus();

cy.realPress('Tab');
cy.findByRole('button', { name: /Section 2/i }).should('be.focused');

cy.realPress('Tab');
cy.findByRole('button', { name: /Section 3/i })
.should('be.focused')
.realPress('Space');
cy.findByText(/Panel 1/).should('not.be.visible');
cy.findByText(/Panel 2/).should('not.be.visible');
cy.findByText(/Panel 3/).should('be.visible');
// snapshots should always be taken _after_ an assertion that
// a element/component should be visible. This is to ensure
// the DOM has settled and the element has fully loaded.
cy.percySnapshot();

cy.realPress(['Shift', 'Tab']);
cy.realPress('Space');
cy.realPress(['Shift', 'Tab']);
cy.realPress('Space');

cy.findByText(/Panel 1/).should('be.visible');
cy.findByText(/Panel 2/).should('be.visible');
cy.findByText(/Panel 3/).should('be.visible');
});
});
25 changes: 25 additions & 0 deletions packages/react/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

module.exports = {
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
options: {
presets: [require.resolve('./scripts/env.js')],
},
},
{
test: /\.s?css$/i,
use: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
},
],
},
],
},
};
Loading