Skip to content

Commit 94694f7

Browse files
authored
Add E2E test with Cypress (#65)
* Add test for compare editor * Add test cases for cypress * move tsconfig file for angular to root dir
1 parent 5876a25 commit 94694f7

20 files changed

+2421
-168
lines changed

.github/workflows/main_text-compare.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
npm install
3030
npm run build:azure
3131
npm run test:headless
32+
npm run e2e:headless
3233
3334
- name: Upload artifact for deployment job
3435
uses: actions/upload-artifact@v4

.github/workflows/main_text-compare2.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
npm install
3030
npm run build:azure
3131
npm run test:headless
32+
npm run e2e:headless
3233
3334
- name: Upload artifact for deployment job
3435
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ npm-debug.log
3535
yarn-error.log
3636
testem.log
3737
/typings
38+
/cypress/videos/
3839

3940
# System Files
4041
.DS_Store

angular.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"base": "dist"
1616
},
1717
"index": "src/index.html",
18-
"tsConfig": "src/tsconfig.app.json",
18+
"tsConfig": "tsconfig.app.json",
1919
"polyfills": [
2020
"src/polyfills.ts"
2121
],
@@ -176,7 +176,7 @@
176176
"main": "src/test.ts",
177177
"karmaConfig": "./karma.conf.js",
178178
"polyfills": "src/polyfills.ts",
179-
"tsConfig": "src/tsconfig.spec.json",
179+
"tsConfig": "tsconfig.spec.json",
180180
"scripts": [],
181181
"styles": [
182182
"node_modules/bootstrap/dist/css/bootstrap.min.css",

azure-pipelines.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ stages:
104104
npm run test:headless
105105
displayName: 'Run unit tests (headless)'
106106
107+
- script: |
108+
# Run e2e tests in headless Chrome
109+
npm run e2e:headless
110+
displayName: 'Run e2e tests (headless)'
111+
107112
- stage: Build
108113
displayName: 'Build'
109114
dependsOn:

cypress.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"integrationFolder": "cypress/integration",
3+
"supportFile": "cypress/support/index.ts",
4+
"videosFolder": "cypress/videos",
5+
"screenshotsFolder": "cypress/screenshots",
6+
"pluginsFile": "cypress/plugins/index.js",
7+
"fixturesFolder": "cypress/fixtures",
8+
"baseUrl": "https://text-compare.netlify.app/"
9+
}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/integration/home.cy.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('Text Compare App', () => {
4+
beforeEach(() => {
5+
cy.visit('https://text-compare.netlify.app/');
6+
});
7+
8+
it('should display the app name on the home page', () => {
9+
cy.visit('/');
10+
cy.contains('Text Compare');
11+
cy.contains('Netlify');
12+
cy.get('h1').should('contain.text', 'Text Compare');
13+
});
14+
15+
it('should display two text boxes and a compare button', () => {
16+
cy.visit('/');
17+
cy.get('#editor1').should('be.visible');
18+
cy.get('#editor2').should('be.visible');
19+
cy.contains('button', 'Compare').should('be.visible');
20+
});
21+
22+
it('should compare two text inputs', () => {
23+
const left = 'Hello World';
24+
const right = 'Hello world';
25+
26+
cy.get('#editor1').clear().type(left);
27+
cy.get('#editor2').clear().type(right);
28+
29+
cy.contains('button', 'Compare').click();
30+
cy.get('#diffeditor').should('be.visible');
31+
});
32+
});

cypress/plugins/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = (on, config) => {};

cypress/support/commands.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ***********************************************
2+
// This example namespace declaration will help
3+
// with Intellisense and code completion in your
4+
// IDE or Text Editor.
5+
// ***********************************************
6+
// declare namespace Cypress {
7+
// interface Chainable<Subject = any> {
8+
// customCommand(param: any): typeof customCommand;
9+
// }
10+
// }
11+
//
12+
// function customCommand(param: any): void {
13+
// console.warn(param);
14+
// }
15+
//
16+
// NOTE: You can use it like so:
17+
// Cypress.Commands.add('customCommand', customCommand);
18+
//
19+
// ***********************************************
20+
// This example commands.js shows you how to
21+
// create various custom commands and overwrite
22+
// existing commands.
23+
//
24+
// For more comprehensive examples of custom
25+
// commands please read more here:
26+
// https://on.cypress.io/custom-commands
27+
// ***********************************************
28+
//
29+
//
30+
// -- This is a parent command --
31+
// Cypress.Commands.add("login", (email, password) => { ... })
32+
//
33+
//
34+
// -- This is a child command --
35+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
36+
//
37+
//
38+
// -- This is a dual command --
39+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
40+
//
41+
//
42+
// -- This will overwrite an existing command --
43+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

0 commit comments

Comments
 (0)