Running multiple commands for npm test

concurrently is a nice library that can handle this. It can be installed from npm.

npm install --save-dev concurrently

When each section is sorted as a separate script, the scripts section of package.json looks a bit like this:

{
  ...
  "scripts": {
    "test": "concurrently 'npm run karma' 'npm run protractor' 'npm run eslint' 'npm run htmlhint' 'npm run stylelint'",
    "karma": "karma start --single-run",
    "protractor": "protractor",
    "eslint": "eslint .",
    "htmlhint": "htmlhint 'app/**/*.html'",
    "stylelint": "stylelint 'app/**/*.css'",
  },
  ...
}

npm-run-all can also handle this well

You can run multiple npm commands concurrently, continuing on error as follows:

npm-run-all --parallel --continue-on-error karma protractor eslint htmlhint stylelint

Options as written in the documentation:

-p, --parallel <tasks>   - Run a group of tasks in parallel.
                           e.g. 'npm-run-all -p foo bar' is similar to
                                'npm run foo & npm run bar'.
-c, --continue-on-error  - Set the flag to continue executing other tasks
                           even if a task threw an error. 'run-p' itself
                           will exit with non-zero code if one or more tasks
                           threw error(s).

The scripts tags in package.json are run by your shell, so you can run the command that you want the shell to run:

"scripts": {
  "test": "karma ; protractor ; eslint ; htmlhint ; stylelint"
},

Will run all commands if you have a unix/OSX shell.

To be able to retain the exit_code like you specify you need to have a separate script to run the commands. Maybe something like this:

#!/bin/bash

EXIT_STATUS=0

function check_command {
    "$@"
    local STATUS=$?
    if [ $STATUS -ne 0 ]; then
        echo "error with $1 ($STATUS)" >&2
        EXIT_STATUS=$STATUS
    fi
}

check_command karma
check_command protractor
check_command eslint
check_command htmlhint
check_command stylelint
exit $EXIT_STATUS

Tags:

Node.Js

Npm