npm error ELIFECYCLE while running the test

前端 未结 4 1532
甜味超标
甜味超标 2020-12-15 18:33

I am using mocha-phantomjs setup for unit testing. I have following package.json scriot to run the tests.

\"scripts\": {
\"test\": \"npm run testFlickr\",
\"         


        
相关标签:
4条回答
  • 2020-12-15 18:33

    I was having this same problem, and what fixed it for me was when I run my unit tests, do NOT use

    npm run test
    

    instead use:

    npm test
    
    0 讨论(0)
  • 2020-12-15 18:34

    And when I run the command npm test in cmd, the test run alright

    No they aren't. You have 6 failing tests. The exit code of mocha-phantomjs is equal to the number of failing tests. Run mocha-phantomjs ./test/FlickrTest.html directly and see what is failing. Realize the PhantomJS is a bit different than your browser - you may have to debug it.

    Your script setup is odd. You should just have:

    "scripts": {
       "test": "mocha-phantomjs ./test/FlickrTest.html"
    }
    

    Then the odd node errors should go away.

    0 讨论(0)
  • 2020-12-15 18:39

    This is a problem when using npm run, it has to do with Mocha exiting with code !== 0 whenever a test fails. If you are on Windows try this:

    "scripts": {
      "test": "npm run testFlickr || ECHO.",
      "testFlickr": "mocha-phantomjs ./test/FlickrTest.html || ECHO." 
    }
    
    0 讨论(0)
  • 2020-12-15 18:41

    When running npm test it squelches ELIFECYCLE errors so you never encounter this experience.

    Reference to code

    Once you move a test script to a different script-name you'll start seeing ELIFECYCLE errors.

    My fix is to add a exit 0 to the end of the command. For your code it would look like this:

    "scripts": {
      "test": "npm run testFlickr",
      "testFlickr": "mocha-phantomjs ./test/FlickrTest.html; exit 0" 
    }
    
    0 讨论(0)
提交回复
热议问题