Skip to content

Commit 274354a

Browse files
committed
build: migrate e2e testing to Cypress
1 parent 0de5edb commit 274354a

File tree

12 files changed

+1112
-2199
lines changed

12 files changed

+1112
-2199
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[Angular 17](https://angular.io/)
66
[Angular Material](https://material.angular.io/)
77
✅ Unit Testing with [Jest](https://jestjs.io/)
8-
✅ End-to-End Testing with [TestCafé](https://testcafe.io/)
8+
✅ End-to-End Testing with [Cypress](https://www.cypress.io/)
99
✅ Internationalization with [Transloco](https://github.com/ngneat/transloco)
1010
✅ Auto documentation with [Compodoc](https://compodoc.app/)
1111
✅ Provide component examples with [Storybook](https://storybook.js.org/)

angular.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,56 @@
8484
"options": {
8585
"lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
8686
}
87+
},
88+
"cypress-run": {
89+
"builder": "@cypress/schematic:cypress",
90+
"options": {
91+
"devServerTarget": "angular-starter:serve"
92+
},
93+
"configurations": {
94+
"production": {
95+
"devServerTarget": "angular-starter:serve:production"
96+
}
97+
}
98+
},
99+
"cypress-open": {
100+
"builder": "@cypress/schematic:cypress",
101+
"options": {
102+
"watch": true,
103+
"headless": false
104+
}
105+
},
106+
"ct": {
107+
"builder": "@cypress/schematic:cypress",
108+
"options": {
109+
"devServerTarget": "angular-starter:serve",
110+
"watch": true,
111+
"headless": false,
112+
"testingType": "component"
113+
},
114+
"configurations": {
115+
"development": {
116+
"devServerTarget": "angular-starter:serve:development"
117+
}
118+
}
119+
},
120+
"e2e": {
121+
"builder": "@cypress/schematic:cypress",
122+
"options": {
123+
"devServerTarget": "angular-starter:serve",
124+
"watch": true,
125+
"headless": false
126+
},
127+
"configurations": {
128+
"production": {
129+
"devServerTarget": "angular-starter:serve:production"
130+
}
131+
}
87132
}
88133
}
89134
}
135+
},
136+
"cli": {
137+
"schematicCollections": ["@cypress/schematic", "@schematics/angular"]
90138
}
91139
}

cypress.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineConfig } from 'cypress';
2+
3+
export default defineConfig({
4+
e2e: {
5+
baseUrl: 'http://localhost:4200',
6+
},
7+
8+
component: {
9+
devServer: {
10+
framework: 'angular',
11+
bundler: 'webpack',
12+
},
13+
specPattern: '**/*.cy.ts',
14+
},
15+
});

cypress/e2e/spec.cy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe('My First Test', () => {
2+
it('Visits the initial project page', () => {
3+
cy.visit('/')
4+
cy.contains('app is running!')
5+
})
6+
})

cypress/fixtures/example.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]"
4+
}

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/component-index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>

cypress/support/component.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// ***********************************************************
2+
// This example support/component.ts 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+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
21+
22+
import { mount } from 'cypress/angular';
23+
24+
// Augment the Cypress namespace to include type definitions for
25+
// your custom command.
26+
// Alternatively, can be defined in cypress/support/component.d.ts
27+
// with a <reference path="./component" /> at the top of your spec.
28+
declare global {
29+
namespace Cypress {
30+
interface Chainable {
31+
mount: typeof mount;
32+
}
33+
}
34+
}
35+
36+
Cypress.Commands.add('mount', mount);
37+
38+
// Example use:
39+
// cy.mount(MyComponent)

cypress/support/e2e.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts 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+
}

0 commit comments

Comments
 (0)