@@ -175,15 +175,13 @@ Next, we will create a `.gitlab-ci.yml` file to define our tests.
test binarysearch:
script:
- npm i -g jest
- npm install jest-junit
- jest binarysearch.test.js
- npm install jest
- node_modules/.bin/jest binarysearch.test.js
test linearsearch:
script:
- npm i -g jest
- npm install jest-junit
- jest linearsearch.test.js
- npm install jest
- node_modules/.bin/jest linearsearch.test.js
```
1. Select **Commit changes**.
@@ -198,7 +196,7 @@ Let’s take a look at this set of job definitions to see if they can be made mo
install deps:
stage: deps
script:
- npm install jest-junit
- npm install jest
cache:
key: $CI_COMMIT_REF_SLUG
paths:
@@ -226,7 +224,7 @@ The `.gitlab-ci.yml` file should now look like this:
install deps:
stage:deps
script:
-npm install jest-junit
-npm install jest
cache:
key:$CI_COMMIT_REF_SLUG
paths:
@@ -235,23 +233,21 @@ The `.gitlab-ci.yml` file should now look like this:
test binarysearch:
stage:test
script:
-npm i -g jest
-npm install jest-junit
-jest binarysearch.test.js
-npm install jest
-node_modules/.bin/jest binarysearch.test.js
test linearsearch:
stage:test
script:
-npm i -g jest
-npm install jest-junit
-jest linearsearch.test.js
-npm install jest
-node_modules/.bin/jest linearsearch.test.js
```
> With this definition, we create a cache with a key that matches the `CI_COMMIT_REF_SLUG`. This ensures that each job will receive a unique cache. The data being cached is the `node_modules` folder. To set up the cache for use, we use the script to run the install command for the `jest-junit` package, which we will use for report formatting in a later lab.
> With this definition, we create a cache with a key that matches the `CI_COMMIT_REF_SLUG`. This ensures that each job will receive a unique cache. The data being cached is the `node_modules` folder. To set up the cache for use, we use the script to run the install command for the `jest` package, which we will use to run the tests.
Now that we have a cache defined, we can remove the `jest-junit` package install from each job.
Now that we have a cache defined, we can remove the `jest` package install from each job.
1. Remove the `npm i jest-junit` commands from your jobs and replace it with a cache reference. Below is an example of the completed `.gitlab-ci.yml` file:
1. Remove the `npm install jest` commands from your jobs and replace it with a cache reference. Below is an example of the completed `.gitlab-ci.yml` file:
```yml
stages:
@@ -264,27 +260,25 @@ Now that we have a cache defined, we can remove the `jest-junit` package install
@@ -26,27 +26,25 @@ In this lab, we will explore the different ways that we can configure testing in
install deps:
stage:deps
script:
-npm install jest-junit
-npm install jest
cache:
key:$CI_COMMIT_REF_SLUG
paths:
-node_modules
test binarysearch:
before_script:
-npm install -g jest
stage:test
script:
-jest binarysearch.test.js
-node_modules/.bin/jest binarysearch.test.js
cache:
key:$CI_COMMIT_REF_SLUG
paths:
-node_modules
test linearsearch:
before_script:
-npm install -g jest
stage:test
script:
-jest linearsearch.test.js
-node_modules/.bin/jest linearsearch.test.js
cache:
key:$CI_COMMIT_REF_SLUG
paths:
@@ -115,27 +113,25 @@ Now that we have verified the auto cancel works, let's remove the failing job.
install deps:
stage: deps
script:
- npm install jest-junit
- npm install jest
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- node_modules
test binarysearch:
before_script:
- npm install -g jest
stage: test
script:
- jest binarysearch.test.js
- node_modules/.bin/jest binarysearch.test.js
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- node_modules
test linearsearch:
before_script:
- npm install -g jest
stage: test
script:
- jest linearsearch.test.js
- node_modules/.bin/jest linearsearch.test.js
cache:
key: $CI_COMMIT_REF_SLUG
paths:
@@ -154,24 +150,31 @@ In this task, we will add a test report to our test jobs.
1. Select **Edit > Edit in pipeline editor**.
1. We are going to adjust our `jest` commands for the `test binarysearch` and `test linearsearch` jobs to add a `testResultsProcessor` to the command. We can do this by adding the `--ci --testResultsProcessor=jest-junit` flags to the command. The `--ci` option is provided will make Jest assume it is running in a CI environment. Below is an example of both jobs after the changes have been made:
1. We are going to adjust our `jest` commands for the `test binarysearch` and `test linearsearch` jobs to add a `testResultsProcessor` to the command. We can do this by adding the `--ci --testResultsProcessor=jest-junit` flags to the command. The `--ci` option is provided will make Jest assume it is running in a CI environment. For this to work we also have to install `jest-junit`. Below is an example of the jobs after the changes have been made:
> This change not only reduces the total number of lines of code, but also makes it so if the artifact changes, you only need to change it in one place, rather than multiple locations.
@@ -21,20 +21,6 @@ For this task, we will be creating a web application to run in our review enviro
1. Select **Edit > Edit in pipeline editor**.
1. In your `install deps` job, add an install for express:
```yml
install deps: &cachedef
stage: deps
script:
- npm install jest-junit
- npm install express
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- node_modules
```
1. When we add express code into our `index.js` file, our tests will no longer be able to run against `index.js`, since running this will create a webserver that waits for connections. For now, we will comment our tests out. To do this, place a `.` character in front of each test job as shown below: