Skip to content

Commit fc9f652

Browse files
authored
Merge pull request ironhack-labs#2378 from ironhack-labs/automated-testing
Add automated testing
2 parents cb981d0 + 8c6e7c8 commit fc9f652

File tree

14 files changed

+172
-6349
lines changed

14 files changed

+172
-6349
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Automated Testing
2+
on: push
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Load code
8+
uses: actions/checkout@v2
9+
- name: Prepare environment
10+
uses: actions/setup-node@v2
11+
with:
12+
node-version: '14'
13+
check-latest: true
14+
- name: Install dependencies
15+
run: npm i
16+
- name: Run tests
17+
run: npm run test -- --ci --reporters=default --reporters=jest-junit
18+
- name: Reports the results of tests
19+
uses: IgnusG/jest-report-action@v2.3.3
20+
if: always()
21+
with:
22+
access-token: ${{ secrets.GITHUB_TOKEN }}
23+
run-name: test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.DS_Store
3+
.vscode
4+
package-lock.json
5+
yarn.lock
6+
*.log
7+
lab-solution.html

README.md

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,86 @@
22

33
# LAB | JS Functions & Arrays
44

5+
<br>
6+
57
## Introduction
68

79
Manipulating arrays in code is a very common operation. Whether you are creating a total for a shopping cart, grabbing only the first names out of a list of people, or moving a piece on a chessboard, you are probably going to be modifying or manipulating an array in some way.
810

911
## Requirements
1012

1113
- Fork this repo
12-
- Clone this repo
14+
- Clone it to your machine
15+
- Visit the "actions" tab in your fork, and enable workflows.
1316

1417
## Submission
1518

1619
Upon completion, run the following commands:
1720

18-
```
19-
$ git add .
20-
$ git commit -m "done"
21-
$ git push origin master
21+
```bash
22+
git add .
23+
git commit -m "Solved lab"
24+
git push origin master
2225
```
2326

2427
Create Pull Request so your TAs can check up your work.
2528

29+
<br>
30+
2631
## Automated Testing Introduction
2732

33+
<br>
34+
2835
### What is automated testing?
2936

3037
Automated software testing is the process of programmatically executing an application in order to validate and verify that it meets the business needs, as well as the technical requirements, and that it behaves as expected.
3138

3239
Testing should be viewed as a continuous process, not a discrete operation or single activity in the development lifecycle. Designing tests at the beginning of the product lifecycle can be help to mitigate common issues that arise when developing complex code bases.
3340

34-
Having a strong _test suite_ can provide you ease of mind, since you will be able to confidently improve upon your work while knowing that your not breaking a previously developed feature.
41+
Having strong _test suites_ can provide you ease of mind, since you will be able to confidently improve upon your work while knowing that your not breaking a previously developed feature.
42+
43+
<br>
3544

3645
### Testing labs
3746

3847
This lab, along with some of the labs you will be working on during the bootcamp, has a complete test suite that is meant to ensure that your work fulfills the requirements we established.
3948

40-
### Testing with Jasmine
41-
42-
<!-- ![Jasmine Logo](https://i.imgur.com/A1pop7h.png) -->
49+
<br>
4350

44-
Jasmine is an automated testing framework for JavaScript. It is designed to be used in Behavior-driven Development (**BDD**) programming, which focuses more on the business value than on the technical details.
51+
### Testing with Jest
4552

46-
We have already included Jasmine in the project you just forked, so let's see how to use it to implement our code.
53+
Jest is an automated test-runner for JavaScript.
4754

48-
### Usage
55+
Before start coding, we will explain the project structure we have provided you.
4956

50-
Before start coding, we will explain the project structure we have provided you:
57+
We will be working with the `src/functions-and-arrays.js` file. To run your tests, open your terminal at the root directory of the lab, run `npm install` to install your dependencies and `npm run test:watch` to generate the `lab-solution.html` file. In case you want to check the tests, they are in the `tests/functions-and-arrays.spec.js` file.
5158

52-
```
53-
lab-js-functions-and-arrays
54-
├── README.md
55-
├── SpecRunner.html
56-
├── jasmine
57-
│   └── ...
58-
├── src
59-
│   └── functions-and-arrays.js
60-
└── tests
61-
└── functions-and-arrays.spec.js
62-
```
63-
64-
We will be working with the `src/functions-and-arrays.js`. In the `jasmine` folder you can find all of the files needed to use Jasmine. All these files are already linked with the `SpecRunner.html` file. In case you want to check the tests, they are in the `tests/functions-and-arrays.spec.js` file.
65-
66-
#### Run tests
59+
Open the `lab-solution.html` file using the live server VSCode extension.
6760

68-
Running automated tests with Jasmine is super easy. All you need to do is open the `SpecRunner.html` file in your browser. You will find something similar this:
69-
70-
![image](https://user-images.githubusercontent.com/23629340/33389609-c2f3965c-d533-11e7-9a03-e0a89314dd98.png)
61+
<br>
7162

7263
#### Pass the tests
7364

74-
You should write your code on the `src/functions-and-arrays.js` file. While following the instructions for each iteration, you should check every test and make sure it's _passing_, before moving on.
65+
You should work on the `src/functions-and-arrays.js` file. While following the instructions for each iteration, you should check every test and make sure it's _passing_, before moving on.
7566

7667
Do not rush. You should take your time to carefully read every iteration, and you should address the _breaking_ tests as you progress through the exercise.
7768

7869
When coding with tests, it is super important that you carefully read and understand the errors you are getting, this way you will know for sure what's expected from your code.
7970

8071
Note that **you don't need to execute the functions yourself**, the tests are responsible for doing that. All you should do is declare them, make sure they deal with the parameters passed and that they return what is indicated on the iterations and in the test messages. For some iterations we provide you with a sample array, so that you can do some **manual** testing, if you wish.
8172

73+
<br>
74+
8275
## Instructions
8376

77+
<br>
78+
8479
### Iteration #1: Find the maximum
8580

8681
Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.
8782

83+
<br>
84+
8885
### Iteration #2: Find the longest word
8986

9087
Declare a function named `findLongestWord` that takes as an argument an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.
@@ -95,6 +92,8 @@ You can use the following array to test your solution:
9592
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
9693
```
9794

