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

Refactor acceptance tests #1103

Merged
merged 1 commit into from
Dec 18, 2019
Merged

Refactor acceptance tests #1103

merged 1 commit into from
Dec 18, 2019

Conversation

chancancode
Copy link
Member

@chancancode chancancode commented Dec 17, 2019

The main goal is to get the tests to more accurately reflect what actually happen in real applications. Instead of mocking/reopening the application "port", we now directly replace the adapter with a TestAdapter that faithfully implements the required hooks the same way that a "real" adapter does.

This allows us to write acceptance tests by only sending/responding to messages in a way that is, as a far as the inspector app can is concerned, indistinguishable from the "real" ember debug behaves in the real world. The new API also allows us to be a bit more precise in terms of the expectations (messages sent/received the correct number of times, in the right order, etc).

Split from #1088. I'll rebase that PR and merge in these changes when this lands.

@wycats wycats force-pushed the refactor-acceptance-tests branch from fd26634 to 890ccb1 Compare December 17, 2019 23:55
@chancancode
Copy link
Member Author

I recommend that you start the review with tests/test-adapter.js, and also enable "Hide whitespace changes"

@wycats wycats force-pushed the refactor-acceptance-tests branch 2 times, most recently from 34a9699 to 5aad4a5 Compare December 18, 2019 00:42
The main goal is to get the tests to more accurately reflect what
actually happen in real applications. Instead of mocking/reopening
the application "port", we now directly replace the adapter with a
`TestAdapter` that faithfully implements the required hooks the
same way that a "real" adapter does.

This allows us to write acceptance tests by only sending/responding
to messages in a way that is, as a far as the inspector app can is
concerned, indistinguishable from the "real" ember debug behaves in
the real world. The new API also allows us to be a bit more precise
in terms of the expectations (messages sent/received the correct
number of times, in the right order, etc).
@wycats wycats force-pushed the refactor-acceptance-tests branch from 5aad4a5 to 0b541c6 Compare December 18, 2019 01:24
if (!this.detectedApplications.mapBy('applicationId').includes(app.applicationId)) {
this.detectedApplications.push(app);
}
message.apps.forEach(({ applicationId, applicationName }) => {
Copy link
Member

Choose a reason for hiding this comment

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

Does this not need to do a push into this.detectedApplications? Is it not a list?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not a list anymore, it is a dictionary/object of { applicationId: applicationName } (e.g. { "ember123": "Ember Inspector", "ember456": "Ember Observer" }), so it uses Ember.set to instead

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. So this is setting the application name under the key of application id. Makes sense 👍 .


selectedDidChange: observer('selectedApp', function() {
this.port.set('applicationId', this.selectedApp);
}),
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 seems unnecessary, since we already have an action here, and on the port side we also have a callback to maintain the applicationId/applicationName when they change.

@@ -98,7 +98,6 @@ export default Controller.extend({
*/
pinnedObjectId: null,
inspectingViews: false,
viewTreeLoaded: false,
Copy link
Member Author

Choose a reason for hiding this comment

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

Now unneeded, since the model hook of the route now blocks until the tree is loaded.

let Adapter;
if (typeOf(instance.adapter) === 'string') {
Adapter = instance.resolveRegistration(`adapter:${instance.adapter}`);
} else {
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 don't think this branch is possible: on line 9 we unconditionally set it to a string, so seems impossible for it to fall through.

@@ -19,6 +19,7 @@ export default Route.extend({
this.applicationBooted = ({ booted }) => {
if (booted) {
port.off('general:applicationBooted', this.applicationBooted);
this.applicationBooted = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

In deactivate it checks for this variable to avoid calling off twice, but we never unset it.

return new Promise(resolve => {
this.port.one('view:viewTree', resolve);
this.port.send('view:getTree');
});
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Now blocks until we get a tree, so we don't have to worry about the viewTreeLoaded = false state anymore

this.port.one('deprecation:deprecationsAdded', resolve);
this.port.send('deprecation:watch');
});
},
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 now blocks until we received the message from ember-debug, which is unconditional (it still sends it even when there are no deprecations).

* An array of objects of the form:
* { applicationId, applicationName }
* A dictionary of the form:
* { applicationId: applicationName }
Copy link
Member Author

Choose a reason for hiding this comment

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

Keep track of the names as well, in addition to the IDs. Changed from an array to a dictionary object.

@@ -132,7 +132,6 @@ const EmberDebug = EmberObject.extend({
this.startModule('deprecationDebug', DeprecationDebug);

this.generalDebug.sendBooted();
this.viewDebug.sendTree();
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 will be requested by the component tree route as needed.

@chancancode chancancode merged commit 8ab435e into master Dec 18, 2019
@delete-merged-branch delete-merged-branch bot deleted the refactor-acceptance-tests branch December 18, 2019 02:01
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.

2 participants