角度迁移(从4迁移到6)e2e --proxy-config不起作用 [英] Angular migration (from 4 to 6) e2e --proxy-config not working

查看:158
本文介绍了角度迁移(从4迁移到6)e2e --proxy-config不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将我的应用程序从4迁移到6,并且我无法执行代理脚本进行e2e测试.

I've been currently migrating my app from 4 to 6 and I can not executing my proxy script for my e2e tests.

脚本列表如下:

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "start:tst1": "ng serve --proxy-config config/proxy/proxy.tst1.json",
    "start:tst5": "ng serve --proxy-config config/proxy/proxy.tst5.json",
    ...
    "test:watch": "ng test",
    "lint": "ng lint --type-check true",
    "e2e": "ng e2e",
    "e2e:tst1": "ng e2e --proxy-config config/proxy/proxy.tst1.json",
    "e2e:tst5": "ng e2e --proxy-config config/proxy/proxy.tst5.json",
  },

我不了解的是,启动命令(ng服务)对于实例npm run start:tst5来说可以很好地工作.但是,当我尝试执行npm run e2e:tst5之类的e2e测试时,会抛出错误:Unknown option: '--proxyConfig'.

What I don't understand is, that the start commands (ng serve) work perfectly fine for instancenpm run start:tst5. But when I try to execute the e2e tests like npm run e2e:tst5 it throws me the error: Unknown option: '--proxyConfig'.

我的 angular.json 中的配置如下:

...
"lmsbo-bo-e2e": {
  "root": "e2e",
  "sourceRoot": "e2e",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "e2e/protractor.conf.js",
        "devServerTarget": "lmsbo-bo:serve"
      },
        "configurations": {
            "production": {
                "devServerTarget": "lmsbo-bo:serve:production"
            }
        }
    },
  ...

编辑

angular.cli中,我进行了以下添加的e2e测试:

Edit

I got the e2e test working with following addition in the angular.cli:

        "serve": {
            "builder": "@angular-devkit/build-angular:dev-server",
            "options": {
                "browserTarget": "lmsbo-bo:build",
                "proxyConfig": "config/proxy/proxy.tst5.json" <== **added this** line
            },
            "configurations": {
                "production": {
                    "browserTarget": "lmsbo-bo:build:production"
                }
            }
        },

但是这种解决方法不能令人满意.每当我想在另一个环境下执行时,我都必须更改这一行代码.我宁愿通过编写类似ng serve --proxy-config config/proxy/proxy.tst5.json.

But this solution approach is not satisfying by any means. I got to change this line of code every time I want to execute against another environment. I would rather want to manage this via command line by writing something like: ng serve --proxy-config config/proxy/proxy.tst5.json.

推荐答案

即使不再支持此功能并且github上已经存在一个开放问题,Ive发现了一种非常方便的方式来通过:

Even though this feature is not supported anymore and there is already an open issue on github, Ive found out a pretty convinient way to execute the proxy config via script:

在以下行(示例)中将package.json添加:

add in your package.json following lines (example):

"e2e:local": "ng config projects.**yourAppName**.architect.serve.options.proxyConfig **yourProxyFile1** && ng e2e && ng config projects.**yourAppName**.architect.serve.options.proxyConfig ''",
"e2e:tst1": "ng config config projects.**yourAppName**.architect.serve.options.proxyConfig **yourProxyFile2** && ng e2e && ng config projects.**yourAppName**.architect.serve.options.proxyConfig ''"

您要做的就是通过ng命令在angular.json中设置proxyConfig值,并在e2e测试完成后将其重置.确保ng命令正常运行(如果未将angular/cli路径添加到操作系统的环境属性中,然后重新启动计算机).

All you do is to set the proxyConfig value in your angular.json via ng command and reset it after the e2e tests are finished. Make sure the ng command is working (if not add your angular/cli path into your environment properties of your operating System and restart your computer).

这篇关于角度迁移(从4迁移到6)e2e --proxy-config不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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