[tests][m]: Setup Integration Tests with Cypress (#26).

* [cypress][s]-setup-integration=with-cypress
* [fix][s]- fix typescript bug 'All files must be modules when the '--isolatedModules' flag is provided' by adding an 'export {}' to all test files
* Fixes of cypress tests
* Use yarn everywhere not npm

Co-authored-by: Abhishek Gahlot <me@abhishek.it>
This commit is contained in:
Gift Egwuenu 2020-07-17 16:16:26 +01:00 committed by GitHub
parent 3cc1c1dca8
commit d9b5c4ddbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1435 additions and 728 deletions

16
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,16 @@
name: Cypress Integration Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Cypress run
uses: cypress-io/github-action@v1
with:
browser: chrome
build: yarn run build
start: yarn start
wait-on: 'http://localhost:3000'

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
# testing # testing
/coverage /coverage
/cypress/videos
# next.js # next.js
/.next/ /.next/

View File

@ -42,7 +42,7 @@ function Recent() {
return ( return (
<section className="my-10 mx-4 lg:my-20"> <section className="my-10 mx-4 lg:my-20">
<h1 className="text-2xl font-thin mb-4">Recent Datasets</h1> <h1 className="text-2xl font-thin mb-4">Recent Datasets</h1>
<div className="flex flex-col lg:flex-row"> <div className="recent flex flex-col lg:flex-row">
{result.results.map((dataset, index) => ( {result.results.map((dataset, index) => (
<div <div
key={index} key={index}

3
cypress.json Normal file
View File

@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000"
}

View File

@ -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"
}

View File

@ -0,0 +1,32 @@
describe('Test Home Page', () => {
beforeEach(() => {
cy.visit('/');
});
it('renders the hero title', () => {
cy.contains('Find, Share and Publish Quality Data with Datahub');
});
it('checks that a search form exists', () => {
cy.get('form').contains('Search');
});
it('submits the search form', () => {
cy.get('form').find('[type="text"]').type('my-dataset');
cy.get('form').submit();
cy.url().should('include', '/search?q=my-dataset&sort=');
cy.get('.text-3xl').and('contain.text', 'results found');
});
it('shows the recent datasets', () => {
cy.contains('Recent Datasets');
});
it('returns the expected number of recent datasets', () => {
cy.get('.recent')
.find('div')
.should(($div) => {
expect($div).to.have.length.of.at.least(2);
});
});
});

View File

@ -0,0 +1,18 @@
describe('Test Search Page', () => {
beforeEach(() => {
cy.visit('/search');
});
it('has a search form', () => {
cy.contains('form');
cy.contains('Search');
});
it('should return a search result', () => {
cy.get('form').find('[type="text"]').type('world population');
cy.get('form').submit();
cy.url().should('include', 'search?q=world%20population&sort=');
cy.get('.text-3xl').should('have.text', '1 results found');
cy.get('.text-xl > .text-primary').should('have.text', 'World Population');
});
});

21
cypress/plugins/index.js Normal file
View File

@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// 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)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};

View File

@ -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
cypress/support/index.js Normal file
View File

@ -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')

12
cypress/tsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": [
"**/*.ts"
]
}

View File

@ -9,6 +9,9 @@
"test": "jest", "test": "jest",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"test:coverage": "jest --coverage", "test:coverage": "jest --coverage",
"cypress:open": "cypress open",
"cypress:ci": "cypress run --config video=false",
"e2e": "cypress run",
"format": "prettier --single-quote --write .", "format": "prettier --single-quote --write .",
"pre-commit": "echo 'formating your changes.....' && prettier --single-quote --write" "pre-commit": "echo 'formating your changes.....' && prettier --single-quote --write"
}, },
@ -26,7 +29,7 @@
"markdown-it": "^11.0.0", "markdown-it": "^11.0.0",
"next": "9.4.2", "next": "9.4.2",
"qs": "^6.9.4", "qs": "^6.9.4",
"react": "16.13.1", "react": "^16.13.1",
"react-dom": "16.13.1", "react-dom": "16.13.1",
"slugify": "^1.4.0" "slugify": "^1.4.0"
}, },
@ -37,6 +40,7 @@
"@types/react": "^16.9.35", "@types/react": "^16.9.35",
"babel-jest": "^26.0.1", "babel-jest": "^26.0.1",
"babel-plugin-graphql-tag": "^2.5.0", "babel-plugin-graphql-tag": "^2.5.0",
"cypress": "^4.8.0",
"husky": ">=4", "husky": ">=4",
"jest": "^26.0.1", "jest": "^26.0.1",
"lint-staged": ">=10", "lint-staged": ">=10",

2002
yarn.lock

File diff suppressed because it is too large Load Diff