-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[CHORE] Refactor away from createStore
test helper
#6347
Conversation
5c8c793
to
e73aa7a
Compare
If this looks good I can do the same for |
e73aa7a
to
3bb4450
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
testRecord: DS.Model.extend(), | ||
}); | ||
}); | ||
this.owner.register('adapter:application', ApplicationAdapter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases where we have to register the corresponding RESTSerializer
? (previously the createStore was doing this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createStore
helper was actually registering the -default
serializer as the JSONAPISerializer
:
owner.register('serializer:-default', JSONAPISerializer); |
There were a few cases where I needed to do this where the test involves mocking the response from the adapter.
Some examples:
https://github.com/emberjs/data/pull/6347/files#diff-8aaaee520d117ac876f402e7a684ebd8R34
https://github.com/emberjs/data/pull/6347/files#diff-8aaaee520d117ac876f402e7a684ebd8R101
https://github.com/emberjs/data/pull/6347/files#diff-8aaaee520d117ac876f402e7a684ebd8R189
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my notes in setupStore
in #6353 for providing serializers. TL;DR we should always be supplying a serializer in tests unless we are testing the current default logic.
3bb4450
to
6164e5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the focus on eliminating createStore
, I'm alright with this being a slightly more minimal refactor away from createStore
vs fully modernizing all of the tests it touches. We do want to eliminate the usage of run
and reopen
but can do that in a follow up.
Left some comments for minor nits.
testRecord: DS.Model.extend(), | ||
}); | ||
}); | ||
this.owner.register('adapter:application', ApplicationAdapter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my notes in setupStore
in #6353 for providing serializers. TL;DR we should always be supplying a serializer in tests unless we are testing the current default logic.
Record = DS.Model.extend({ | ||
title: DS.attr('string'), | ||
wasFetched: DS.attr('boolean'), | ||
let Record = Model.extend({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer const in this situation as it would be a mistake to reassign
From emberjs#6166 This refactors some tests so that they don't rely on the `createStore` test helper. `createStore` was helpful in the past but is less so now that we have [nice APIs for dependency injection](https://guides.emberjs.com/release/applications/dependency-injection/). --- One test was removed from `unit/store/adapter-interop - Store working with a Adapter` because I don't think it was correct. Here was the test: https://github.com/emberjs/data/blob/39182f324d5777e4a75c4a582f0791631e37d8de/packages/-ember-data/tests/unit/store/adapter-interop-test.js#L28-L32 This test was, at one time, testing that it was possible to pass a factory as the `adapter` property to `Store`. This feature was removed in emberjs#3191 but the test continued passing because of the way the `createStore` works. https://github.com/emberjs/data/blob/39182f324d5777e4a75c4a582f0791631e37d8de/packages/-ember-data/tests/helpers/store.js#L57-L60
6164e5a
to
0f2acb6
Compare
Part of emberjs#6166 Follow up to emberjs#6347 This replaces usage of the `setupStore` helper for `tests/integration/relationships/*`.
Part of emberjs#6166 Follow up to emberjs#6347 This replaces usage of the `setupStore` helper for `tests/integration/relationships/*`.
Part of emberjs#6166 Follow up to emberjs#6347 This replaces usage of the `setupStore` helper for `tests/integration/relationships/*`.
From #6166
This refactors some tests so that they don't rely on the
createStore
test helper.createStore
was helpful in the past but is less so now that we have nice APIs for dependency injection.One test was removed from
unit/store/adapter-interop - Store working with a Adapter
because I don't think it was correct.Here was the test:
data/packages/-ember-data/tests/unit/store/adapter-interop-test.js
Lines 28 to 32 in 39182f3
This test was, at one time, testing that it was possible to pass a factory as the
adapter
property toStore
. This feature was removed in #3191 but the test continued passing because of the way thecreateStore
works.data/packages/-ember-data/tests/helpers/store.js
Lines 57 to 60 in 39182f3