Skip to content

Commit bafbb92

Browse files
committed
update 07
1 parent c40d30c commit bafbb92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5586
-18924
lines changed

05-testing/03-e2e/07-ci/.babelrc

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Ci workflow
1+
name: CI workflow
22

33
on: pull_request
44

@@ -7,20 +7,20 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout repository
10-
uses: actions/checkout@v3
10+
uses: actions/checkout@v4
1111
- name: Install
1212
run: npm ci
1313
- name: Tests e2e
1414
run: npm run test:e2e:ci
1515
- name: Upload screenshots when specs fail
1616
if: ${{ failure()}}
17-
uses: actions/upload-artifact@v3
17+
uses: actions/upload-artifact@v4
1818
with:
1919
name: screenshots
2020
path: ./cypress/screenshots
2121
- name: Upload videos when specs fail
2222
if: ${{ failure()}}
23-
uses: actions/upload-artifact@v3
23+
uses: actions/upload-artifact@v4
2424
with:
2525
name: videos
2626
path: ./cypress/videos

05-testing/03-e2e/07-ci/README.md

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ We will start from `06-edit-hotel`.
1212
npm install
1313
```
1414

15-
- Add script commands to run in ci process:
15+
Add script commands to run in ci process:
1616

17-
### ./package.json
17+
_./package.json_
1818

1919
```diff
2020
...
@@ -30,15 +30,15 @@ npm install
3030
>
3131
> We can change browser to another one, with headless version, see [commands](https://docs.cypress.io/guides/guides/command-line.html#Commands)
3232
33-
- And run it:
33+
And run it:
3434

3535
```bash
3636
npm run test:e2e:ci
3737
```
3838

3939
Update config:
4040

41-
### ./cypress.config.ts
41+
_./cypress.config.ts_
4242

4343
```diff
4444
import { defineConfig } from 'cypress';
@@ -54,9 +54,9 @@ export default defineConfig({
5454

5555
```
5656

57-
- Notice that `cypress` has added `screenshots` and `videos` with failing specs, we should ignore these folder for git:
57+
Notice that `cypress` has added `screenshots` and `videos` with failing specs, we should ignore these folder for git:
5858

59-
### ./.gitignore
59+
_./.gitignore_
6060

6161
```diff
6262
...
@@ -65,50 +65,26 @@ export default defineConfig({
6565

6666
```
6767

68-
- Let's make a test fail:
68+
Let's make a test fail:
6969

70-
### ./cypress/e2e/hotel-edit.spec.ts
70+
_./cypress/e2e/hotel-edit.spec.ts_
7171

7272
```diff
7373
...
7474
it('should update hotel name when it edits an hotel and click on save button', () => {
75-
// Arrange
76-
77-
// Act
78-
cy.loadAndVisit(
79-
'/hotel-collection',
80-
[
81-
{ path: '/api/hotels', alias: 'loadHotels' },
82-
{ path: '/api/hotels/2' },
83-
{ path: '/api/cities' },
84-
],
85-
() => {
86-
cy.findAllByRole('button', { name: 'Edit hotel' }).then((buttons) => {
87-
buttons[1].click();
88-
});
89-
}
90-
);
91-
92-
cy.findByLabelText('Name').should('not.have.value', '');
93-
94-
cy.findByLabelText('Name').clear().type('Updated hotel two');
95-
96-
cy.findByRole('button', { name: 'Save' }).click();
97-
98-
// Assert
99-
cy.wait('@loadHotels');
75+
...
10076
- cy.findByText('Updated hotel two');
10177
+ cy.findByText('Updated hotel three');
10278
});
10379
```
10480

105-
- And run it:
81+
And run it:
10682

10783
```bash
10884
npm run test:e2e:ci
10985
```
11086

111-
- We will configure [Github actions](https://github.com/features/actions) to run all tests in this app. Since Github has [free private/public repositories](https://github.com/pricing) we only need to create a github repository:
87+
We will configure [Github actions](https://github.com/features/actions) to run all tests in this app. Since Github has [free private/public repositories](https://github.com/pricing) we only need to create a github repository:
11288

11389
```bash
11490
git init
@@ -118,9 +94,9 @@ git commit -m "add project with tests"
11894
git push -u origin main
11995
```
12096

121-
- Create new branch on repository `feature/add-ci-file` and add ci config:
97+
Create new branch on repository `feature/add-ci-file` and add ci config:
12298

123-
### ./.github/workflows/ci.yml
99+
_./.github/workflows/ci.yml_
124100

125101
```yml
126102
name: CI workflow
@@ -139,19 +115,19 @@ jobs:
139115
run: npm run test:e2e:ci
140116
```
141117
142-
- Commit, push:
118+
Commit, push:
143119
144120
```bash
145121
git add .
146122
git commit -m "add ci file"
147123
git push -u origin feature/add-ci-file
148124
```
149125

150-
- Create a pull request.
126+
Create a `pull request`.
151127

152-
- We can upload `screenshots` and `videos` as `artifacts` if specs `fail`:
128+
We can upload `screenshots` and `videos` as `artifacts` if specs `fail`:
153129

154-
### ./.github/workflows/ci.yml
130+
_./.github/workflows/ci.yml_
155131

156132
```diff
157133
name: Ci workflow
@@ -182,17 +158,17 @@ jobs:
182158
+ path: ./cypress/videos
183159
```
184160

185-
- Commit again:
161+
Commit again:
186162

187163
```bash
188164
git add .
189165
git commit -m "upload artifacts"
190166
git push
191167
```
192168

193-
- Restore specs:
169+
Restore specs:
194170

195-
### ./cypress/e2e/hotel-edit.spec.ts
171+
_./cypress/e2e/hotel-edit.spec.ts_
196172

197173
```diff
198174
it('should update hotel name when it edits an hotel and click on save button', () => {

05-testing/03-e2e/07-ci/config/webpack/base.js

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

05-testing/03-e2e/07-ci/config/webpack/dev.js

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

05-testing/03-e2e/07-ci/config/webpack/helpers.js

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

05-testing/03-e2e/07-ci/config/webpack/prod.js

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

05-testing/03-e2e/07-ci/cypress.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ export default defineConfig({
44
e2e: {
55
baseUrl: 'http://localhost:8080/#',
66
specPattern: 'cypress/e2e/**/*.spec.{js,jsx,ts,tsx}',
7+
video: true,
8+
screenshotOnRunFailure: true,
79
},
810
});

05-testing/03-e2e/07-ci/cypress/e2e/hotel-collection.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
describe('Hotel collection specs', () => {
22
it('should fetch hotel list and show it in screen when visit /hotel-collection url', () => {
33
// Arrange
4-
54
// Act
6-
cy.loadAndVisit('/hotel-collection', [{ path: '/api/hotels' }]);
5+
cy.loadAndVisit('/api/hotels', '/hotel-collection');
76

87
// Assert
98
cy.findAllByRole('listitem').should('have.length', 10);
@@ -13,7 +12,7 @@ describe('Hotel collection specs', () => {
1312
// Arrange
1413

1514
// Act
16-
cy.loadAndVisit('/hotel-collection', [{ path: '/api/hotels' }]);
15+
cy.loadAndVisit('/api/hotels', '/hotel-collection');
1716

1817
// Assert
1918
cy.findAllByRole('listitem').should('have.length.greaterThan', 0);
@@ -23,9 +22,7 @@ describe('Hotel collection specs', () => {
2322
// Arrange
2423

2524
// Act
26-
cy.loadAndVisit('/hotel-collection', [
27-
{ path: '/api/hotels', fixture: 'hotels.json' },
28-
]);
25+
cy.loadAndVisit('/api/hotels', '/hotel-collection', 'hotels');
2926

3027
// Assert
3128
cy.findAllByRole('listitem').should('have.length', 2);

0 commit comments

Comments
 (0)