Commit 218cd778 authored by Alexia Ognard's avatar Alexia Ognard Committed by Thibaud-Vdb
Browse files

feat:(job) create ng_test job

parent 9ac7cf2f
Loading
Loading
Loading
Loading

jobs/ng_test/README.md

0 → 100644
+45 −0
Original line number Diff line number Diff line
## Objective

This job allows you to run the units tests on Angular project. The `ng test` command builds the application in watch mode, and launches the Karma test runner.

## How to use it

1. Ensure sure that your project has 
   [`package.json`](https://docs.npmjs.com/cli/v6/configuring-npm/package-json){:target="_blank"}
1. You should specify your project name in the `PROJECT_NAME` variable, you can find it in your `angular.json` file under the `projects` section. You don't have to go through this step if there is a `defaultProject` value in your `angular.json` because the `ng test` command will be executed on the  `defaultProject`.
1. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/ng_test.yml'
    ```
1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
1. Well done, your job is ready to work ! 😀

## Job details

* Job name: `ng_test`
* Docker image:
[`timbru31/node-chrome:latest`](https://hub.docker.com/r/timbru31/node-chrome/)
* Default stage: `static_tests`
* When: `always`

### Variables

!!! info
    If no `PROJECT_NAME` have been specified it will execute the `ng test` command on the `defaultProject` specified in the `angular.json` file.

!!! note
    All paths defined in variables are relative and start from the root of your
    repository.

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` | Path to the root of project to test  | `.` |
| `PROJECT_NAME` | Project name specified in the `projects` section of the `angular.json` workspace configuration file. | ` ` |
| `NG_TEST_OPTIONS` | Additional options available for the user, they are added just after the test command | ` ` |
| `NG_CODE_COVERAGE` | 	Boolean which define if the script will output a code coverage report. | `true` |


### Cache

To cache `node_modules` folder for other `npm` jobs, take a look at [`npm_install`](/jobs/others/npm_install/#cache)

jobs/ng_test/job.yml

0 → 100644
+13 −0
Original line number Diff line number Diff line
name: ng_test
description: Ready to use job on Angular project that runs `test` specified on options.
default_stage: static_tests
icon: 🧪
maintainer: alexiaognard
license: Apache-2.0
images:
  timbru31/node-chrome:latest
tools:
labels:
    - GitLab
    - Test
    - Angular
 No newline at end of file
+35 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - static_tests

ng_test:
  image:
    name: timbru31/node-chrome:latest
    entrypoint: [""]

  stage: static_tests

  variables:
    PROJECT_ROOT: "."
    PROJECT_NAME: ""
    NG_TEST_OPTIONS: ""
    NG_CODE_COVERAGE: "true"

  script:
    # Working directory
    - cd $PROJECT_ROOT
    # Run npm install
    - npm install
    # Install angular dependencies
    - npm install -g @angular/cli
    # Run ng test
    - ng test $PROJECT_NAME $NG_TEST_OPTIONS --code-coverage=$NG_CODE_COVERAGE

  artifacts:
    when: always
    paths:
      - ${PROJECT_ROOT}/coverage/index.html
    reports:
      junit: ${PROJECT_ROOT}/coverage/index.html
+0 −0

Empty file added.

+1 −0
Original line number Diff line number Diff line
* Initial version
 No newline at end of file