Angular migration (from 4 to 6) e2e --proxy-config not working

MarcoLe

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

The script listing looks as follows:

"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",
  },

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'.

The config in my angular.json looks as follows:

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"
            }
        }
    },
  ...

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"
                }
            }
        },

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.

MarcoLe

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:

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 ''"

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

http-backend-proxy is not working with protractor e2e

Angular migration (from 4 to 6) warning - Cant resolve stream

Angular 15: Proxy Config not Working or Deducted

'not found' error with proxy config in Angular 6

Lodash omit not working after angular migration to 6

proxy.config.json is not working in Angular 4/5 when i use ng build

E2E Angular 6 websocket mocking

Angular 6 generate the service in "e2e/app" folder

Running E2E Tests with Protractor and Angular 4

Template Url in component not working while Angular 1.5 to Angular 6 migration

"ng e2e" is failling probably in reason of proxy but "ng serve" and "ng test" are working

Can't run Angular > 2 e2e using protractor behind a proxy

Pug support for Angular 2 / Angular 4 / Angular 6 / Angular cli / Angular cli 6 (without custom WebPack config)

Migration from angular 5 to angular 6 - changes in @angular/core

Issue when using Angular CLI ng e2e and passing both --config and --specs options

config proxy in angular cli

angular ng e2e testcase with file download not working with headless chrome

How to run Protractor e2e tests with different environment variables (Angular 6)

Angular 6 / AngularFire migration

Angular 6 proxy.conf.json on apache not working

Is it possible to access localstorage from Angular proxy.config.js file?

Ionic 4 - Angular 6 formArrayName not working as expected

Angular proxy not working

Angular proxy config to change url

Android Room Migration from version 2 - 4?

Angular CLI upgrade from 6 to 7 not working

Different proxy config based on environment in Angular 2 CLI

How to deploy angular 2 application to HTTP server with proxy-config

Angular 4 with Angularfire2 and Firebase 4 Syntax Migration issues