Search code examples
npmgulpjestjsgulp-shell

Why "gulp test" runs the tests twice?


I have the following setup:

package.json

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

gulpfile.js

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

When I run npm test, it runs tests once and stops.

But, running gulp test results in running the tests twice. See the log below.

Why is this happening and how would you fix that?

Log:

$ 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

Solution

  • Looks like the problem is that gulp-shell outputs the error the second time. This fixed the issue:

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