如何使用配置为 ng e2e 指定端口和主机 [英] How to specify the port and host for ng e2e using configuration

查看:17
本文介绍了如何使用配置为 ng e2e 指定端口和主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用配置文件为 ng e2e 命令设置端口和主机?

How do you set the port and host for the ng e2e command using a configuration file?

我知道可以在命令行中使用以下语句

I am aware that it is possible to use the following statement at the command line

ng e2e --port <port number> --host <host>

这很好用,但在配置文件中设置端口和地址会更方便.我查看了 .angular-cli.json 并发现有一个名为 protractor.config.js 的文件,我无法弄清楚要进行哪些设置在该文件中使用,有一个 baseUrl 设置,但更改它对 ng e2e 命令使用的端口没有任何影响.它似乎在使用随机端口.

This works nicely, but it would be more convenient to set the port and address in the configuration file. I have looked inside .angular-cli.json and found that there is a file called protractor.config.js, I've not been able to figure out what settings to use in that file, there's a baseUrl setting, but changing that does not make any difference to the port that is used by the ng e2e command. It seems to be using a random port.

除了 baseUrl 我也试过设置 portseleniumPort 但它们没有区别.

Aside from baseUrl I have also tried setting port and seleniumPort but they make no difference.

输入 ng e2e 命令后,控制台中会出现以下输出

After entering the ng e2e command the following output appears in the in the console

** NG Live Development Server is running on http://localhost:49155 **

protractor.config.js 中,我将 baseUrl 设置为 http://localhost:50000.我观察到测试正在执行,我可以看到浏览器正在使用地址 http://localhost:49155 这不是我想要的地址.

In the protractor.config.js I have baseUrl set as http://localhost:50000. I have observed the tests executing and I can see that the browser is using the address http://localhost:49155 which is not the address that I desire.

ng --version 返回以下内容

@angular/cli: 1.0.0
节点:7.7.1
操作系统:win32 x64
@angular/common: 4.0.3
@angular/编译器:4.0.3
@角度/核心:4.0.3
@angular/表单:4.0.3
@angular/http: 4.0.3
@angular/平台浏览器:4.0.3
@angular/platform-b​​rowser-dynamic: 4.0.3
@角度/路由器:4.0.3
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.3

@angular/cli: 1.0.0
node: 7.7.1
os: win32 x64
@angular/common: 4.0.3
@angular/compiler: 4.0.3
@angular/core: 4.0.3
@angular/forms: 4.0.3
@angular/http: 4.0.3
@angular/platform-browser: 4.0.3
@angular/platform-browser-dynamic: 4.0.3
@angular/router: 4.0.3
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.3

推荐答案

通过修改项目 webapp-e2eangular.json 中设置主机和端口,例如:

Set the host and port in angular.json by modifying the project webapp-e2e , e.g:

"e2e": {
  "builder": "@angular-devkit/build-angular:protractor",
  "options": {
    "protractorConfig": "./protractor.conf.js",
    "devServerTarget": "webapp:serve",
    "port": 4201
  }

一旦 angular-cli 调用 webapp:serve-command,这将覆盖正在使用的端口.忘记 protractor.conf.js 文件 - 直到过程后期才使用它.

This will override the port being used once webapp:serve-command is invoked by angular-cli. Forget the protractor.conf.js file - it's not used until later in the process.

因此您可以独立或并行运行 ng serve --watch(用于服务和单元测试)和 ng e2e(用于 e2e 测试).

Thus you can run ng serve --watch (for serving and unit tests) and ng e2e (for e2e tests) independently or in parallell.

br,延斯

这篇关于如何使用配置为 ng e2e 指定端口和主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