Angular-cli: ng test does not use --proxy-config

Created on 15 Mar 2018  路  6Comments  路  Source: angular/angular-cli

Spec request:

I would like to pass integration test with karma,
but ng test does not use -proxy-config.

So I have to change all mu URL + enable CORS to test my backend ... not very ptratical.

Could you activate this option ?

devkibuild-angular

Most helpful comment

yes I know, that's what I have found and used.
Still, it would be nice to have the same API for CLI exec and CLI test.

All 6 comments

Do you pass the --proxy-config flag when starting ng test?

yes when i run ng test --proxy-config proxy-config.json
here is the console:

[email protected] testp C:\me\js\Angular__tp-ng_innersource\Angular-tp-basic-http

ng test --proxy-config proxy-config.json

The option '--proxy-config' is not registered with the test command. Run ng test --help for a list of supported options.
17 03 2018 12:42:22.769:WARN [karma]: No captured browser, open http://localhost:9876/
17 03 2018 12:42:22.797:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
17 03 2018 12:42:22.797:INFO [launcher]: Launching browser Chrome with unlimited concurrency

By now you can achieve the same result configuring the karma.conf.js 'proxies' param:

proxies: {
      '/api': {
        'target': 'http://localhost:8080/api',
        'changeOrigin': true
      }
    }

yes I know, that's what I have found and used.
Still, it would be nice to have the same API for CLI exec and CLI test.

It is true that the unit tests do not share the serving setup as present in ng serve, but this is not something we intend to add.

ng serve is meant to provide a development server, and also provides some convenience features for common cases. For more complex cases, like proxies that need to be available for both serving and testing, the intent is to setup a more robust proxy on your machine that fits your specific needs.

Karma itself allows some proxying behaviour, but it is not very elaborate either.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MateenKadwaikar picture MateenKadwaikar  路  3Comments

daBishMan picture daBishMan  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

donaldallen picture donaldallen  路  3Comments

brtnshrdr picture brtnshrdr  路  3Comments