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

[FEATURE] Support for ApplicationInstances in test helpers #12310

Closed

Conversation

trentmwillis
Copy link
Member

Addresses #12277. Adds the following:

  • Application#buildTestInstance, which creates a new instance of an application and registers test helpers on it.
  • ApplicationInstance#injectTestHelpers and ApplicationInstance#removeTestHelpers which are similar to the same name methods on Application, but bind the test helpers to the instance

Todo:

  • Discourage use of globals (by not supporting them in instance-based tests)
  • Tests (unsure how much coverage to include, as we could theoretically duplicate all the tests that use the current setup)

});

EmberApplicationInstance.reopen({
injectTestHelpers() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function and ApplicationInstance#removeTestHelpers are super similar to the same functions on Application, I was unsure if I should extract them out though as they differ on a couple lines

@trentmwillis trentmwillis force-pushed the instance-test-helpers branch 2 times, most recently from a89a98d to 60582b1 Compare September 9, 2015 21:44
@trentmwillis
Copy link
Member Author

@stefanpenner @rwjblue this is ready for an initial review.

Primary concern I have is the extent to test the instance-based approach, as I could duplicate all the current test helper tests, but that seems a bit ridiculous.


function currentRouteName(app) {
var appController = lookup(app, 'controller:application');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR directly, but we should update these to use service:-routing instead of controller:application.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a separate PR for that once this work is finished.

@rwjblue
Copy link
Member

rwjblue commented Sep 10, 2015

A few notes:

  • This should be feature flagged, as it adds new public API.
  • I would prefer to check something like app.isApplicationInstance instead of using instanceof.
  • I'm not a giant fan of instance.visit, I would prefer to just go with instance.testHelpers.visit and allow other test helpers to provide the sugar:
// in ember-qunit or ember-test-helpers
for (var helperName in this.instance.testHelpers) {
  this[helperName] = function() {
    this.instance.testHelpers[helperName](...arguments);
  }
}

// allows the following

test('visted foo', function(assert) {
  this.visit('foo');
});

@trentmwillis
Copy link
Member Author

I'll make those changes. I think leaving the mapping of the helpers to a more convenient location up to other libraries is fine. Chances are this.instance.visit will be modified to something like this.visit in almost all cases anyway.

@trentmwillis trentmwillis force-pushed the instance-test-helpers branch 2 times, most recently from 6aad2b2 to 62c3adb Compare September 11, 2015 00:19
@trentmwillis
Copy link
Member Author

@rwjblue updated with your requested changes. Also duplicated the current acceptance_test file to do the same tests but in the new format. This uncovered a good number of issues that I've since addressed.

There is one issue that I can't seem to solve, and that is the test with a redirect in it keeps failing. It doesn't seem to pick up on the intermediate transition and thus exits the test before all the assertions have been made. I'll keep digging, but would appreciate any thoughts on the matter.

@trentmwillis
Copy link
Member Author

Figured out the last issue, was calling the wrong handleURL method. Everything's green now.

@trentmwillis trentmwillis changed the title [WIP] Add support for ApplicationInstances in test helpers [FEATURE] Support for ApplicationInstances in test helpers Sep 11, 2015
@stefanpenner
Copy link
Member

I'm not a giant fan of instance.visit, I would prefer to just go with instance.testHelpers.visit and allow other test helpers to provide the sugar:

ah this was my question, so we follow up with ember-test-helpers PR to make this fancy.


this.testHelpers = {};
for (var name in helpers) {
this.testHelpers[name] = helper(this, name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really a fan of all this copying, but without a large refactoring i dont see a quick fix.

One idea, is rather then copying, the test frameworks gives us a TestHelpers object, something like

this.testHelpers = new TestHelpers(applicationInstance);
// internally, this.testHelpers now has a reference to the app instance, and can just do the right thing internally.

@stefanpenner
Copy link
Member

this LGTM

@trentmwillis
Copy link
Member Author

@rwjblue think this can this get merged?

@rwjblue
Copy link
Member

rwjblue commented Sep 15, 2015

@trentmwillis - Will try to review in detail tonight, sorry for the delays.

@trentmwillis trentmwillis force-pushed the instance-test-helpers branch 2 times, most recently from c1ff82e to 2042c6b Compare September 28, 2015 17:22
@trentmwillis
Copy link
Member Author

Rebased to get the latest changes in. @rwjblue any time to check this out soon?

@stefanpenner
Copy link
Member

Just did another pass, this looks good. My existing comments stands, but we can always address that later.

It's important somewhere, to bring attention to the fact that we don't (at least that is my understandating) actually intend the end user to use instance.testHelpers.click (atleast in most cases) the eventual goal is for the test helpers to sugar that to this.click etc.

@stefanpenner
Copy link
Member

we may have some overlap with: #12394

@chancancode r?

@trentmwillis
Copy link
Member Author

@stefanpenner @rwjblue had some time to revisit this and update it to take into consideration @chancancode's changes. Hoping we can finally get this in soon.

@trentmwillis
Copy link
Member Author

Looks like I finally managed to get the tests passing (other than one version of IE that timed out on Sauce Labs).

I'm not 100% sure why, but the ember-extension-support/tests/data_adapter_test.js file wasn't passing until I setup some of the Application calls in run-loops. Might have something to do with introducing new reopens?

@homu
Copy link
Contributor

homu commented Jan 20, 2016

☔ The latest upstream changes (presumably #12766) made this pull request unmergeable. Please resolve the merge conflicts.

@trentmwillis trentmwillis force-pushed the instance-test-helpers branch 2 times, most recently from fd4166e to 693c651 Compare January 20, 2016 04:47
@homu
Copy link
Contributor

homu commented Jan 29, 2016

☔ The latest upstream changes (presumably #12772) made this pull request unmergeable. Please resolve the merge conflicts.

@trentmwillis
Copy link
Member Author

@stefanpenner or @rwjblue rebased again, can either of you take a look at this? Or if it's been decided to not support this use case I'll close the PR

@nickiaconis
Copy link
Contributor

+1 Would love to see this get merged. Watching Trent's local copy of Ember, with this change applied, cruise through acceptance tests while my default copy slowly churned through those same tests was eye opening.

@homu
Copy link
Contributor

homu commented Feb 5, 2016

☔ The latest upstream changes (presumably #12575) made this pull request unmergeable. Please resolve the merge conflicts.

@stefanpenner
Copy link
Member

Let me give it a read. I do believe we want this, sorry for letting it slip

Example:

```javascript
var instance = run(App, 'buildTestInstance');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we should do a run.join inside of this method, so we don't need to enforce the external run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with that. Currently chose this approach to keep it similar to how start-app works.

@stefanpenner
Copy link
Member

@tomdale / @wycats needs your review

@rwjblue
Copy link
Member

rwjblue commented Feb 5, 2016

I'd like to have a meeting to discuss with @trentmwillis, @mmun, and I. Basically, I'd rather focus on implementing a new wholistic testing setup (will try to write the RFC tonight), and eventually completely remove/deprecate packages/ember-testing after a migration and wind down period (certainly supported through 3.0.0 though).

@trentmwillis
Copy link
Member Author

@rwjblue I think that is a good goal, though I would like to see this feature come sooner rather than later. I do, however, understand wanting to keep churn down and not introduce multiple major testing changes. So, let's talk sometime soon.

@tomdale
Copy link
Member

tomdale commented Feb 8, 2016

@rwjblue @trentmwillis One constraint I'd love for you guys to take into account when designing a holistic new test API is to not surface the concept of "application instance" to new developers. It's just a concept that is very useful for internals but adds complexity to the end user.

As discussed above, just do this.visit() instead of this.instance.visit(). The word "instance" should not appear anywhere; the user already knows they are testing an instance of their application, and how Ember chooses to represent that internally should stay insider baseball.

@rwjblue
Copy link
Member

rwjblue commented Feb 8, 2016

The word "instance" should not appear anywhere

Yes, agreed. It is a mega troll that we have Application instances and ApplicationInstance instances. We should not force the mental pain upon anyone else.

@trentmwillis
Copy link
Member Author

Closing this in favor of emberjs/rfcs#119.

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

Successfully merging this pull request may close these issues.

None yet

6 participants