&& amp;之后没有运行命令在npm脚本

时间:2016-04-08 22:42:55

标签: node.js gulp

这是我正在运行的 npm脚本(在我的package.json中定义):

  "scripts": {
    "test": "gulp && mocha-casperjs test/features/specs/*-spec.js"
  }

出于某种原因,我所有的gulp任务运行正常,但我的mocha测试从未运行过。因此,当gulp完全完成时我所看到的是:

$ npm test

> someApp@0.0.0 test /Users/me/code/projects/we-do-tdd
> gulp && mocha-casperjs test/features/specs/*-spec.js

[17:34:50] Using gulpfile ~/code/projects/someApp/gulpfile.js
[17:34:50] Starting 'default'...
[17:34:50] Starting 'bundleApp'...
[17:34:50] Finished 'bundleApp' after 17 ms
[17:34:50] Starting 'watch'...
[17:34:50] Finished 'watch' after 7.33 ms
[17:34:50] Starting 'startApp'...
[17:34:50] Finished 'startApp' after 6.63 ms
[17:34:50] Finished 'default' after 34 ms

gulpfile

"use strict";

var app = require('./server'),
    gulp = require('gulp'),
    runSequence = require('run-sequence'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    gutil = require('gulp-util'),
    babelify = require('babelify');

var scriptsCount = 0;

gulp.task('default', function (cb){
    runSequence(['bundleApp','watch'], ['startApp'], cb)
});

gulp.task('watch', function () {
    gulp.watch(['./src/*.js'], ['scripts']);
});

gulp.task('startApp', function (cb) {
    app.listen(3000, cb).on('error', function(err) {
        console.log(err);
    });;
});

gulp.task('bundleApp', function () {
    bundleApp(false);
});

function bundleApp() {
    scriptsCount++;
    var appBundler = browserify({
        entries: './src/components/app.js',
        debug: true
    })

    appBundler
        .transform("babelify", {presets: ["es2015", "react"]})
        .bundle()
        .on('error', gutil.log)
        .pipe(source('bundle.js'))
        .pipe(gulp.dest('./build/app/js'));
}

1 个答案:

答案 0 :(得分:10)

&&&在第一个命令finsihed之后执行,因为你的默认gulp任务没有终止,第二个命令永远不会被调用。

使用:

 "test": "gulp & mocha-casperjs test/features/specs/*-spec.js"

一个&同时运行命令。