Node.js project

A simple example of a pipeline for a Node.js project with NPM, NYC & Mocha.

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

  - deps
  - test
  - coverage

install dependencies:
  stage: deps
    - npm install

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

  stage: coverage
    # fail if the total coverage is below 90%
    - node_modules/.bin/nyc --check-coverage --lines 90
Last modified October 21, 2020