95+
<br>
96+
9897
### Iteration #3: Calculate the sum
9998

10099
Calculating a sum can be as simple as iterating over an array and adding each of the elements together.
@@ -107,6 +106,8 @@ You can use the following array to test your solution:
107106
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
108107
```
109108

109+
<br>
110+
110111
#### Bonus - Iteration #3.1: A generic `sum()` function
111112

112113
**The goal: Learn how to refactor your code.** :muscle:
@@ -125,6 +126,8 @@ const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
125126
// should return: 57
126127
```
127128

129+
<br>
130+
128131
### Iteration #4: Calculate the average
129132

130133
Calculating an average is an extremely common task. Let's practice it a bit.
@@ -134,6 +137,8 @@ Calculating an average is an extremely common task. Let's practice it a bit.
134137
1. Find the sum as we did in the first exercise (or how about reusing that the _sumNumbers()_?)
135138
2. Take that sum and divide it by the number of elements in the list.
136139

140+
<br>
141+
137142
#### Level 1: Array of numbers
138143

139144
Declare a function named `averageNumbers` that expects an array of numbers and returns the average of the numbers:
@@ -144,6 +149,8 @@ You can use the following array to test your solution:
144149
const numbers = [2, 6, 9, 10, 7, 4, 1, 9];
145150
```
146151

152+
<br>
153+
147154
#### Level 2: Array of strings
148155

149156
Declare a function named `averageWordLength` that receives as a single argument an array of words and returns the average length of the words:
@@ -154,6 +161,8 @@ You can use the following array to test your solution:
154161
const words = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
155162
```
156163

164+
<br>
165+
157166
#### Bonus - Iteration #4.1: A generic `avg()` function
158167

159168
Create function `avg(arr)` that receives any mixed array and calculates average. Consider as mixed array an array filled with numbers and/or strings and/or booleans. We are following a similar logic to the one applied on the bonus iteration 4.1. :wink:
@@ -164,6 +173,8 @@ const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
164173
// should return: 5.7
165174
```
166175

176+
<br>
177+
167178
### Iteration #5: Unique arrays
168179

169180
Take the following array, remove the duplicates, and return a new array. You are more than likely going to want to check out the [`indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) Array method.
@@ -188,6 +199,8 @@ const words = [
188199
];
189200
```
190201

202+
<br>
203+
191204
### Iteration #6: Find elements
192205

193206
Let's create a simple array search.
@@ -200,6 +213,8 @@ You can use the following array to test your solution:
200213
const words = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
201214
```
202215

216+
<br>
217+
203218
### Iteration #7: Count repetition
204219

205220
Declare a function named `howManyTimes` that will take in an array of words as the first argument, and a word to search for as the second argument. The function will return the number of times that word appears in the array.
@@ -222,6 +237,8 @@ const words = [
222237
];
223238
```
224239

240+
<br>
241+
225242
### Bonus - Iteration #8: Product of adjacent numbers
226243

227244
What is the greatest product of four adjacent numbers? We consider adjacent any four numbers that are next to each other horizontally or vertically.
@@ -265,8 +282,12 @@ const matrix = [
265282
];
266283
```
267284

285+
<br>
286+
268287
### Bonus - Iteration #8.1: Product of diagonals
269288

270289
Following the logic you've used in iteration #8, declare a function called `greatestProductOfDiagonals(matrix)`. It takes a matrix as a parameter and returns the greatest product of any four values layed out diagonally, in either direction.
271290

291+
<br>
292+
272293
**Happy coding!** :heart:

SpecRunner.html

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

0 commit comments

Comments
 (0)