Skip to content

Commit ec1a6ab

Browse files
committed
Add e2e testing using cypress
1 parent d6b3660 commit ec1a6ab

File tree

14 files changed

+2880
-742
lines changed

14 files changed

+2880
-742
lines changed

angular.json

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,37 @@
9898
],
9999
"scripts": []
100100
}
101+
},
102+
"cypress-run": {
103+
"builder": "@cypress/schematic:cypress",
104+
"options": {
105+
"devServerTarget": "demo:serve"
106+
},
107+
"configurations": {
108+
"production": {
109+
"devServerTarget": "demo:serve:production"
110+
}
111+
}
112+
},
113+
"cypress-open": {
114+
"builder": "@cypress/schematic:cypress",
115+
"options": {
116+
"watch": true,
117+
"headless": false
118+
}
119+
},
120+
"e2e": {
121+
"builder": "@cypress/schematic:cypress",
122+
"options": {
123+
"devServerTarget": "demo:serve",
124+
"watch": true,
125+
"headless": false
126+
},
127+
"configurations": {
128+
"production": {
129+
"devServerTarget": "demo:serve:production"
130+
}
131+
}
101132
}
102133
}
103134
},
@@ -129,9 +160,42 @@
129160
"tsConfig": "projects/ng2-google-charts/tsconfig.spec.json",
130161
"karmaConfig": "projects/ng2-google-charts/karma.conf.js"
131162
}
163+
},
164+
"cypress-run": {
165+
"builder": "@cypress/schematic:cypress",
166+
"options": {
167+
"devServerTarget": "ng2-google-charts:serve",
168+
"configFile": "projects/ng2-google-charts/cypress.json"
169+
},
170+
"configurations": {
171+
"production": {
172+
"devServerTarget": "ng2-google-charts:serve:production"
173+
}
174+
}
175+
},
176+
"cypress-open": {
177+
"builder": "@cypress/schematic:cypress",
178+
"options": {
179+
"watch": true,
180+
"headless": false,
181+
"configFile": "projects/ng2-google-charts/cypress.json"
182+
}
183+
},
184+
"e2e": {
185+
"builder": "@cypress/schematic:cypress",
186+
"options": {
187+
"devServerTarget": "ng2-google-charts:serve",
188+
"watch": true,
189+
"headless": false
190+
},
191+
"configurations": {
192+
"production": {
193+
"devServerTarget": "ng2-google-charts:serve:production"
194+
}
195+
}
132196
}
133197
}
134198
}
135199
},
136200
"defaultProject": "ng2-google-charts"
137-
}
201+
}

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.ts",
7+
"fixturesFolder": "cypress/fixtures",
8+
"baseUrl": "http://localhost:4200"
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/spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('demo App', () => {
2+
3+
it('should render Column chart', () => {
4+
cy.visit('/', {
5+
onBeforeLoad(win) {
6+
cy.spy(win.console, 'error').as('spyWinConsoleError');
7+
},
8+
});
9+
10+
const expected = ['Countries', 'Germany', 'USA', 'Brazil', 'Canada', 'France', 'RU'];
11+
12+
const getText = (el:HTMLElement) => el.textContent?.trim();
13+
const text = cy.get('#columnChart').find('text').then(els => {
14+
const texts = [...els].map(getText).slice(0, expected.length);
15+
expect(texts).to.deep.eq(expected);
16+
})
17+
});
18+
19+
afterEach(() => {
20+
cy.get('@spyWinConsoleError').should('not.have.been.called');
21+
});
22+
23+
})

cypress/plugins/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Plugins enable you to tap into, modify, or extend the internal behavior of Cypress
2+
// For more info, visit https://on.cypress.io/plugins-api
3+
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) => { ... })

cypress/support/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// When a command from ./commands is ready to use, import with `import './commands'` syntax
17+
// import './commands';

cypress/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["**/*.ts"],
4+
"compilerOptions": {
5+
"sourceMap": false,
6+
"types": ["cypress"]
7+
}
8+
}

e2e/protractor.conf.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

e2e/src/app.e2e-spec.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

e2e/src/app.po.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

e2e/tsconfig.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)