为什么 "gulp test" 运行两次测试?

Why "gulp test" runs the tests twice?

我有以下设置:

package.json

"scripts": {
  "test": "jest"
}

gulpfile.js

gulp.task('test', shell.task('npm test'));

当我 运行 npm test 时,它 运行 测试一次并停止。

但是,运行ning gulp test 导致 运行ning 测试两次。请参阅下面的日志。

为什么会发生这种情况,您将如何解决?

日志:

$ gulp test
[14:12:28] Using gulpfile e:\react-playground\gulpfile.js
[14:12:28] Starting 'test'...

> react-playground@1.0.0 test e:\react-playground
> jest

Using Jest CLI v0.2.2
Waiting on 1 test...
 FAIL  search-panel\questions\__tests__\questions-test.js (1.145s)
● Questions › it should render content
  - Expected: 'Hi! Questions here' toEqual: 'Hi! Questions here2'
        at new jasmine.ExpectationResult (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:115:32)
        at null.toEqual (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:1236:29)
        at Spec.<anonymous> (e:\react-playground\src\search-panel\questions\__tests__\questions-test.js:14:55)
        at jasmine.Block.execute (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:1065:17)
        at jasmine.Queue.next_ (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:2098:31)
        at null._onTimeout (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:2088:18)
        at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 test failed, 0 tests passed (1 total)
Run time: 1.416s
npm ERR! Test failed.  See above for more details.
npm[14:12:30] 'test' errored after 2.32 s
[14:12:30] Error in plugin 'gulp-shell'
Message:
    Command failed: npm ERR! Test failed.  See above for more details.
npm
Details:
    killed: false
    code: 1
    signal: null
    stdout:
> react-playground@1.0.0 test e:\react-playground
> jest

Using Jest CLI v0.2.2
Waiting on 1 test...
 FAIL  search-panel\questions\__tests__\questions-test.js (1.145s)
● Questions › it should render content
  - Expected: 'Hi! Questions here' toEqual: 'Hi! Questions here2'
        at new jasmine.ExpectationResult (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:115:32)
        at null.toEqual (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:1236:29)
        at Spec.<anonymous> (e:\react-playground\src\search-panel\questions\__tests__\questions-test.js:14:55)
        at jasmine.Block.execute (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:1065:17)
        at jasmine.Queue.next_ (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:2098:31)
        at null._onTimeout (e:\react-playground\node_modules\jest-cli\vendor\jasmine\jasmine-1.3.0.js:2088:18)
        at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 test failed, 0 tests passed (1 total)
Run time: 1.416s

    stderr: npm ERR! Test failed.  See above for more details.
npm

看起来问题是gulp-shell第二次输出错误。这解决了问题:

gulp.task('test', shell.task('npm test', { ignoreErrors: true }));