You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/assignments/hw4-25.md
+67-12Lines changed: 67 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,9 @@ Let's fix one configuration error in the calculator code; this is necessary beca
30
30
31
31
Edit calculator-frontend/package.json. Change the line starting with "test" inside of the "scripts" object to read:
32
32
33
-
```"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(axios)/)' --detectOpenHandles",~~~
33
+
```
34
+
"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(axios)/)' --detectOpenHandles",
35
+
```
34
36
35
37
#### Turn in instructions
36
38
@@ -43,8 +45,10 @@ In calculator-backend/tests, there's a file called calculate.test.js. The code c
43
45
44
46
Run the test by executing:
45
47
46
-
```cd calculator-backend
47
-
npm test~~~
48
+
```
49
+
cd calculator-backend
50
+
npm test
51
+
```
48
52
49
53
It should execute the test and show that it passed.
50
54
@@ -70,12 +74,14 @@ You'll need to install more npm modules to test the front end.
70
74
71
75
Execute these three commands:
72
76
73
-
```npm install @testing-library/react
74
-
npm install @testing-library/jest-dom~~~
77
+
```
78
+
npm install @testing-library/react
79
+
npm install @testing-library/jest-dom
80
+
```
75
81
76
82
There's already an App.test.js in the src/ directory. It has the test code for App.js.
77
83
78
-
Let's run that using ```npm test~~~.
84
+
Let's run that using ```npm test```.
79
85
80
86
This looks like a bad test. If you open up App.test.js it creates the Calculator app React element and then looks for a box on the screen labeled 'learn react'.
81
87
@@ -95,11 +101,14 @@ First, we need to add an HTML attribute to the appropriate div so we can refer t
95
101
96
102
In Calculator.js, add the attribute 'data-testid="total"' to the div with the className 'expression'. It should look like this:
Second, in the calculator-frontend/src directory, add a new file called Calculate.tests.js. Put this code in your file:
101
109
102
-
```import { render, fireEvent, screen } from '@testing-library/react'
110
+
```
111
+
import { render, fireEvent, screen } from '@testing-library/react'
103
112
import '@testing-library/jest-dom'
104
113
import Calculator from './Calculator'
105
114
@@ -122,9 +131,8 @@ it('Appends the number when pressed', async () => {
122
131
123
132
// get the expression DOM node and check that it is 12
124
133
expect(element).toHaveTextContent('12');
125
-
126
-
127
-
});~~~
134
+
});
135
+
```
128
136
129
137
It checks that if you press a '1', you see a 1 in the top of the calculator. If you then press a '2', you should see a 12 at the top of the calculator.
130
138
@@ -159,7 +167,7 @@ Create a PR to commit your test code to the team's repository. Use your PR messa
159
167
160
168
Please provide us a link to your PR.
161
169
162
-
### 9. Review at least two PRs
170
+
### 7. Review at least two PRs
163
171
164
172
Following the best practices we discussed in class, leave two reviews on your teammates' PRs. If there issues, continue to discuss in the comments until you're satisfied with the changes and able to approve the pull requests.
165
173
@@ -174,3 +182,50 @@ Finally, once your PR has been approved, [merge it](https://docs.github.com/en/p
174
182
#### Turn in instructions
175
183
176
184
Please provide a link to your merged commit.
185
+
186
+
### 8. Create a continuous integration pipeline to run your test cases
187
+
188
+
To ensure the quality of our codebase, we want to make sure that your code passes all its test cases after every checkin. If the tests fail, we should reject the checkin.
189
+
190
+
To setup our CI workflow, first, create a workflows subdirectory in .github. Then create a new file called ci.yml in workflows/.
191
+
192
+
Open ci.yml in a text editor, paste in the following code snippet, and commit this to your repository. Use hygienic code practices and commit to a branch first, then issue a pull request, do a code review, and merge it into main.
193
+
194
+
```
195
+
name: ci
196
+
on:
197
+
push:
198
+
branches:
199
+
- main
200
+
pull_request:
201
+
branches: [main]
202
+
203
+
permissions:
204
+
contents: write
205
+
206
+
jobs:
207
+
jest:
208
+
runs-on: ubuntu-latest
209
+
steps:
210
+
- uses: actions/checkout@v4
211
+
- name: Run Frontend Tests
212
+
working-directory: ./calculator-frontend
213
+
run: |
214
+
npm install
215
+
npm test
216
+
- name: Run Backend Tests
217
+
working-directory: ./calculator-backend
218
+
run: |
219
+
npm install
220
+
npm test
221
+
```
222
+
223
+
Once this is installed, every time we push to main or do a pull request to main, this will execute the frontend and backend test code. We have Require status checks to pass before merging turned on in our repository settings. If any tests fail, the push or pull request will fail as well.
224
+
225
+
You can find out what happened in the tests by clicking on the Actions tab at the top of your GitHub repository page and choose the 'ci' workflow. If the tests worked, you'll see all green dots. If it's running right now, the dot will be yellow and show a spinning circle. If there was a failure, the dot will be red. Click on a dot to see a terminal window that shows the commands as they executed as well as their results.
226
+
227
+
#### Turn in instructions
228
+
229
+
Turn in the URL to your workflow run of ci.yml that resulted in a successful test case run. If you had to run the ci workflow several times before it passed, turn in the URL of the latest workflow run that succeeded.
0 commit comments