It is possible to pass proxy-config parameter when running ng e2e command like this:
ng e2e --proxy-config proxy.conf.json
This is the same parameter as when running ng serve command, nevertheless it is not documented in the wiki:
https://github.com/angular/angular-cli/wiki/e2e
I personally think that it would save some developers time, when configuring protractor to run against the real backend, that requires proxy.
If the missed argument in the wiki is desired - is there any reason not to pass the argument just like we do when running ng serve?
Up to Angular 5, the parameter --proxy-config was working for both ng serve and ng e2e. Now it doesn't work anymore for ng e2e.
If anyone else stumbles on this wondering how to use a proxy for e2e-tests in Angular 6 then this is now done in the angular.json file by configuring the serve option used by your e2e tests devServerTarget and adding the proxyConfig to your options.
For example I have e2e tests for angular-login with the following configuration:
"angular-login-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular-login:serve"
}
}
}
}
The devServerTarget option refers to angular-login:serve which is the webpack dev server which will be started.
What you want to do is to add the proxyConf option to that dev server. In my angular-login's serve I have included proxyConfig under options, which will work聽the same way as before:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "angular-login:build",
"proxyConfig": "proxy.conf.json",
},
"configurations": {
"production": {
"browserTarget": "angular-login:build:production"
}
}
}
Is it possible to set the value of proxyConfig dynamically? We are currently creating a dynamic proxy config file in a temp folder for CI runs.
@plurch would it work to create a symlink from proxy.conf.json to the dynamically created one in the temporary directory?
Thanks for the suggestion, @mbark . Seems like that would work. We decided to just overwrite the same proxy.conf.json file directly.
thats works, THank you
Closing as this absolute and the new documentation is now available in https://angular.io/cli/e2e
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._
Most helpful comment
If anyone else stumbles on this wondering how to use a proxy for
e2e-tests in Angular 6 then this is now done in theangular.jsonfile by configuring theserveoption used by youre2etestsdevServerTargetand adding theproxyConfigto youroptions.For example I have
e2etests forangular-loginwith the following configuration:The
devServerTargetoption refers toangular-login:servewhich is the webpack dev server which will be started.What you want to do is to add the
proxyConfoption to that dev server. In myangular-login'sserveI have includedproxyConfigunderoptions, which will work聽the same way as before: