Webpack: An npm error occurred while running `npm run unit -- --coverage=false`, but running `node_modules/.bin/jest --config test/unit/jest.conf.js` was normal

Created on 11 Jan 2018  ·  6Comments  ·  Source: vuejs-templates/webpack

Add an assertion failure expect(false).toBe(true) to test/unit/specs/HelloWorld.spec.js

import Vue from 'vue'
import HelloWorld from '@/components/HelloWorld'

describe('HelloWorld.vue', () => {
  it('should render correct contents', () => {
    const Constructor = Vue.extend(HelloWorld)
    const vm = new Constructor().$mount()
    expect(vm.$el.querySelector('.hello h1').textContent)
    .toEqual('Welcome to Your Vue.js App')

    expect(false).toBe(true) // for test
  })
})

Run command
npm run unit -- --coverage=false
Output

> [email protected] unit /xxx/cp1
> jest --config test/unit/jest.conf.js --coverage "--coverage=false"

 FAIL  test/unit/specs/HelloWorld.spec.js
  HelloWorld.vue
    ✕ should render correct contents (29ms)

  ● HelloWorld.vue › should render correct contents

    expect(received).toBe(expected)

    Expected value to be (using ===):
      true
    Received:
      false

      at Object.<anonymous> (test/unit/specs/HelloWorld.spec.js:10:19)
          at new Promise (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.118s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] unit: `jest --config test/unit/jest.conf.js --coverage "--coverage=false"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2018-01-11T08_09_15_737Z-debug.log

Run command
node_modules/.bin/jest --config test/unit/jest.conf.js
Output

➜  cp1 node_modules/.bin/jest --config test/unit/jest.conf.js
 FAIL  test/unit/specs/HelloWorld.spec.js
  HelloWorld.vue
    ✕ should render correct contents (26ms)

  ● HelloWorld.vue › should render correct contents

    expect(received).toBe(expected)

    Expected value to be (using ===):
      true
    Received:
      false

      at Object.<anonymous> (test/unit/specs/HelloWorld.spec.js:10:19)
          at new Promise (<anonymous>)
          at <anonymous>

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.092s
Ran all test suites.

Most helpful comment

@ruanjf npm run unit --silent works just as well, any reason for specifying the coverage?

found the following neat trick for test scripts here:

{
  "scripts": {
    "test": "jest || exit 0",
   }
}

All 6 comments

That's to be expected, if I understand your problem correctly.

Jest exits with an exit code of 1 if any tests fail, which npm always interprets as an error.

@LinusBorg Yes
Use npm run unit --silent -- --coverage=false to ignore error?

That would work, yes.

@ruanjf npm run unit --silent works just as well, any reason for specifying the coverage?

found the following neat trick for test scripts here:

{
  "scripts": {
    "test": "jest || exit 0",
   }
}

@therightstuff thanks

@therightstuff you suggestion actually fix the problem I encounter

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brucejcw picture brucejcw  ·  4Comments

v1ar31 picture v1ar31  ·  3Comments

paulgeisler picture paulgeisler  ·  3Comments

rkrejcii picture rkrejcii  ·  4Comments

SSmale picture SSmale  ·  3Comments