ChrisBeyer
ChrisBeyer

Reputation: 59

If scripts fails, NPM should continue executing further ones

I have following script in my package.json file which I execute in my cmd by npm run protractor:

"scripts": {
    "postinstall": "bower install",
    "pretest": "npm install",
    "test": "karma start test/karma.conf.js",
    "test-single-run": "karma start test/karma.conf.js  --single-run",
    "preupdate-webdriver": "npm install",
    "update-webdriver": "webdriver-manager update",
    "preprotractor": "npm run update-webdriver && node setUp.js",
    "protractor": "protractor test/protractor-conf.js",
    "postprotractor": "node tearDown.js",
  }

If all my e2e test pass, npm runs the entire script - also my tearDown.js. However, in the event of a failure in my protractor tests ("protractor": "protractor test/protractor-conf.js"), npm does not continue to execute my postprotractor file(I need tearDown.js as it closes my backend). Is there any solution of making npm run the entire script?

Upvotes: 2

Views: 1759

Answers (1)

hankduan
hankduan

Reputation: 6034

You should run your setup script and teardown script as part of protractor in beforeLaunch and afterLaunch, not npm.

If for some reason you absolutely do not want to run it as part of protractor you would have to change the protractor exitCode to '0', either in afterLaunch (example) or by wrapping a script around your protractor run script. However, I highly advise against doing this because then you're just masking errors.

Upvotes: 2

Related Questions