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

[CHORE] Refactor away from createStore test helper #6347

Merged
merged 1 commit into from
Aug 22, 2019

Conversation

HeroicEric
Copy link
Member

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:

test('Adapter can be set as a factory', function(assert) {
store = createStore({ adapter: TestAdapter });
assert.ok(store.get('defaultAdapter') instanceof TestAdapter);
});

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 #3191 but the test continued passing because of the way the createStore works.

if (typeof adapter !== 'string') {
env.registry.register('adapter:-ember-data-test-custom', adapter);
adapter = '-ember-data-test-custom';
}

@HeroicEric
Copy link
Member Author

If this looks good I can do the same for setupStore

Copy link
Contributor

@snewcomer snewcomer left a 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);
Copy link
Contributor

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)

Copy link
Member Author

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

Copy link
Contributor

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.

@runspired runspired added the 🌲 Project Trim 🌲 PRs related to https://github.com/emberjs/data/issues/6166 label Aug 20, 2019
Copy link
Contributor

@runspired runspired left a 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);
Copy link
Contributor

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.

packages/-ember-data/tests/unit/debug-test.js Outdated Show resolved Hide resolved
Record = DS.Model.extend({
title: DS.attr('string'),
wasFetched: DS.attr('boolean'),
let Record = Model.extend({
Copy link
Contributor

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
@runspired runspired merged commit 4aa8e41 into emberjs:master Aug 22, 2019
HeroicEric added a commit to HeroicEric/data that referenced this pull request Aug 22, 2019
Part of emberjs#6166
Follow up to emberjs#6347

This replaces usage of the `setupStore` helper for
`tests/integration/relationships/*`.
HeroicEric added a commit to HeroicEric/data that referenced this pull request Aug 22, 2019
Part of emberjs#6166
Follow up to emberjs#6347

This replaces usage of the `setupStore` helper for
`tests/integration/relationships/*`.
HeroicEric added a commit to HeroicEric/data that referenced this pull request Aug 22, 2019
Part of emberjs#6166
Follow up to emberjs#6347

This replaces usage of the `setupStore` helper for
`tests/integration/relationships/*`.
runspired pushed a commit that referenced this pull request Aug 22, 2019
…6361)

Part of #6166
Follow up to #6347

This replaces usage of the `setupStore` helper for
`tests/integration/relationships/*`.
@runspired runspired mentioned this pull request Aug 23, 2019
65 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌲 Project Trim 🌲 PRs related to https://github.com/emberjs/data/issues/6166
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants