[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:
parent
3cc1c1dca8
commit
d9b5c4ddbd
16
.github/workflows/main.yml
vendored
Normal file
16
.github/workflows/main.yml
vendored
Normal 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
1
.gitignore
vendored
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
# testing
|
# testing
|
||||||
/coverage
|
/coverage
|
||||||
|
/cypress/videos
|
||||||
|
|
||||||
# next.js
|
# next.js
|
||||||
/.next/
|
/.next/
|
||||||
|
|||||||
@ -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
3
cypress.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"baseUrl": "http://localhost:3000"
|
||||||
|
}
|
||||||
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal 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"
|
||||||
|
}
|
||||||
32
cypress/integration/pages/homepage-spec.js
Normal file
32
cypress/integration/pages/homepage-spec.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
18
cypress/integration/pages/search-spec.js
Normal file
18
cypress/integration/pages/search-spec.js
Normal 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
21
cypress/plugins/index.js
Normal 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
|
||||||
|
};
|
||||||
25
cypress/support/commands.js
Normal file
25
cypress/support/commands.js
Normal 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
20
cypress/support/index.js
Normal 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
12
cypress/tsconfig.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"baseUrl": "../node_modules",
|
||||||
|
"target": "es5",
|
||||||
|
"lib": ["es5", "dom"],
|
||||||
|
"types": ["cypress"]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"**/*.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -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",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user