1

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
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • 2
    It looks to me like the test ran once, then npm reports both the stdout and stderr due to the script failing. Take note of the timestamps marked in brackets. Also note that the "Run time" reported is exactly the same in both outputs. I wouldn't expect that if the test was running more than once. – Randy Morris Feb 04 '15 at 11:36
  • @RandyMorris I tried `gulp test 2>/dev/null` but it didn't help. I start to suspect `gulp-shell` because of this line in the log: "Error in plugin 'gulp-shell'". Any ideas how to fix this? – Misha Moroshko Feb 04 '15 at 22:36

1 Answers1

0

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 }));
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • Note: gulp-shell is [blacklisted](https://github.com/gulpjs/plugins/blob/a6e707b784c87529f7b1dda8b5b355aaa86064a4/src/blackList.json#L13) – Heikki Feb 07 '15 at 10:45