Skip to content

e2e devServerTarget doesn't seem to be working correctly #10697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oliverdavidt opened this issue May 7, 2018 · 21 comments · Fixed by #12507
Closed

e2e devServerTarget doesn't seem to be working correctly #10697

oliverdavidt opened this issue May 7, 2018 · 21 comments · Fixed by #12507
Labels

Comments

@oliverdavidt
Copy link

oliverdavidt commented May 7, 2018

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.

@Bjeaurn
Copy link

Bjeaurn commented May 8, 2018

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?

@sebastian-zarzycki-apzumi

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.

@pjmagee
Copy link

pjmagee commented Jun 1, 2018

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
Copy link

pjmagee commented Jun 1, 2018

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/ **

@sebastian-zarzycki-apzumi

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

@clydin clydin added needs: investigation Requires some digging to determine if action is needed severity1: confusing labels Jun 7, 2018
@listepo-alterpost
Copy link

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?

@Juansasa
Copy link

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

@tongfa
Copy link

tongfa commented Jul 13, 2018

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

@Smiter15
Copy link

Smiter15 commented Aug 8, 2018

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.

@aniruddhadas9
Copy link
Contributor

@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
Copy link
Contributor

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

@intellix
Copy link
Contributor

intellix commented Oct 8, 2018

Related: #11089

@filipesilva
Copy link
Contributor

Heya, we weren't computing host and port correctly in our Protractor setup. #12507 should fix it. Sorry about that!

@MRHarrison
Copy link

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

@Bjeaurn
Copy link

Bjeaurn commented Jan 23, 2019

@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?

@MRHarrison
Copy link

@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 } }));
  }
};

@Bjeaurn
Copy link

Bjeaurn commented Jan 23, 2019

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.

@MRHarrison
Copy link

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

@loganmzz
Copy link
Contributor

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
Copy link
Contributor

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

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.