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

feat: integrate Cypress end-to-end testing (resolves #84) #91

Closed
wants to merge 20 commits into from
Closed
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
25 changes: 25 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: End-to-end tests

on: [pull_request]

jobs:
cypress-run:
name: Run end-to-end-tests with Cypress
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm i
env:
CI: true
- name: Run Cypress
uses: cypress-io/github-action@v2
with:
start: npm start
wait-on: 'http://localhost:3000'
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
name: Lint JavaScript and SCSS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Checkout
uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ src/_data/assets.json
# Local Netlify folder
.netlify

# Cypress data
cypress/screenshots
cypress/videos
cypress/reports

# Backstop data
backstop_data/*
!backstop_data/engine_scripts
Expand Down
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file added cypress/fixtures/.gitkeep
Empty file.
File renamed without changes.
10 changes: 10 additions & 0 deletions cypress/integration/menu.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe('Mobile menu', () => {
it('Mobile menu expands when clicked', () => {
cy.visit('http://localhost:3000');

// Get an input, type into it and verify that the value has been updated
cy.get('.menu-toggle')
.click()
.should('have.attr', 'aria-expanded', 'true');
});
});
5 changes: 5 additions & 0 deletions cypress/integration/regression.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Using backstopjs', () => {
it('Generate report using Backstop JS', () => {
cy.task('backstopTest', {folder: 'idrc'}, {timeout: 820000});
});
});
57 changes: 57 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint camelcase: ["error", {properties: "never"}] */

const backstop = require('backstopjs');

const config = require('../fixtures/backstop.config.js');

/**
* Run BackstopJS as code
* Scenarios and Report folder name can be set via params
*/
function backstopExec(payload, refreshReferences = true) {
payload = {
scenarios: [],
folder: 'default',
...payload
};

return new Promise(resolve => {
const configuration = config;
// Config.scenarios = payload.scenarios
config.paths.html_report = `cypress/reports/backstop/${payload.folder}/html_report`;
config.paths.json_report = `cypress/reports/backstop/${payload.folder}/json_report`;

if (refreshReferences) {
backstop('reference', {config: configuration, docker: true}).then(() => {
resolve(null);
}).catch(() => {
resolve(null);
});
} else {
backstop('test', {config: configuration, docker: true}).then(() => {
resolve(null);
}).catch(() => {
resolve(null);
});
}
});
}

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => { // eslint-disable-line no-unused-vars
backstop('init');
on('task', {
log(message) { // eslint-disable-line react/function-component-definition
console.log(message);
return null;
},
backstopRefreshReferences(config) {
return backstopExec(config);
},
backstopTest(config) {
return backstopExec(config, false);
}
});
};
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'; // eslint-disable-line import/no-unassigned-import

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading