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

Add Cypress e2e tests #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 22 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
version: 2.1

jobs:
run_tests:
run_e2e_tests:
docker:
- image: cypress/browsers:node10.16.0-chrome77
environment:
TERM: xterm
steps:
- checkout
- run:
command: npm install && npm run prepare
- run:
command: cd example && npm install
- run:
command: cd example && npm start
background: true
- run:
command: npx wait-on -d 60000 http://localhost:3000
- run:
command: npm run ci:cypress

run_integration_and_unit_tests:
docker:
- image: circleci/node:10.18.1
environment:
Expand All @@ -16,4 +35,5 @@ jobs:
workflows:
tests:
jobs:
- run_tests
- run_integration_and_unit_tests
- run_e2e_tests
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ yarn-error.log*

# coverage report
coverage

# cypress
cypress/examples
cypress/videos
6 changes: 6 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"baseUrl": "http://localhost:3000",
"pageLoadTimeout": 180000,
"projectId": "fsyzwo",
"chromeWebSecurity": false
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
17 changes: 17 additions & 0 deletions cypress/integration/marker.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe("react-hook-google-maps", () => {
before(() => {
cy.visit("/");
});
it("renders Google Maps one with a marker", () => {
cy.findAllByText("This page can't load Google Maps correctly.").should(
"have.length",
2,
);
cy.findAllByText("OK").click({ multiple: true });
cy.queryAllByText("This page can't load Google Maps correctly.").should(
"not.exist",
);
// map marker can be selected with document.querySelectorAll("img[usemap='#gmimap0']");
cy.get("img[usemap='#gmimap0']").should("have.length", 1);
});
});
17 changes: 17 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
28 changes: 28 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ***********************************************
// 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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

// install cypress-testing-library
import '@testing-library/cypress/add-commands';
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'

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