Node.js project

In the following example we’re building and testing a Node.js project using the official node docker image.

There are three stages of the pipeline:

  • deps — installs all the required dependencies (mocha, nyc)
  • test — runs unit tests and shows the total code coverage
  • coverage — ensures that the total coverage is not below 90%
image: node:13

stages:
  - deps
  - test
  - coverage

install dependencies:
  stage: deps
  commands:
    - npm install

unit tests:
  stage: test
  commands:
    - node_modules/.bin/nyc --reporter=text node_modules/.bin/mocha

coverage:
  stage: coverage
  commands:
    # fail if the total coverage is below 90%
    - node_modules/.bin/nyc --check-coverage --lines 90

Last modified July 1, 2020