Skip to content
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

Visit('foo'), route goes to localhost:4200/foo in test #279

Closed
quantuminformation opened this issue Jul 12, 2017 · 18 comments
Closed

Visit('foo'), route goes to localhost:4200/foo in test #279

quantuminformation opened this issue Jul 12, 2017 · 18 comments
Labels

Comments

@quantuminformation
Copy link

quantuminformation commented Jul 12, 2017

This is making it impossible to run the tests as every route navigation changes the window location. It almost as if the test runner is not running under environment === 'test'. Integration tests render fine inside the #ember-testing

Empty ember-testing div, and the app in the wrong place:

image

env config:

  if (environment === 'test') {
    // Testem prefers this...
    ENV.locationType = 'none';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
    ENV.host = '';
  }

test:

import {test} from 'qunit';
import moduleForAcceptance from 'foo/tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | all');

test('visiting /', function (assert) {
  visit('/');

  andThen(function () {
    assert.equal(currentURL(), '/');

Can anyone imagine a probable cause of this?

  "devDependencies": {
    "broccoli-asset-rev": "^2.4.5",
    "broccoli-json-module": "^1.0.0",
    "ember-ajax": "2.4.1",
    "ember-cli": "2.13.1",
    "ember-cli-app-version": "^3.0.0",
    "ember-cli-babel": "^6.0.0",
    "ember-cli-clipboard": "0.4.1",
    "ember-cli-datepicker": "2.0.1",
    "ember-cli-dependency-checker": "^1.3.0",
    "ember-cli-htmlbars": "^1.1.1",
    "ember-cli-htmlbars-inline-precompile": "^0.4.0",
    "ember-cli-inject-live-reload": "^1.4.1",
    "ember-cli-jshint": "2.0.1",
    "ember-cli-json-module": "0.0.3",
    "ember-cli-less": "^1.5.4",
    "ember-cli-qunit": "^4.0.0",
    "ember-cli-selectize": "0.5.12",
    "ember-cli-shims": "^1.1.0",
    "ember-cli-toggle": "2.0.2",
    "ember-cli-tooltipster": "^0.8.1",
    "ember-cli-uglify": "^1.2.0",
    "ember-export-application-global": "^2.0.0",
    "ember-froala-editor": "2.4.0",
    "ember-inflector": "^2.0.0",
    "ember-load-initializers": "^1.0.0",
    "ember-lodash": "0.0.11",
    "ember-mixinify-class": "1.0.1",
    "ember-multiselect-checkboxes": "0.10.3",
    "ember-radio-button": "1.0.7",
    "ember-resolver": "^4.0.0",
    "ember-route-action-helper": "1.0.0",
    "ember-sortable": "1.9.1",
    "ember-source": "~2.13.0",
    "ember-truth-helpers": "1.2.0",
    "emberx-file-input": "1.1.0",
    "emberx-select": "3.0.0",
    "loader.js": "^4.2.3",
    "memory-scroll": "0.2.0",
    "tooltipster": "^4.2.5"
  }
@quantuminformation
Copy link
Author

Could it be something related to the weird position of the testing div to the right,

image

@trentmwillis
Copy link
Member

Can you provide a reproduction of this issue? It is likely that this is specific to your setup as we haven't had reports of this being an issue before.

FWIW, the fact that neither the ENV.locationType or ENV.APP.rootElement leads me to believe that either the environment isn't being properly applied during build or the method by which you're creating the application is not applying the config properly.

@quantuminformation
Copy link
Author

quantuminformation commented Jul 26, 2017

Unfortunately, this is part of a large ember app which I can't really break down. However, It was part an upgrade recently and I took a lot of the default generated files from the cli init.

@quantuminformation
Copy link
Author

All the current tests were done with another test runner than embers one.

@quantuminformation
Copy link
Author

If you have ENV.APP.rootElement = '#ember-testing'; in your env, and rootElement: '#applicationContainer' in your app.js

is it expected that in the test runner you will have this dom output?

#ember-testing'
    applicationContainer

I'm not sure what you mean by

FWIW, the fact that neither the ENV.locationType or ENV.APP.rootElement

@trentmwillis
Copy link
Member

Ah, the custom rootElement being defined in app.js is likely causing the issue. The rootElement will determine where the application is rendered and thus if you have it defined to something other than #ember-testing, it will not render in the #ember-testing <div>.

@quantuminformation
Copy link
Author

quantuminformation commented Jul 27, 2017

So I got rid of my <div id="applicationContainer" class="application-container positioned-parent"></div> in my index.html (although I don't see why this should be neccessary) and removed rootElement: '#applicationContainer' from app.js

So my test code looks like this:

visit('/foo);
andThen(){
   //some code
}

However, the whole browser navigates away from localhost:4200/tests to localhost:4200/foo which kills the test session.

Thanks for any light you can shine on this as it's holding all of our e2e testings up(

@quantuminformation
Copy link
Author

I tried upgrading to latest versions of everything and still the same result.

@quantuminformation
Copy link
Author

quantuminformation commented Jul 27, 2017

I also did a cli upgrade and ember init and couldn't see any major testing fill diffs.

@quantuminformation
Copy link
Author

Found the styling issue, now to fix the test issue.

@quantuminformation quantuminformation changed the title App not being inserted into ember-testing div for acceptance tests Visit('foo'), route goes to localhost:4200/foo in test Jul 27, 2017
@quantuminformation
Copy link
Author

quantuminformation commented Jul 28, 2017

Found the cause of the issue:

image

This code changes the url, boom!

Normally this wouldn't change the location:

image

@quantuminformation
Copy link
Author

So in our project when this line runs in the acceptance test: router.location.setURL(url);
it steps into:

function delegateToConcreteImplementation(methodName) {
    return function () {
      var concreteImplementation

But in the normal working case (window.location doesn't change) this:
image

@rwjblue
Copy link
Member

rwjblue commented Jul 28, 2017

Are you certain you are using none location in your tests? That code looks like auto location to me.

@rwjblue
Copy link
Member

rwjblue commented Jul 28, 2017

The default blueprint has this code to ensure that the location type is set to none in the test environment.

@quantuminformation
Copy link
Author

Default is:

locationType: 'auto',

and

  if (environment === 'test') {
    // Testem prefers this...
    ENV.locationType = 'none';

@rwjblue
Copy link
Member

rwjblue commented Jul 28, 2017

Yep, I know the default values, but that code snippet is from auto (here) not none so something is either changing the location or forcing a different one.

@quantuminformation
Copy link
Author

Yes your right, its being loaded in as auto in the test runner:

image

@quantuminformation
Copy link
Author

Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants