-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[QUEST] Decouple Ember tests from the globals resolver #15058
Comments
i'm having some challenges converting the test case to_string_test.js. Converting the following line seems easy enough:
with:
in the new ApplicationTestCase sub-class constructor. The challenging part comes with resolving and looking up this model. The test-resolver.js has a
The PostFactory variable will now contain the class but calling its The original to_string_test.js file uses the following two App.__container __ method calls:
It looks like the test-resolver's So, finally my question: Any tips would be greatly appreciated! |
@pythonquick you've ended up in a non-trivial part of the migration. The Also, for you general reference, |
@mixonic thank you for the notes! I'll try to revisit to_string_test.js later on. Currently I'm trying to convert component_registration_test.js which looks easy enough. The old-style test deals with this by wrapping the expected deprecation in a call to expectDeprectation. Unfortunately there is no counterpart assert.expectDeprecation method, except when installing the ember-qunit-assert-helpers addon. Is there another way of dealing with expected deprecations in the new-style test case? |
1) Decouple the acceptance_test and helpers_test files from the globals resolver per emberjs#15058. 2) Update setupForTesting to reference the router factory in the registry instead of the globally resolved one on the application instance. 3) Extend the Router during application registry setup to isolate `reopen` calls.
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. I've removed the step testing function. This seemed to be more important for debugging the authoring of the original sets of tests instead of actually asserting code. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Refs emberjs#15058
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. I've removed the step testing function. This seemed to be more important for debugging the authoring of the original sets of tests instead of actually asserting code. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Refs emberjs#15058
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Also in the service of inclusivity 'smells' has been replaced by 'puppies' Refs emberjs#15058
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Also in the service of inclusivity 'smells' has been replaced by 'puppies' Refs emberjs#15058
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Also in the service of inclusivity 'smells' has been replaced by 'puppies' Refs emberjs#15058
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Also in the service of inclusivity 'smells' has been replaced by 'puppies' Refs emberjs#15058
I've moved this into three different test modules: * A default state that relies on the visit API. * A nested route module that has shared setup for roughly half the tests * An AutobootTestCase module for dealing with the one test case that cannot be worked around. The instance of 'BRO' has been replaced with 'TURTLE' because I hate fun and value inclusivity. Also in the service of inclusivity 'smells' has been replaced by 'puppies' Refs #15058
This is complete! 🎉 And we did it in under a year. 💪 Thank you @patricksrobertson @fsmanuel @josemarluedke @NullVoxPopuli @Karthiick @rwjblue @Gaurav0 @stevenwu @lbaillie @ballPointPenguin @defraz @cibernox @pythonquick (I apologize if I missed anyone) for your individual efforts on this huge undertaking. This was a big task and none of us could have completed it alone. You've exemplified what good open source contribution and collaboration looks like. 🙇 |
(lifted some of this introduction from #15055)
The Ember test suite is very coupled to the default globals-mode resolver. For example:
App.FooController
setTemplates
to set a template ontoEmber.TEMPLATES
App.Router
to set location or other configurationAll of these ways of passing things to Ember are considered part of the globals-mode resolver API.
At some far future date, we would like to drop the default resolver and its globals API from Ember. Nearly all (but not all) Ember apps are built using Ember-CLI. Those applications (with a few minor tweaks) do not need the default resolver. Already they use the ember-resolver, however this itself is a subclass of the default resolver and retains globals loading as a fallback behavior.
The first step (of many) toward removal of the globals-mode default resolver is to refactor Ember's test suite to not be reliant upon it. To this end #15055 introduced a configurable resolver mock to be used in Ember tests, ideally through the class-based testing abstraction added during the Glimmer2 test porting effort. For example:
Roughly taken from link-to-test.js.
ApplicationTestCase
will default to theModuleBasedTestResolver
mock. To break it down:ApplicationTestCase
is a subclass ofAbstractApplicationTestCase
AbstractApplicationTestCase
creates an application. The options default the resolver to theModuleBasedTestResolver
.ModuleBasedTestResolver
is a subclass ofTestResolver
. The module-based resolver will use loading substates (a feature globals mode cannot successfully be integrated with) but besides that there is no difference.Our goal is to migrate all tests in Ember that implicitly rely on the globals resolver to this improved testing style. Note that the aim really is to use the test resolver: Some tests may be avoiding the implicit default resolver by registering factories into the registry. Those tests should also be migrated to the mock resolver.
How to help
Figuring out what tests use the default resolver to pass is a little tricky since it is, well, default. Once you identify a test that uses the default resolver, you still must ascertain if that test is testing the default resolver or if it the dependency is only implicit. Most tests using the default resolver should be candidates for refactoring: They are not testing interaction with the resolver.
Running this
ag
call:Spits out a list of tests possibly using the globals resolver. I've narrowed that list to 28 files that look like good candidates for refactoring:
Your mission, should you choose to accept it, is to pick a file from that list and port it from the old style to a test that uses the class-based testing framework and does not use the global resolver.
A successfully converted file will:
ApplicationTestCase
though. In fact, there are already other test cases that might be more appropriate such asRenderTestCase
orAutobootApplicationTestCase
. However, all these class-based systems should default to theTestResolver
orModuleBasedTestResolver
. If you add or modify a test case, be sure it defaults to the test resolver.Resolver
. This subset of tests should opt-in to the global resolver. For an example of this seeapplication_test.js:193
.The following are useful resources in your journey:
test-resolver.js
frominternal-test-helpers
.test-cases/
folder ininternal-test-helpers
.autoboot
is used in these tests.Please see the Google spreadsheet "Ember tests using the globals resolver" to learn what files make good candidates for this work. Add your Github handle and the date there if you are attempting a refactor. Advanced Jedi may find refactoring opportunities not included in that spreadsheet, please feel free to add them and open a PR.
Thank you for your help! If you're attending EmberConf, perhaps I can pick up a ☕️ or 🍻 tab!
The text was updated successfully, but these errors were encountered: