angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

e2e devServerTarget doesn't seem to be working correctly

Open oliverdavidt opened this issue 8 years ago • 21 comments

Versions

Angular CLI: 6.0.0
Node: 8.9.4
OS: darwin x64
Angular: 6.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... elements, forms, http, language-service, material
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.5.12
@angular-devkit/build-optimizer   0.5.12
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0-rc.10
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.0.0
typescript                        2.7.2
webpack                           4.6.0

Repro steps

This may not be an issue, but rather a lack of understanding of how the new cli config works.

  • Update port option in myapp-app:serve to 8080
  • Set myapp-app-e2e:e2e option of devServerTarget to myapp-app:serve
  • Run ng e2e
  • Server starts up on localhost:4200 rather than specified port.

Again, maybe I am not understanding how this works, but I would think that if I set the devServerTarget e2e option then whatever configuration that server has it should pull through during the e2e task.

Observed behavior

ng e2e
** Angular Live Development Server is listening on localhost: 4200, open your browser on http://localhost:4200/ **

Desired behavior

I would expect server to startup on the specified port that is set in myapp-app:serve.

Mention any other details that might be useful (optional)

If I set the port option directly in the myapp-app-e2e:e2e options section, then it does respect that and starts up the server on that port.

oliverdavidt avatar May 07 '18 12:05 oliverdavidt

Same issue here, when I tried to add the options to the e2e part of the angular.json it failed because of Schema validation. Example:

Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(publicHost).

Only overriding the port there was fine though but we need some more settings to get serve to work. I managed to override port and host (not publicHost tho) either in the package.json (ng e2e --host <bla>) or in the angular.json (added to the options: {} part of the `e2e definition), as a temporary work around.

Are we misunderstanding what the devServerTarget is refering to?

Bjeaurn avatar May 08 '18 09:05 Bjeaurn

Same issue here. I was surprised to see that the port for e2e is different than what I specified in myapp:serve. For now overriding just port is fine, but I am confused nevertheless.

I am confused too. Documentation is very minimal and there needs to be more verbose examples of how to configure the angular.json file. Especially since the basic examples only show the argument way to define options, e.g --public-host, but doesnt explain if this is "publicHost" in the angular.json

pjmagee avatar Jun 01 '18 10:06 pjmagee

I am a god damn legend. I got it working, here is an example for you guys.

 "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": {
                        "browserTarget": "Project:build",
                        "hmrWarning": false,
                        "host": "myproject.com",
                        "port": 8000
                    },
                    "configurations": {
                        "hmr": {
                            "hmr": true,
                            "browserTarget": "Project:build:hmr"
                        },
                        "production": {
                            "hmr": false,
                            "browserTarget": "Projectbuild:production"
                        }
                    }
                },

Output message from Angular:

Angular Live Development Server is listening on myproject.com: 8000, open your browser on http://myproject.com:8000/ **

pjmagee avatar Jun 01 '18 10:06 pjmagee

You've misunderstood the original issue. It's not about setting a port for serve target.

Earlier we run --serve=false with --base-url or baseUrl(protractor.conf) for remote testing, but now that don't work. Any news about this bug?

listepo-alterpost avatar Jun 08 '18 14:06 listepo-alterpost

And i dont know why devServerTarget is a requirement either. --sever=false is a valid use case and now its gone

Juansasa avatar Jun 19 '18 12:06 Juansasa

I was able to delete devServerTarget from angular.json, the change the baseUrl parameter in the e2e project's protractor.conf.js file and point the e2e test to another port on localhost. I imagine adjusting baseUrl to point to another server would work just as well.

Angular 6.0.8

tongfa avatar Jul 13 '18 20:07 tongfa

With @tongfa's comment i was able to change host and port. Remove the "devServerTarget": "project-name:serve" like he mentions and in protractor.conf.js just update the baseUrl to contain both your host and port eg: baseUrl: 'http://project-name.local:8080/'

But really it should be picking it up as intended from the serve:options in angular.json.

Smiter15 avatar Aug 08 '18 15:08 Smiter15

@Smiter15 @tongfa it did not working for me. here is my configuration and I running ng e2e --configuration=e2e-ci --suite=home

            "e2e-ci": {
              "protractorConfig": "./protractor.conf.js",
              "baseUrl": "https://udc.dev.finra.org"
            }

aniruddhadas9 avatar Sep 27 '18 17:09 aniruddhadas9

I make it work and below is the stackoverflow link and details how it works

https://stackoverflow.com/questions/50744266/angular-cli-use-configuration-with-e2e-tests/52542761#52542761

aniruddhadas9 avatar Sep 27 '18 18:09 aniruddhadas9

Related: https://github.com/angular/angular-cli/issues/11089

intellix avatar Oct 08 '18 08:10 intellix

Heya, we weren't computing host and port correctly in our Protractor setup. https://github.com/angular/angular-cli/pull/12507 should fix it. Sorry about that!

filipesilva avatar Oct 08 '18 09:10 filipesilva

This doesn't work for me, because it strips the appended path.

When I run the tests it opens https://localhost not https://localhost/test/local/ which is the production build I need to test. It strips the path information. This used to work before without any issue. It was highly configurable but has now become too opinionated, please revert back, or have a deprecation warning or something.

I can get http://localhost to work for now, but this is not a complete test and bugs will arrive in the future and I'll can do is blame the angular framework to my VP, which makes me look silly.

Please add the previous functionality back.

        "e2e": {
          "configurations": {
            "noserve": {
              "devServerTarget": "",
              "baseUrl": "https://localhost/test/local/"
            }
          },

MRHarrison avatar Jan 23 '19 16:01 MRHarrison

@MRHarrison You will have to take a look at your protractor.conf.js and see what URL you're using there.

Can you post the result of that file?

Bjeaurn avatar Jan 23 '19 17:01 Bjeaurn

@Bjeaurn I changed the protractor.conf.js and removed baseUrl from angular.json file but same result.

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'https://localhost/test/local/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};

MRHarrison avatar Jan 23 '19 17:01 MRHarrison

Alright, you can still leave the baseUrl in the angular.json, but the entry point where Protractor connects to isn't directly linked to what's in the angular.json, that's just where the :serve is making it available.

I bet somewhere in your .e2e-spec.ts files you have a 'redirect' function redirecting to localhost or anything like that. Have you searched through all the .e2e-spec.ts files for localhost?

Only reason I know this by the way, is I ran into the exact same issue a week ago. I'm quite sure the application and framework are behaving as intended.

Bjeaurn avatar Jan 23 '19 17:01 Bjeaurn

@Bjeaurn What version are you using? Can't find another reference. When I switch from https://localhost/test/local/ to http://localhost in angular.json I do notice that the protocol does switch from https to http. So I know the baseUrl arg is taking affect.

MRHarrison avatar Jan 23 '19 17:01 MRHarrison

I confirm problem with URL stripping. We deployed many projects on a single Web server and using some path to access deployment.

For example, having project A with version 1.2 and 1.3, next project B with version 0.0.1 and 0.0.2, then web server on http://dev.mycompany.com. Finally a target URL is http://dev.mycompany.com/A/1.2 but test failed because http://dev.mycompany.com/ is not an Angular application ...

However as I have try to put baseUrl in Protractor configuration file, I suspect problem is on its side ?

loganmzz avatar Jan 25 '19 12:01 loganmzz

I found solution ... or the problem. Default generated E2E is accessing '/' instead of browser.baseUrl. See e2e/src/app.po.ts

loganmzz avatar Jan 25 '19 13:01 loganmzz