Skip to content

Commit

Permalink
[CHORE] eliminate legacy test-infra and simplify initializer (#6448)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Thoburn <[email protected]>
  • Loading branch information
snewcomer and runspired committed Sep 19, 2019
1 parent fe7d728 commit 27dbe82
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 129 deletions.
87 changes: 40 additions & 47 deletions packages/-ember-data/addon/setup-container.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
import { DebugAdapter } from './-private';
import { deprecate } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import Store from '@ember-data/store';

function hasRegistration(application, registrationName) {
// fallback our ember-data tests necessary
// until we kill-off setupStore
// see https://github.com/emberjs/data/issues/6357
// or @ember/test-helpers kills off it's
// legacy support that calls our initializer with registry
// instead of application
if (typeof application.hasRegistration !== 'function') {
return application.has(registrationName);
function initializeStore(application) {
// we can just use registerOptionsForType when we no longer
// support (deprecated) versions of @ember/test-helpers
// We're issuing a "private-api" deprecation for users of the
// deprecated @ember/test-helpers versions, but will keep
// this for as long as until 4.0 as needed
if (DEBUG && !application.registerOptionsForType) {
deprecate(
`Deprecated test syntax usage detected!\n\n\t` +
`This test relies on a deprecated test setup that is no longer supported by EmberData.` +
` To resolve this you will need to be on a recent version of @ember/test-helpers` +
` AND your tests must use \`setApplication()\` instead of \`setResolver()\` and` +
` \`module()\` with \`setup*Test()\`instead of \`moduleFor*()\`.`,
false,
{
id: 'ember-data:legacy-test-helper-support',
until: '3.17',
}
);

application.optionsForType('serializer', { singleton: false });
application.optionsForType('adapter', { singleton: false });

if (!application.has('service:store')) {
application.register('service:store', Store);
}

return;
}
return application.hasRegistration(registrationName);
}
/*
Configures a registry for use with an Ember-Data
store. Accepts an optional namespace argument.

@method initializeStore
@param {Ember.Registry} registry
*/
function initializeStore(application) {
// we can just use registerOptionsForType when setupStore is killed
// see https://github.com/emberjs/data/issues/6357
let registerOptionsForType = application.registerOptionsForType || application.optionsForType;
registerOptionsForType.call(application, 'serializer', { singleton: false });
registerOptionsForType.call(application, 'adapter', { singleton: false });
application.registerOptionsForType('serializer', { singleton: false });
application.registerOptionsForType('adapter', { singleton: false });

if (!hasRegistration(application, 'service:store')) {
if (!application.hasRegistration('service:store')) {
application.register('service:store', Store);
}
}

/*
Configures a registry with injections on Ember applications
for the Ember-Data store. Accepts an optional namespace argument.
@method initializeDebugAdapter
@param {Ember.Registry} registry
*/
function initializeDataAdapter(registry) {
registry.register('data-adapter:main', DebugAdapter);
function initializeDataAdapter(application) {
application.register('data-adapter:main', DebugAdapter);
}

/*
Configures a registry with injections on Ember applications
for the Ember-Data store. Accepts an optional namespace argument.
@method initializeStoreInjections
@param {Ember.Registry} registry
*/
function initializeStoreInjections(registry) {
// registry.injection for Ember < 2.1.0
// application.inject for Ember 2.1.0+
let inject = registry.inject || registry.injection;
inject.call(registry, 'controller', 'store', 'service:store');
inject.call(registry, 'route', 'store', 'service:store');
inject.call(registry, 'data-adapter', 'store', 'service:store');
function initializeStoreInjections(application) {
let inject = application.inject || application.injection;
inject.call(application, 'controller', 'store', 'service:store');
inject.call(application, 'route', 'store', 'service:store');
inject.call(application, 'data-adapter', 'store', 'service:store');
}

export default function setupContainer(application) {
Expand Down
1 change: 1 addition & 0 deletions packages/-ember-data/tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function(environment) {
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}

return ENV;
Expand Down
5 changes: 0 additions & 5 deletions packages/-ember-data/tests/helpers/destroy-app.js

This file was deleted.

21 changes: 0 additions & 21 deletions packages/-ember-data/tests/helpers/module-for-acceptance.js

This file was deleted.

12 changes: 0 additions & 12 deletions packages/-ember-data/tests/helpers/owner.js

This file was deleted.

9 changes: 0 additions & 9 deletions packages/-ember-data/tests/helpers/resolver.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/-ember-data/tests/helpers/start-app.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/-ember-data/tests/integration/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module('integration/application - Injecting a Custom Store', function(hooks) {
hooks.beforeEach(function() {
let { owner } = this;

owner.unregister('service:store');
owner.register('service:store', Store.extend({ isCustom: true }));
owner.register('controller:foo', Controller.extend());
owner.register('controller:baz', {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module('integration/record-data - Custom RecordData Errors', function(hooks) {
let { owner } = this;

owner.register('model:person', Person);
owner.unregister('service:store');
owner.register('service:store', CustomStore);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module('integration/record-data - Record Data State', function(hooks) {
let { owner } = this;

owner.register('model:person', Person);
owner.unregister('service:store');
owner.register('service:store', CustomStore);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ module('integration/record-data - Custom RecordData Implementations', function(h

owner.register('model:person', Person);
owner.register('model:house', House);
owner.unregister('service:store');
owner.register('service:store', CustomStore);
owner.register('adapter:application', JSONAPIAdapter.extend());
owner.register('serializer:application', JSONAPISerializer.extend());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function(hoo
owner.register('model:person', Person);
owner.register('model:house', House);
owner.register('model:car', Car);
owner.unregister('service:store');
owner.register('service:store', CustomStore);
});

Expand Down
9 changes: 4 additions & 5 deletions packages/-ember-data/tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import Application from '../app';
import config from '../config/environment';
import RSVP from 'rsvp';
import resolver from './helpers/resolver';
import { setResolver } from '@ember/test-helpers';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';

import QUnit from 'qunit';
import DS from 'ember-data';
import { wait, asyncEqual, invokeAsync } from 'dummy/tests/helpers/async';

// TODO get us to a setApplication world instead
// seems to require killing off createStore
setResolver(resolver);
setApplication(Application.create(config.APP));

const { assert } = QUnit;
const transforms = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if (CUSTOM_MODEL_CLASS) {
})
);
owner.register('serializer:-default', JSONAPISerializer);
owner.unregister('service:store');
});

test('notification manager', function(assert) {
Expand Down Expand Up @@ -454,7 +455,7 @@ if (CUSTOM_MODEL_CLASS) {
kind: 'belongsTo',
inverse: null,
options: {},
key: 'house'
key: 'house',
},
};
} else {
Expand All @@ -470,7 +471,7 @@ if (CUSTOM_MODEL_CLASS) {
data: {
type: 'house',
id: '1',
attributes: { address: 'boat' }
attributes: { address: 'boat' },
},
});
store.push({
Expand Down Expand Up @@ -517,7 +518,7 @@ if (CUSTOM_MODEL_CLASS) {
kind: 'hasMany',
inverse: null,
options: {},
key: 'house'
key: 'house',
},
};
} else {
Expand All @@ -533,7 +534,7 @@ if (CUSTOM_MODEL_CLASS) {
data: {
type: 'house',
id: '1',
attributes: { address: 'boat' }
attributes: { address: 'boat' },
},
});
store.push({
Expand All @@ -543,13 +544,10 @@ if (CUSTOM_MODEL_CLASS) {
attributes: { name: 'chris' },
relationships: {
house: {
data: [
{ type: 'house', id: '1' },
{ type: 'house', id: '2' }
]
}
}
}
data: [{ type: 'house', id: '1' }, { type: 'house', id: '2' }],
},
},
},
});
let relationship = store.relationshipReferenceFor({ type: 'person', id: '7' }, 'house');
assert.deepEqual(relationship.ids(), ['1', '2'], 'relationship found');
Expand Down

0 comments on commit 27dbe82

Please sign in to comment.