Skip to content

Commit

Permalink
test(e2e): introduce cypress e2e testing (carbon-design-system#1451)
Browse files Browse the repository at this point in the history
* chore(issue-templates): updating issue templates for the website

* chore(issue-templates): updating feature request based on feedback

* test(e2e): introduce cypress e2e testing

* test(e2e): change workflow to only run on upstream

* test(e2e): change workflow to only run on upstream

* chore(yarn): update yarn offline mirror

* fix(github-actions): fix e2e test script name

* chore(github-actions): add cache for gatsby builds

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
jeffchew and kodiakhq[bot] authored Feb 4, 2022
1 parent 90d846b commit 1710a05
Show file tree
Hide file tree
Showing 90 changed files with 795 additions and 70 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.cache/*
/node_modules/*
.github
tests/e2e/cypress
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugins": ["react"],
"plugins": ["react", "cypress"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/e2e-tests-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: e2e-tests-prod

on:
schedule:
- cron: "0 */2 * * *"

concurrency:
group: e2e-tests-prod-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e-tests:
if: github.repository == 'carbon-design-system/carbon-for-ibm-dotcom-website'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['14.x']
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: '14.x'
cache: yarn
- name: Install dependencies
run: yarn install
- name: Run e2e tests
run: yarn test:e2e:prod
- uses: act10ns/slack@v1
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
status: ${{ job.status }}
57 changes: 57 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: e2e-tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

concurrency:
group: e2e-tests-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e-tests:
if: github.repository == 'carbon-design-system/carbon-for-ibm-dotcom-website'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['14.x']
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: '14.x'
cache: yarn
- name: Caching Gatsby
id: gatsby-cache-build
uses: actions/cache@v2
with:
path: |
public
.cache
key: ${{ runner.os }}-gatsby-build-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-gatsby-build-
- name: Install dependencies
run: yarn install
- name: Set env vars
uses: ./.github/actions/set-dotenv
with:
env-file: .env.production
env:
GATSBY_CPU_COUNT: 1
- name: Building Gatsby
run: yarn build
env:
GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES: true
CI: true
- name: Run e2e tests
run: yarn test:e2e:local
- uses: act10ns/slack@v1
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
status: ${{ job.status }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ wiki-build
*.log
src/pages/developing/building-for-ibm-dotcom/index.mdx
src/pages/developing/carbon-cdn-style-helpers/index.mdx

# Cypress output files
tests/e2e/cypress/screenshots
tests/e2e/cypress/videos
9 changes: 9 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"*.js": [
"eslint --fix",
"prettier --write"
],
"*.{css,scss,json,html,yaml,md,mdx}": [
"prettier --write"
]
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.yarn
.github
public
tests/e2e/cypress/fixtures
Binary file added .yarn/offline-mirror/@cypress-request-2.88.10.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@cypress-xvfb-1.2.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-node-14.18.10.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-sizzle-2.3.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-yauzl-2.9.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/async-3.2.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/basic-auth-2.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/blob-util-2.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/buffer-crc32-0.2.13.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/cachedir-2.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/check-more-types-2.24.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ci-info-3.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/cli-table3-0.6.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/colorette-2.0.16.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/commander-5.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/corser-2.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/cypress-9.4.1.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/dayjs-1.10.7.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/debug-4.3.2.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/debug-4.3.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/engine.io-4.1.1.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/engine.io-4.1.2.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/event-stream-3.3.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/eventemitter2-6.4.5.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/execa-4.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/executable-4.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/extract-zip-2.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/fd-slicer-1.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/from-0.1.7.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/getos-3.2.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/he-1.2.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/http-server-14.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/http-signature-1.3.6.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/human-signals-1.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/iconv-lite-0.6.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/is-ci-3.0.1.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/json-schema-0.4.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jsprim-2.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/lazy-ass-1.6.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/listr2-3.14.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/lodash.once-4.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/log-symbols-4.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/map-stream-0.1.0.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/mime-db-1.51.0.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/mime-types-2.1.34.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ospath-1.2.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pause-stream-0.0.11.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pend-1.2.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pify-2.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/portfinder-1.0.28.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/proxy-from-env-1.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ps-tree-1.2.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/qs-6.10.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/request-progress-3.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/rfdc-1.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/rxjs-7.5.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/secure-compare-3.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/split-0.3.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/sshpk-1.17.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/stream-combiner-0.0.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/throttleit-1.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/union-0.5.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/untildify-4.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/url-join-4.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/uuid-8.3.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/wait-on-6.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/whatwg-encoding-2.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/yauzl-2.10.0.tgz
Binary file not shown.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
"postinstall": "husky install",
"postpublish": "pinst --enable",
"prepublishOnly": "pinst --disable",
"serve": "gatsby serve"
"serve": "gatsby serve",
"test:e2e:local": "start-server-and-test 'yarn test:e2e:run' 8080 'cypress run --config video=false --config-file tests/e2e/cypress.json'",
"test:e2e:local:with-video": "start-server-and-test 'yarn test:e2e:run' 8080 'cypress run --config-file tests/e2e/cypress.json'",
"test:e2e:prod": "cypress run --config video=false --config-file tests/e2e/cypress-prod.json",
"test:e2e:run": "http-server -c-1 public --silent"
},
"dependencies": {
"@carbon/icons-react": "^10.27.0",
Expand All @@ -38,23 +42,19 @@
"@babel/plugin-proposal-class-properties": "^7.12.13",
"@babel/plugin-transform-classes": "^7.12.13",
"babel-preset-gatsby": "^1.14.0",
"cypress": "^9.4.1",
"cypress-wait-until": "^1.7.2",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-cypress": "^2.12.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"http-server": "^14.1.0",
"husky": "^7.0.2",
"lint-staged": "^11.1.2",
"prettier": "^2.3.2"
},
"lint-staged": {
"*.js": [
"eslint --fix",
"prettier --write"
],
"*.{css,scss,json,html,yaml,md,mdx}": [
"prettier --write"
]
"prettier": "^2.3.2",
"start-server-and-test": "^1.14.0"
}
}
14 changes: 14 additions & 0 deletions tests/e2e/cypress-prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"baseUrl": "https://www.ibm.com/standards/carbon",
"browser": "chrome",
"headless": true,
"fixturesFolder": "tests/e2e/cypress/fixtures",
"screenshotsFolder": "tests/e2e/cypress/screenshots",
"videosFolder": "tests/e2e/cypress/videos",
"integrationFolder": "tests/e2e/cypress/integration",
"supportFile": "tests/e2e/cypress/support/index.js",
"pluginsFile": "tests/e2e/cypress/plugins/index.js",
"testFiles": "**/*.e2e.js",
"pageLoadTimeout": 60000,
"defaultCommandTimeout": 60000
}
14 changes: 14 additions & 0 deletions tests/e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"baseUrl": "http://localhost:8080",
"browser": "chrome",
"headless": true,
"fixturesFolder": "tests/e2e/cypress/fixtures",
"screenshotsFolder": "tests/e2e/cypress/screenshots",
"videosFolder": "tests/e2e/cypress/videos",
"integrationFolder": "tests/e2e/cypress/integration",
"supportFile": "tests/e2e/cypress/support/index.js",
"pluginsFile": "tests/e2e/cypress/plugins/index.js",
"testFiles": "**/*.e2e.js",
"pageLoadTimeout": 60000,
"defaultCommandTimeout": 60000
}
8 changes: 8 additions & 0 deletions tests/e2e/cypress/fixtures/ibm-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright IBM Corp. 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = {}
25 changes: 25 additions & 0 deletions tests/e2e/cypress/integration/homepage/homepage.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright IBM Corp. 2022
*
* 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';

describe('Homepage', () => {
beforeEach(() => {
cy.visit('/');
cy.viewport(1280, 780);

cy.waitUntil(() => cy.get('header').should('not.be.empty'));
});

it('should have a functioning left navigation', () => {
cy.get('.bx--side-nav__submenu').first().click();

cy.get('.bx--side-nav__link').first().should('be.visible').click();

cy.location('pathname').should('not.eq', '/');
});
});
12 changes: 12 additions & 0 deletions tests/e2e/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright IBM Corp. 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
8 changes: 8 additions & 0 deletions tests/e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright IBM Corp. 2022
*
* 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-wait-until';
15 changes: 15 additions & 0 deletions tests/e2e/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright IBM Corp. 2022
*
* 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 './commands';

beforeEach(() => {
// Block ibm-common.js
cy.intercept('https://1.www.s81c.com/common/stats/ibm-common.js', {
fixture: 'ibm-common.js',
});
});
Loading

0 comments on commit 1710a05

Please sign in to comment.