简体   繁体   English

Angular CLI,覆盖由“ ng e2e”运行的命令?

[英]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. 我正在尝试在与本地计算机不同的服务器上对应用程序实例运行Angular的e2e测试。 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: 不幸的是,如果我过度修改/删除以下行,则angular.json文件将引发错误:

"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) 编写运行此命令的npm脚本(我可能最终会做)
  2. Find out how to overwrite what ng e2e does. 了解如何覆盖ng e2e功能。 If I can run the more complicated command here, it'll save productivity and feedback time. 如果我可以在这里运行更复杂的命令,它将节省生产力和反馈时间。

I'm on Angular V7. 我正在使用Angular V7。

Is overwriting ng e2e so that it executes node node_modules/protractor/bin/protractor e2e/protractor.conf.js instead possible? 是否可以覆盖ng e2e以便执行node node_modules/protractor/bin/protractor e2e/protractor.conf.js

Yup. 对。 I would do #1. 我会做#1。 That makes sense to update your package.json 更新您的package.json很有意义

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

and then just run npm run protractor . 然后运行npm run protractor The e2e command is also downloading chromedriver, the selenium jar file, and maybe geckodriver? e2e命令还会下载chromedriver,selenium jar文件以及geckodriver? with webdriver-manager. 与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. 如果您需要这样做,我只需要在后台进程中调用ng serve并运行它即可。 I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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