How to create a npm script to run several commands to run some tests?

前端 未结 2 1138
春和景丽
春和景丽 2021-01-04 23:00

When I run the e2e tests for my angularjs application, I need to run following commands in different shell session:

// start the selenium server
webdriver-ma         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 23:26

    You should use npm-run-all (or concurrently, parallelshell), because it has more control over starting and killing commands. The operators &, | are bad ideas because you'll need to manually stop it after all tests are finished.

    Once npm-run-once, protractor, http-server installed, you can modify package.json like that:

    scripts: {
      "webdriver-start": "./node_modules/protractor/bin/webdriver-manager update && ./node_modules/protractor/bin/webdriver-manager start",
      "protractor": "./node_modules/protractor/bin/protractor ./tests/protractor.conf.js",
      "http-server": "./node_modules/http-server/bin/http-server -a localhost -p 8000",
      "python-example": "python -m SimpleHTTPServer",
      "test1": "npm-run-all -p -r webdriver-start http-server protractor",
      "test2": "npm-run-all -p -r webdriver-start python-example protractor"
    }
    

    -p = Run commands in parallel.

    -r = Kill all commands when one of them finishes with zero.

    Running npm run test1 will start Selenium driver, start http server (to serve you files) and run protractor tests. Once all tests are finished, it will close the http server and the selenium driver.

提交回复
热议问题