简体   繁体   中英

Angular cli, overwrite the command that gets run by 'ng e2e'?

I'm trying run Angular's e2e tests against an instance of the application ON A DIFFERENT SERVER than my local machine. So to be clear, I'm not testing my local code .

I just need to run protractor without the angular build steps because it's a waste of time since the code I'm testing is on another server. Unfortunately, the angular.json file throws an error if i excessively modify/remove the following line:

"builder": "@angular-devkit/build-angular:protractor",

I already have a solution for this, but it's long winded and I'd like to be able to not change how my teammates are running tests from their shells:

node node_modules/protractor/bin/protractor e2e/protractor.conf.js

I have two thoughts:

  1. Write npm script which runs this command (what i'll likely end up doing)
  2. Find out how to overwrite what ng e2e does. If I can run the more complicated command here, it'll save productivity and feedback time.

I'm on Angular V7.

Is overwriting ng e2e so that it executes node node_modules/protractor/bin/protractor e2e/protractor.conf.js instead possible?

Yup. I would do #1. That makes sense to update your package.json

"scripts": {
  "protractor": "protractor e2e/protractor.conf.js"
}

and then just run npm run protractor . The e2e command is also downloading chromedriver, the selenium jar file, and maybe geckodriver? with webdriver-manager. If you want that as a pre-step:

"scripts": {
  "protractor": "protractor e2e/protractor.conf.js",
   // just download chromedriver and the selenium jar
  "preprotractor": "webdriver-manager update --gecko false"  
}

It also starts your angular application. If you need to do that, I would just call ng serve and run it in a background process. I hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM