2016-02-26 6 views
13

現在、プロジェクトをテストするためにgulpタスクを使用しています。 (gulp-postcssを使用して)Stylelint(gulp-htmlhintを使用して)npmテスト用に複数のコマンドを実行する

  • gulp-eslintを使用して)カルマ(非同期)
  • 分度器(子プロセス)
  • ESlint
  • HTMLHint
  • :これは、以下のツールを使用してタスクを実行します

これらのタスクのいずれかが失敗した場合、タスクは失敗します。

これらのツールはすべて、きれいなcliインターフェイスを備えています。そこで、代わりにnpmテストスクリプトを使用してこれらのツールを実行することにしました。

簡単に言えば、すべてのツールがフラグを設定せずに呼び出すだけです。そして、これは使用して行うことができます。

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

しかし、これはkarmaが失敗した場合、他のツールのいずれも実行しないことを意味します。

これらのツールをすべて実行するセットアップを作成することはできますが、いずれかのコマンドが失敗した場合はnpm testが失敗しますか? package.json

答えて

4

npm-run-allも、このほかに

を扱うことができる あなたは、複数のNPMを実行することができます同時にコマンドを実行し、次のようにエラーが発生し続けます。

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

マニュアルに書かれたよう

オプション:

-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). 
+1

私は実際には同時にこれを同時に優先します。 –

11

スクリプトタグはシェルによって運営されているので、あなたはシェルが実行するコマンドを実行することができます:あなたは、UNIX/OSXのシェルを持っている場合

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

は、すべてのコマンドを実行します。

exit_codeを指定できるようにするには、コマンドを実行するために別のスクリプトを用意する必要があります。おそらくこのような何か:

#!/bin/bash 

EXIT_STATUS=0 

function check_command { 
    "[email protected]" 
    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 
+0

これは、すべてのコマンドを実行しますが、それは以前の終了コードを無視して、最後のコマンドのコードが存在して終了します。この場合、失敗したテストは無視されます。 –

+0

私はこれの例を今追加しました。 – bolav

+0

最初の例の 'test'スクリプトはWindowsをサポートしていないので、'; '構文はPowerShellでは無効です。 –

7

concurrentlyこれを処理できる素敵なライブラリです。 npmからインストールできます。各セクションは別々のスクリプトとしてソートされている場合は

npm install --save-dev concurrently 

package.jsonのスクリプトセクションは、ビットのようになります。

{ 
    ... 
    "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'", 
    }, 
    ... 
} 
+2

'' 'test": "同時に実行する" "npm run protractor" 'npm run eslint' 'npm run htmlhint' 'npm run stylelint' "' '' '' 'test": "同時に実行する必要があります\ "npm run karma \" \ "npm run eslint \" \ "npm run htmlhint \" \ "npm run stylelint \" "' ''ウィンドウ上で実行します。 – lfree

関連する問題