2015-10-17 7 views
10

私はノードに慣れていないし、 "適切な"環境で開発しています。 mochaと他のいくつかのモジュールと一緒に私の現在のプロジェクトのためにgulpをインストールしました。ここに私のgulpfile.jsです:私は「一口」を実行すると"Finishing"の後でGulpがハングアップする

var gulp = require('gulp'); 
var mocha = require('gulp-mocha'); 
var eslint = require('gulp-eslint'); 

gulp.task('lint', function() { 
    return gulp.src(['js/**/*.js']) 
     // eslint() attaches the lint output to the eslint property 
     // of the file object so it can be used by other modules. 
     .pipe(eslint()) 
     // eslint.format() outputs the lint results to the console. 
     // Alternatively use eslint.formatEach() (see Docs). 
     .pipe(eslint.format()) 
     // To have the process exit with an error code (1) on 
     // lint error, return the stream and pipe to failOnError last. 
     .pipe(eslint.failOnError()); 
}); 

gulp.task('test', function() { 
    return gulp.src('tests/test.js', {read: false}) 
     // gulp-mocha needs filepaths so you can't have any plugins before it 
     .pipe(mocha({reporter: 'list'})); 
}); 

gulp.task('default', ['lint','test'], function() { 
    // This will only run if the lint task is successful... 
}); 

、すべてのタスクを完了するために見えますが、ハングアップします。コマンドプロンプトに戻るにはCtrl + Cキーを押す必要があります。どのようにしてそれを正しく仕上げるのですか?

+0

、彼らがハングアップするのですか?私はここにあなたのコードをカットアンドペーストし、それを実行する問題はありません。何も掛からない。 – Louis

+0

これは後でお試しいただきます。ありがとうございます。 – Ooberdan

答えて

15

謝罪!これはgulp-mocha FAQに記載されていることが判明しました。引用すると:あなたのテストスイートは、あなたはまだ余韻コールバックを持っているので、それはあるかもしれないから出ていない場合は

テストスイートが

を出ていない、最も頻繁に開いているデータベース 接続によって引き起こされます。あなたはこの接続を閉じるか、次の操作を行う必要があります

gulp.task('default', function() { 
    return gulp.src('test.js') 
     .pipe(mocha()) 
     .once('error', function() { 
      process.exit(1); 
     }) 
     .once('end', function() { 
      process.exit(); 
     }); 
}); 
2

gulpタスク内にreturn文を追加します。または、コールバックを実行します。

gulp.task('default', ['lint','test'], function (next) { 
    // This will only run if the lint task is successful... 
    next(); 
}); 
+0

私は両方のコールバックを試して、無駄な返品を追加しました。 – Ooberdan

3

あなたはgulp-mocha後に何を実行していない場合は、受け入れられた解決策は、あなたのために動作します。これがために機能

gulp.on('stop',() => { process.exit(0); }); 
gulp.on('err',() => { process.exit(1); }); 

:あなたは(ビルドを展開する前に、モカ・テストを実行しているなど)gulp-mocha後にタスクを実行する必要がある場合は、ここではまだgulp-mocha後タスクの実行を可能にしながら無限にハングからgulpを防ぐことができます解決策ですgulpinheritsorchestratoremits the eventsすべてのタスクが完了またはエラーに実行された後。

2

mocha 4にアップグレードした後、--exitをmochaに渡すことで解決できました。

詳細については、https://boneskull.com/mocha-v4-nears-release/#mochawontforceexitを参照してください。

ゴクゴク-モカを使用して、exit: trueなどのようにオプションを追加します:あなたは( `一気test`、`一気lint`)自身でのタスクのいずれかを実行し

gulp.task('test', function() { 
    return gulp.src(['tests/**/*.spec.js'], {read: false}) 
    .pipe(mocha({ exit: true })); 
});