Skip to content

Commit 7aee05a

Browse files
committed
Done with CI
1 parent 8b8069f commit 7aee05a

File tree

1 file changed

+67
-12
lines changed

1 file changed

+67
-12
lines changed

docs/assignments/hw4-25.md

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Let's fix one configuration error in the calculator code; this is necessary beca
3030

3131
Edit calculator-frontend/package.json. Change the line starting with "test" inside of the "scripts" object to read:
3232

33-
```"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(axios)/)' --detectOpenHandles",~~~
33+
```
34+
"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!(axios)/)' --detectOpenHandles",
35+
```
3436

3537
#### Turn in instructions
3638

@@ -43,8 +45,10 @@ In calculator-backend/tests, there's a file called calculate.test.js. The code c
4345

4446
Run the test by executing:
4547

46-
```cd calculator-backend
47-
npm test~~~
48+
```
49+
cd calculator-backend
50+
npm test
51+
```
4852

4953
It should execute the test and show that it passed.
5054

@@ -70,12 +74,14 @@ You'll need to install more npm modules to test the front end.
7074

7175
Execute these three commands:
7276

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+
```
7581

7682
There's already an App.test.js in the src/ directory. It has the test code for App.js.
7783

78-
Let's run that using ```npm test~~~.
84+
Let's run that using ```npm test```.
7985

8086
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'.
8187

@@ -95,11 +101,14 @@ First, we need to add an HTML attribute to the appropriate div so we can refer t
95101

96102
In Calculator.js, add the attribute 'data-testid="total"' to the div with the className 'expression'. It should look like this:
97103

98-
```<div className="expression" data-testid ="total">{expression || "0"}</div>~~~
104+
```
105+
<div className="expression" data-testid ="total">{expression || "0"}</div>
106+
```
99107

100108
Second, in the calculator-frontend/src directory, add a new file called Calculate.tests.js. Put this code in your file:
101109

102-
```import { render, fireEvent, screen } from '@testing-library/react'
110+
```
111+
import { render, fireEvent, screen } from '@testing-library/react'
103112
import '@testing-library/jest-dom'
104113
import Calculator from './Calculator'
105114
@@ -122,9 +131,8 @@ it('Appends the number when pressed', async () => {
122131
123132
// get the expression DOM node and check that it is 12
124133
expect(element).toHaveTextContent('12');
125-
126-
127-
});~~~
134+
});
135+
```
128136

129137
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.
130138

@@ -159,7 +167,7 @@ Create a PR to commit your test code to the team's repository. Use your PR messa
159167

160168
Please provide us a link to your PR.
161169

162-
### 9. Review at least two PRs
170+
### 7. Review at least two PRs
163171

164172
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.
165173

@@ -174,3 +182,50 @@ Finally, once your PR has been approved, [merge it](https://docs.github.com/en/p
174182
#### Turn in instructions
175183

176184
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.
230+
231+

0 commit comments

Comments
 (0)