Skip to content

Commit

Permalink
test: use cypress (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
derevnjuk authored Feb 15, 2021
1 parent ea8ce5e commit 81b6493
Show file tree
Hide file tree
Showing 15 changed files with 1,676 additions and 11,853 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
project: 'tsconfig.json',
sourceType: 'module',
},
ignorePatterns: ['test', 'node_modules', 'dist', 'public'],
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
Expand Down
5 changes: 0 additions & 5 deletions public/.eslintignore

This file was deleted.

14 changes: 7 additions & 7 deletions public/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
createDefaultProgram: true
},
ignorePatterns: ['cypress', 'node_modules', 'dist', 'public'],
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
'plugin:prettier/recommended'
],
root: true,
env: {
node: true,
jest: true,
browser: true
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
'@typescript-eslint/no-explicit-any': 'off'
}
};
7 changes: 7 additions & 0 deletions public/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"baseUrl": "http://localhost:3001",
"fixturesFolder": false,
"video": false,
"pluginsFile": "cypress/plugins/index.ts",
"supportFile": "cypress/support/index.ts"
}
13 changes: 13 additions & 0 deletions public/cypress/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
ignorePatterns: ['!**/*'],
extends: ['../.eslintrc.js'],
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname
}
}
]
};
47 changes: 47 additions & 0 deletions public/cypress/integration/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe('Log In', () => {
beforeEach(() => cy.visit('/login'));

it('should successfully logs in', () => {
// we can submit form using "cy.submit" command
// https://on.cypress.io/submit
cy.get('input[name=user]').type('admin');
cy.get('input[name=password]').type('admin');
cy.get('button[type=submit]').click();

// we should be in
cy.url().should('include', '/');
cy.get('a.get-started-btn').should('contain', 'Log out admin');
});

it('should displays errors on login', function () {
// alias this request so we can wait on it later
cy.intercept('POST', '/login').as('postLogin');

// incorrect username on password
cy.get('input[name=user]').type('jane.lae');
cy.get('input[name=password]').type('password123{enter}');

// we should always explicitly check if the status equals 401
cy.wait('@postLogin').its('response.statusCode').should('eq', 401);

// and still be on the same URL
cy.url().should('include', '/login');
});

it('can stub the XHR to force it to fail', function () {
// alias this request so we can wait on it later
cy.intercept('POST', '/login', { statusCode: 503, delay: 5000 }).as(
'postLogin'
);

// incorrect username on password
cy.get('input[name=user]').type('admin');
cy.get('input[name=password]').type('admin{enter}');

// we should always explicitly check if the status equals 401
cy.wait('@postLogin').its('response.statusCode').should('eq', 503);

// and still be on the same URL
cy.url().should('include', '/login');
});
});
24 changes: 24 additions & 0 deletions public/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// cypress/plugins/index.ts

/// <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)

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default (
_on: Cypress.PluginEvents,
_config: Cypress.PluginConfigOptions
) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
25 changes: 25 additions & 0 deletions public/cypress/support/commands.ts
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) => { ... })
17 changes: 17 additions & 0 deletions public/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// 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';
10 changes: 10 additions & 0 deletions public/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"isolatedModules": false,
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": ["**/*", "../src/**/*"]
}
Loading

0 comments on commit 81b6493

Please sign in to comment.