From 8356da89d570deee0cc64084f89624f81676b0d5 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 11 Sep 2023 01:54:24 -0700 Subject: [PATCH 1/6] chore: burn down runloop and RSVP usage --- .eslintrc.js | 10 +- package.json | 1 - packages/-ember-data/package.json | 1 - packages/adapter/rollup.config.mjs | 2 - packages/adapter/src/rest.ts | 5 +- packages/graph/rollup.config.mjs | 1 - packages/json-api/rollup.config.mjs | 2 - packages/json-api/src/-private/cache.ts | 10 +- packages/model/rollup.config.mjs | 2 - packages/model/src/-private/model.js | 5 +- .../-private/managers/notification-manager.ts | 1 + packages/store/src/-private/store-service.ts | 65 ++-- tests/main/package.json | 1 - .../identifiers/configuration-test.ts | 1 + .../records/relationship-changes-test.js | 68 ++-- .../integration/records/rematerialize-test.js | 6 +- .../tests/integration/records/unload-test.js | 1 + .../integration/references/has-many-test.js | 1 + .../relationships/belongs-to-test.js | 35 +- .../relationships/has-many-test.js | 1 + .../relationships/one-to-many-test.js | 1 + .../relationships/one-to-one-test.js | 1 + .../serializers/json-api-serializer-test.js | 299 +++++++-------- .../serializers/json-serializer-test.js | 74 ++-- tests/main/tests/integration/store-test.js | 1 + .../integration/store/adapter-for-test.js | 5 +- .../integration/store/serializer-for-test.js | 5 +- .../rest-adapter/ajax-options-test.js | 36 +- .../tests/unit/model/init-properties-test.js | 14 +- tests/main/tests/unit/model/merge-test.js | 273 ++++++-------- .../model/relationships/belongs-to-test.js | 344 ++++++++---------- .../unit/model/rollback-attributes-test.js | 193 +++++----- .../tests/unit/store/adapter-interop-test.js | 69 ++-- tests/main/tests/unit/store/asserts-test.js | 6 +- tests/main/tests/unit/store/push-test.js | 72 ++-- tests/main/tests/unit/store/unload-test.js | 130 +++---- .../polymorphic-relationship-payloads-test.js | 170 ++++----- .../unit/utils/determine-body-promise-test.js | 3 +- tests/performance/app/adapters/application.js | 4 +- tests/performance/app/routes/destroy.js | 6 +- tests/performance/app/routes/unload-all.js | 5 +- tests/performance/app/routes/unload.js | 5 +- .../recommended-json-api/tests/test-helper.js | 17 - tests/request/tests/test-helper.js | 17 - .../tests/integration/create-record-test.js | 5 +- .../tests/integration/delete-record-test.js | 7 +- .../tests/integration/errors-test.js | 5 +- .../tests/integration/relationships-test.js | 7 +- .../tests/integration/requests-test.js | 9 +- .../tests/integration/update-record-test.js | 5 +- 50 files changed, 877 insertions(+), 1130 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5e0510e965e..7f0a9776e70 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -50,9 +50,8 @@ module.exports = { 'no-restricted-imports': [ 'error', { - paths: ['@glimmer/env', '@ember/utils'], + paths: ['@glimmer/env', '@ember/utils', '@ember/runloop'], }, - // '@ember/runloop', // '@ember/string', // '@ember/object', // '@ember/service', @@ -97,10 +96,10 @@ module.exports = { 'no-restricted-imports': [ 'error', { - paths: ['@glimmer/env', '@ember/utils'], + paths: ['@glimmer/env', '@ember/utils', '@ember/runloop'], // patterns: ['@ember/*'], }, - // '@ember/runloop',@glimmer/env + // '@ember/string', // '@ember/object', // '@ember/service', @@ -207,8 +206,6 @@ module.exports = { '@types/ember/index.d.ts', '@types/@glimmer/tracking.d.ts', '@types/@ember/utils/index.d.ts', - '@types/@ember/runloop/index.d.ts', - '@types/@ember/runloop/-private/backburner.d.ts', '@types/@ember/object/compat.d.ts', '@types/@ember/debug/index.d.ts', 'ember-data-types/q/schema-definition-service.ts', @@ -222,7 +219,6 @@ module.exports = { 'ember-data-types/q/identifier.ts', 'ember-data-types/q/fetch-manager.ts', 'ember-data-types/q/ember-data-json-api.ts', - '@types/@ember/runloop/index.d.ts', '@types/@ember/polyfills/index.d.ts', 'tests/graph/tests/integration/graph/polymorphism/implicit-keys-test.ts', 'tests/graph/tests/integration/graph/graph-test.ts', diff --git a/package.json b/package.json index 9d51a6025c1..681b1694ff5 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "@ember/string": "3.1.1", "@ember/test-helpers": "^3.2.0", "@glimmer/component": "^1.1.2", - "@glimmer/env": "^0.1.7", "@types/jquery": "^3.5.18", "@types/qunit": "^2.19.6", "@types/rsvp": "^4.0.4", diff --git a/packages/-ember-data/package.json b/packages/-ember-data/package.json index 75c2eda959b..68961e40be5 100644 --- a/packages/-ember-data/package.json +++ b/packages/-ember-data/package.json @@ -34,7 +34,6 @@ "@ember-data/tracking": "workspace:5.4.0-alpha.12", "@ember/edition-utils": "^1.2.0", "@embroider/macros": "^1.13.1", - "@glimmer/env": "^0.1.7", "broccoli-merge-trees": "^4.2.0", "ember-auto-import": "^2.6.3", "ember-cli-babel": "^8.0.0", diff --git a/packages/adapter/rollup.config.mjs b/packages/adapter/rollup.config.mjs index 450d7d02152..9a5724fbac7 100644 --- a/packages/adapter/rollup.config.mjs +++ b/packages/adapter/rollup.config.mjs @@ -23,8 +23,6 @@ export default { '@ember/object', '@ember/object/mixin', '@ember/application', - '@glimmer/env', - '@ember/runloop', '@ember/polyfills', ], diff --git a/packages/adapter/src/rest.ts b/packages/adapter/src/rest.ts index 6d9ae1e8242..0d57497360e 100644 --- a/packages/adapter/src/rest.ts +++ b/packages/adapter/src/rest.ts @@ -4,7 +4,6 @@ import { getOwner } from '@ember/application'; import { assert, warn } from '@ember/debug'; import { computed } from '@ember/object'; -import { join } from '@ember/runloop'; import { DEBUG } from '@ember-data/env'; import type { Snapshot, SnapshotRecordArray } from '@ember-data/legacy-compat/-private'; @@ -1542,12 +1541,12 @@ function execjQAjax( return new Promise((resolve, reject) => { hash.success = function (payload, textStatus, jqXHR) { let response = ajaxSuccessHandler(adapter, payload, jqXHR, requestData); - join(null, resolve, response); + resolve(response); }; hash.error = function (jqXHR, textStatus, errorThrown) { let error = ajaxErrorHandler(adapter, jqXHR, errorThrown, requestData); - join(null, reject, error); + reject(error); }; adapter._ajax(hash); diff --git a/packages/graph/rollup.config.mjs b/packages/graph/rollup.config.mjs index a5afe47ec93..afb2c762bbc 100644 --- a/packages/graph/rollup.config.mjs +++ b/packages/graph/rollup.config.mjs @@ -22,7 +22,6 @@ export default { '@ember/object', '@ember/object/mixin', '@ember/application', - '@glimmer/env', '@ember/polyfills', ], diff --git a/packages/json-api/rollup.config.mjs b/packages/json-api/rollup.config.mjs index f54ba5dceb4..fd1c5a7c0cd 100644 --- a/packages/json-api/rollup.config.mjs +++ b/packages/json-api/rollup.config.mjs @@ -22,11 +22,9 @@ export default { '@ember/object', '@ember/object/mixin', '@ember/polyfills', - '@ember/runloop', '@ember/service', '@ember/string', '@embroider/macros', - '@glimmer/env', 'ember-inflector', ], diff --git a/packages/json-api/src/-private/cache.ts b/packages/json-api/src/-private/cache.ts index e1cde7cefd9..140b3bc3d96 100644 --- a/packages/json-api/src/-private/cache.ts +++ b/packages/json-api/src/-private/cache.ts @@ -2,7 +2,6 @@ * @module @ember-data/json-api */ import { assert } from '@ember/debug'; -import { schedule } from '@ember/runloop'; import { LOG_MUTATIONS, LOG_OPERATIONS, LOG_REQUESTS } from '@ember-data/debugging'; import { DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE } from '@ember-data/deprecations'; @@ -996,11 +995,10 @@ export default class JSONAPICache implements Cache { * of a test won't cause issues. */ if (this.__destroyedCache.size === 1) { - schedule('destroy', () => { - setTimeout(() => { - this.__destroyedCache.clear(); - }, 100); - }); + // TODO do we still need this? + setTimeout(() => { + this.__destroyedCache.clear(); + }, 100); } if (!removed && removeFromRecordArray) { diff --git a/packages/model/rollup.config.mjs b/packages/model/rollup.config.mjs index b3720f86be3..037afd3fa6c 100644 --- a/packages/model/rollup.config.mjs +++ b/packages/model/rollup.config.mjs @@ -32,9 +32,7 @@ export default { '@ember/object', '@ember/object/mixin', '@ember/application', - '@glimmer/env', '@glimmer/tracking', - '@ember/runloop', '@ember/polyfills', ], diff --git a/packages/model/src/-private/model.js b/packages/model/src/-private/model.js index 14c571e571f..faba35091f7 100644 --- a/packages/model/src/-private/model.js +++ b/packages/model/src/-private/model.js @@ -5,7 +5,6 @@ import { assert, warn } from '@ember/debug'; import EmberObject from '@ember/object'; import { dependentKeyCompat } from '@ember/object/compat'; -import { run } from '@ember/runloop'; import { tracked } from '@glimmer/tracking'; import Ember from 'ember'; @@ -734,9 +733,7 @@ class Model extends EmberObject { return Promise.resolve(this); } return this.save(options).then((_) => { - run(() => { - this.unloadRecord(); - }); + this.unloadRecord(); return this; }); } diff --git a/packages/store/src/-private/managers/notification-manager.ts b/packages/store/src/-private/managers/notification-manager.ts index dec65e384a3..c38637080f6 100644 --- a/packages/store/src/-private/managers/notification-manager.ts +++ b/packages/store/src/-private/managers/notification-manager.ts @@ -2,6 +2,7 @@ * @module @ember-data/store */ import { assert } from '@ember/debug'; +// eslint-disable-next-line no-restricted-imports import { _backburner } from '@ember/runloop'; import { LOG_NOTIFICATIONS } from '@ember-data/debugging'; diff --git a/packages/store/src/-private/store-service.ts b/packages/store/src/-private/store-service.ts index 1398dabcf8b..fa97846362a 100644 --- a/packages/store/src/-private/store-service.ts +++ b/packages/store/src/-private/store-service.ts @@ -5,7 +5,6 @@ import { getOwner } from '@ember/application'; import { assert } from '@ember/debug'; import EmberObject from '@ember/object'; -import { _backburner as emberBackburner } from '@ember/runloop'; import type { Object as JSONObject } from 'json-typescript'; @@ -664,47 +663,45 @@ class Store extends EmberObject { // // to remove this, we would need to move to a new `async` API. let record!: RecordInstance; - emberBackburner.join(() => { - this._join(() => { - let normalizedModelName = normalizeModelName(modelName); - let properties = { ...inputProperties }; + this._join(() => { + let normalizedModelName = normalizeModelName(modelName); + let properties = { ...inputProperties }; - // If the passed properties do not include a primary key, - // give the adapter an opportunity to generate one. Typically, - // client-side ID generators will use something like uuid.js - // to avoid conflicts. + // If the passed properties do not include a primary key, + // give the adapter an opportunity to generate one. Typically, + // client-side ID generators will use something like uuid.js + // to avoid conflicts. - if (properties.id === null || properties.id === undefined) { - let adapter = this.adapterFor(modelName, true); + if (properties.id === null || properties.id === undefined) { + let adapter = this.adapterFor(modelName, true); - if (adapter && adapter.generateIdForRecord) { - properties.id = adapter.generateIdForRecord(this, modelName, properties); - } else { - properties.id = null; - } + if (adapter && adapter.generateIdForRecord) { + properties.id = adapter.generateIdForRecord(this, modelName, properties); + } else { + properties.id = null; } + } - // Coerce ID to a string - properties.id = coerceId(properties.id); - const resource = { type: normalizedModelName, id: properties.id }; + // Coerce ID to a string + properties.id = coerceId(properties.id); + const resource = { type: normalizedModelName, id: properties.id }; - if (resource.id) { - const identifier = this.identifierCache.peekRecordIdentifier(resource as ResourceIdentifierObject); + if (resource.id) { + const identifier = this.identifierCache.peekRecordIdentifier(resource as ResourceIdentifierObject); - assert( - `The id ${String(properties.id)} has already been used with another '${normalizedModelName}' record.`, - !identifier - ); - } + assert( + `The id ${String(properties.id)} has already been used with another '${normalizedModelName}' record.`, + !identifier + ); + } - const identifier = this.identifierCache.createIdentifierForNewRecord(resource); - const cache = this.cache; + const identifier = this.identifierCache.createIdentifierForNewRecord(resource); + const cache = this.cache; - const createOptions = normalizeProperties(this, identifier, properties); - const resultProps = cache.clientDidCreate(identifier, createOptions); + const createOptions = normalizeProperties(this, identifier, properties); + const resultProps = cache.clientDidCreate(identifier, createOptions); - record = this._instanceCache.getRecord(identifier, resultProps); - }); + record = this._instanceCache.getRecord(identifier, resultProps); }); return record; } @@ -738,9 +735,7 @@ class Store extends EmberObject { cache.setIsDeleted(identifier, true); if (cache.isNew(identifier)) { - emberBackburner.join(() => { - this._instanceCache.unloadRecord(identifier); - }); + this._instanceCache.unloadRecord(identifier); } }); } diff --git a/tests/main/package.json b/tests/main/package.json index fa94b9165c3..f8ff31c122c 100644 --- a/tests/main/package.json +++ b/tests/main/package.json @@ -69,7 +69,6 @@ "@ember/test-helpers": "^3.2.0", "@embroider/macros": "^1.13.1", "@glimmer/component": "^1.1.2", - "@glimmer/env": "^0.1.7", "@glimmer/tracking": "^1.1.2", "@types/ember": "^4.0.4", "@types/ember__debug": "^4.0.4", diff --git a/tests/main/tests/integration/identifiers/configuration-test.ts b/tests/main/tests/integration/identifiers/configuration-test.ts index 0bcb60a611b..db508366f8c 100644 --- a/tests/main/tests/integration/identifiers/configuration-test.ts +++ b/tests/main/tests/integration/identifiers/configuration-test.ts @@ -1,4 +1,5 @@ import EmberObject, { set } from '@ember/object'; +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; diff --git a/tests/main/tests/integration/records/relationship-changes-test.js b/tests/main/tests/integration/records/relationship-changes-test.js index 4654a464a54..425d459b304 100644 --- a/tests/main/tests/integration/records/relationship-changes-test.js +++ b/tests/main/tests/integration/records/relationship-changes-test.js @@ -1,4 +1,3 @@ -import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; @@ -211,62 +210,53 @@ module('integration/records/relationship-changes - Relationship changes', functi assert.ok(observerCount >= 1, 'siblings observer should be triggered at least once'); }); - test('Calling push with relationship does not trigger observers if the relationship was not changed', function (assert) { + test('Calling push with relationship does not trigger observers if the relationship was not changed', async function (assert) { assert.expect(1); let store = this.owner.lookup('service:store'); - let person = null; let observerCount = 0; - run(() => { - store.push({ - data: { - type: 'person', - id: 'wat', - attributes: { - firstName: 'Yehuda', - lastName: 'Katz', - }, - relationships: { - siblings: { - data: [sibling1Ref], - }, + const person = store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', + }, + relationships: { + siblings: { + data: [sibling1Ref], }, }, - included: [sibling1], - }); - person = store.peekRecord('person', 'wat'); + }, + included: [sibling1], }); const observerMethod = function () { observerCount++; }; - run(() => { - // prime the pump - person.siblings; - person.addObserver('siblings.[]', observerMethod); - }); + // prime the pump + person.siblings; + person.addObserver('siblings.[]', observerMethod); - run(() => { - store.push({ - data: { - type: 'person', - id: 'wat', - attributes: {}, - relationships: { - siblings: { - data: [sibling1Ref], - }, + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: {}, + relationships: { + siblings: { + data: [sibling1Ref], }, }, - included: [], - }); + }, + included: [], }); - run(() => { - assert.strictEqual(observerCount, 0, 'siblings observer should not be triggered'); - }); + await settled(); + assert.strictEqual(observerCount, 0, 'siblings observer should not be triggered'); person.removeObserver('siblings.[]', observerMethod); }); diff --git a/tests/main/tests/integration/records/rematerialize-test.js b/tests/main/tests/integration/records/rematerialize-test.js index 40ebc9ef3f5..c47869e9e1e 100644 --- a/tests/main/tests/integration/records/rematerialize-test.js +++ b/tests/main/tests/integration/records/rematerialize-test.js @@ -1,7 +1,3 @@ -/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|bob|dudu)" }]*/ - -import { run } from '@ember/runloop'; - import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; @@ -79,7 +75,7 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) 'The person identifier is loaded' ); - run(() => adam.unloadRecord()); + adam.unloadRecord(); assert.strictEqual(store.peekRecord('person', '1'), null, 'The person is unloaded'); assert.false( diff --git a/tests/main/tests/integration/records/unload-test.js b/tests/main/tests/integration/records/unload-test.js index d05e3dec098..cb9c721546f 100644 --- a/tests/main/tests/integration/records/unload-test.js +++ b/tests/main/tests/integration/records/unload-test.js @@ -1,6 +1,7 @@ /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|bob|dudu)" }]*/ import { get } from '@ember/object'; +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; diff --git a/tests/main/tests/integration/references/has-many-test.js b/tests/main/tests/integration/references/has-many-test.js index 6e3dc707103..85424313f3b 100755 --- a/tests/main/tests/integration/references/has-many-test.js +++ b/tests/main/tests/integration/references/has-many-test.js @@ -1,4 +1,5 @@ import { get } from '@ember/object'; +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { module, test } from 'qunit'; diff --git a/tests/main/tests/integration/relationships/belongs-to-test.js b/tests/main/tests/integration/relationships/belongs-to-test.js index f58201013aa..bbd8cc052ea 100644 --- a/tests/main/tests/integration/relationships/belongs-to-test.js +++ b/tests/main/tests/integration/relationships/belongs-to-test.js @@ -1,4 +1,5 @@ import EmberObject from '@ember/object'; +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { module, test } from 'qunit'; @@ -469,8 +470,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function ); }); - test('The store can materialize a non loaded monomorphic belongsTo association', function (assert) { - assert.expect(1); + test('The store can materialize a non loaded monomorphic belongsTo association', async function (assert) { + assert.expect(2); class Post extends Model { @attr('string') title; @@ -493,28 +494,24 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); }; - run(() => { - store.push({ - data: { - id: '1', - type: 'post', - relationships: { - user: { - data: { - id: '2', - type: 'user', - }, + store.push({ + data: { + id: '1', + type: 'post', + relationships: { + user: { + data: { + id: '2', + type: 'user', }, }, }, - }); + }, }); - return run(() => { - return store.findRecord('post', 1).then((post) => { - post.user; - }); - }); + const post = await store.findRecord('post', '1'); + const user = await post.user; + assert.strictEqual(user.id, '2', 'The post should have a user now'); }); testInDebug('Invalid belongsTo relationship identifiers throw errors for null id', function (assert) { diff --git a/tests/main/tests/integration/relationships/has-many-test.js b/tests/main/tests/integration/relationships/has-many-test.js index 638c18b0114..89dbafad28a 100644 --- a/tests/main/tests/integration/relationships/has-many-test.js +++ b/tests/main/tests/integration/relationships/has-many-test.js @@ -1,4 +1,5 @@ import { get } from '@ember/object'; +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { module, test } from 'qunit'; diff --git a/tests/main/tests/integration/relationships/one-to-many-test.js b/tests/main/tests/integration/relationships/one-to-many-test.js index 66ab051437e..6e20816f105 100644 --- a/tests/main/tests/integration/relationships/one-to-many-test.js +++ b/tests/main/tests/integration/relationships/one-to-many-test.js @@ -1,4 +1,5 @@ import { get } from '@ember/object'; +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { module, test } from 'qunit'; diff --git a/tests/main/tests/integration/relationships/one-to-one-test.js b/tests/main/tests/integration/relationships/one-to-one-test.js index 41fc53b8655..d2deb870d77 100644 --- a/tests/main/tests/integration/relationships/one-to-one-test.js +++ b/tests/main/tests/integration/relationships/one-to-one-test.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; diff --git a/tests/main/tests/integration/serializers/json-api-serializer-test.js b/tests/main/tests/integration/serializers/json-api-serializer-test.js index ed8d94af1d6..4032dbf221f 100644 --- a/tests/main/tests/integration/serializers/json-api-serializer-test.js +++ b/tests/main/tests/integration/serializers/json-api-serializer-test.js @@ -1,6 +1,3 @@ -import { get } from '@ember/object'; -import { run } from '@ember/runloop'; - import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; @@ -134,9 +131,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }; assert.expectWarning(function () { - run(function () { - store.serializerFor('user').normalizeResponse(store, User, documentHash, '1', 'findRecord'); - }); + store.serializerFor('user').normalizeResponse(store, User, documentHash, '1', 'findRecord'); }, /Encountered a resource object with type "UnknownType", but no model was found for model name "unknown-type"/); }); @@ -170,9 +165,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }; assert.expectWarning(function () { - run(function () { - store.serializerFor('user').normalizeResponse(store, User, documentHash, '1', 'findRecord'); - }); + store.serializerFor('user').normalizeResponse(store, User, documentHash, '1', 'findRecord'); }, /Encountered a resource object with type "unknown-types", but no model was found for model name "unknown-type"/); }); @@ -200,13 +193,11 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }; assert.expectWarning(function () { - run(function () { - store.pushPayload(documentHash); - }); + store.pushPayload(documentHash); }, /Encountered a resource object with type "unknown-types", but no model was found for model name "unknown-type"/); - var user = store.peekRecord('user', 1); - assert.strictEqual(get(user, 'firstName'), 'Yehuda', 'firstName is correct'); + const user = store.peekRecord('user', 1); + assert.strictEqual(user.firstName, 'Yehuda', 'firstName is correct'); }); testInDebug('Errors when pushing payload with unknown type included in relationship', function (assert) { @@ -247,9 +238,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }; assert.expectAssertion(function () { - run(function () { - store.serializerFor('user').normalizeResponse(store, User, documentHash, '1', 'findRecord'); - }); + store.serializerFor('user').normalizeResponse(store, User, documentHash, '1', 'findRecord'); }, /Encountered a resource object with an undefined type/); }); @@ -315,22 +304,20 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi let store = this.owner.lookup('service:store'); var company, user; - run(function () { - store.push({ - data: { - type: 'company', - id: '1', - attributes: { - name: 'Tilde Inc.', - }, + store.push({ + data: { + type: 'company', + id: '1', + attributes: { + name: 'Tilde Inc.', }, - }); - company = store.peekRecord('company', 1); - user = store.createRecord('user', { - firstName: 'Yehuda', - title: 'director', - company: company, - }); + }, + }); + company = store.peekRecord('company', 1); + user = store.createRecord('user', { + firstName: 'Yehuda', + title: 'director', + company: company, }); var payload = store.serializerFor('user').serialize(user._createSnapshot()); @@ -429,23 +416,21 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi let store = this.owner.lookup('service:store'); let serializer = store.serializerFor('application'); - run(function () { - serializer.pushPayload(store, { - data: { - type: 'handles', - id: '1', - }, - }); + serializer.pushPayload(store, { + data: { + type: 'handles', + id: '1', + }, + }); - let handle = store.peekRecord('handle', 1); + let handle = store.peekRecord('handle', 1); - let serialized = handle.serialize({ includeId: true }); - assert.deepEqual(serialized, { - data: { - type: 'handles', - id: '1', - }, - }); + let serialized = handle.serialize({ includeId: true }); + assert.deepEqual(serialized, { + data: { + type: 'handles', + id: '1', + }, }); }); @@ -481,25 +466,23 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi let store = this.owner.lookup('service:store'); let serializer = store.serializerFor('application'); - run(function () { - serializer.pushPayload(store, { - data: { - type: 'handles', - id: '1', - }, - }); + serializer.pushPayload(store, { + data: { + type: 'handles', + id: '1', + }, + }); - let handle = store.peekRecord('handle', 1); - let user = store.createRecord('user'); - handle.set('user', user); + let handle = store.peekRecord('handle', 1); + let user = store.createRecord('user'); + handle.set('user', user); - let serialized = handle.serialize({ includeId: true }); - assert.deepEqual(serialized, { - data: { - type: 'handles', - id: '1', - }, - }); + let serialized = handle.serialize({ includeId: true }); + assert.deepEqual(serialized, { + data: { + type: 'handles', + id: '1', + }, }); }); @@ -515,49 +498,47 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi let store = this.owner.lookup('service:store'); - run(function () { - store.serializerFor('user').pushPayload(store, { - data: { - type: 'users', - id: '1', - relationships: { - handles: { - data: [ - { type: 'handles', id: '1' }, - { type: 'handles', id: '2' }, - ], - }, + store.serializerFor('user').pushPayload(store, { + data: { + type: 'users', + id: '1', + relationships: { + handles: { + data: [ + { type: 'handles', id: '1' }, + { type: 'handles', id: '2' }, + ], }, }, - included: [ - { type: 'handles', id: '1' }, - { type: 'handles', id: '2' }, - ], - }); + }, + included: [ + { type: 'handles', id: '1' }, + { type: 'handles', id: '2' }, + ], + }); - let user = store.peekRecord('user', 1); + let user = store.peekRecord('user', 1); - let serialized = user.serialize({ includeId: true }); + let serialized = user.serialize({ includeId: true }); - assert.deepEqual(serialized, { - data: { - type: 'users', - id: '1', - attributes: { - 'first-name': null, - 'last-name': null, - title: null, - }, - relationships: { - handles: { - data: [ - { type: 'handles', id: '1' }, - { type: 'handles', id: '2' }, - ], - }, + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [ + { type: 'handles', id: '1' }, + { type: 'handles', id: '2' }, + ], }, }, - }); + }, }); }); @@ -573,50 +554,48 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi let store = this.owner.lookup('service:store'); - run(function () { - store.serializerFor('user').pushPayload(store, { - data: { - type: 'users', - id: '1', - relationships: { - handles: { - data: [ - { type: 'handles', id: '1' }, - { type: 'handles', id: '2' }, - ], - }, + store.serializerFor('user').pushPayload(store, { + data: { + type: 'users', + id: '1', + relationships: { + handles: { + data: [ + { type: 'handles', id: '1' }, + { type: 'handles', id: '2' }, + ], }, }, - included: [ - { type: 'handles', id: '1' }, - { type: 'handles', id: '2' }, - ], - }); + }, + included: [ + { type: 'handles', id: '1' }, + { type: 'handles', id: '2' }, + ], + }); - let user = store.peekRecord('user', 1); - store.createRecord('handle', { user }); + let user = store.peekRecord('user', 1); + store.createRecord('handle', { user }); - let serialized = user.serialize({ includeId: true }); + let serialized = user.serialize({ includeId: true }); - assert.deepEqual(serialized, { - data: { - type: 'users', - id: '1', - attributes: { - 'first-name': null, - 'last-name': null, - title: null, - }, - relationships: { - handles: { - data: [ - { type: 'handles', id: '1' }, - { type: 'handles', id: '2' }, - ], - }, + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [ + { type: 'handles', id: '1' }, + { type: 'handles', id: '2' }, + ], }, }, - }); + }, }); }); @@ -632,35 +611,33 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi let store = this.owner.lookup('service:store'); - run(function () { - store.serializerFor('user').pushPayload(store, { - data: { - type: 'users', - id: '1', - }, - }); + store.serializerFor('user').pushPayload(store, { + data: { + type: 'users', + id: '1', + }, + }); - let user = store.peekRecord('user', 1); - store.createRecord('handle', { user }); + let user = store.peekRecord('user', 1); + store.createRecord('handle', { user }); - let serialized = user.serialize({ includeId: true }); + let serialized = user.serialize({ includeId: true }); - assert.deepEqual(serialized, { - data: { - type: 'users', - id: '1', - attributes: { - 'first-name': null, - 'last-name': null, - title: null, - }, - relationships: { - handles: { - data: [], - }, + assert.deepEqual(serialized, { + data: { + type: 'users', + id: '1', + attributes: { + 'first-name': null, + 'last-name': null, + title: null, + }, + relationships: { + handles: { + data: [], }, }, - }); + }, }); }); diff --git a/tests/main/tests/integration/serializers/json-serializer-test.js b/tests/main/tests/integration/serializers/json-serializer-test.js index a21ab5266bf..8fcfca270f8 100644 --- a/tests/main/tests/integration/serializers/json-serializer-test.js +++ b/tests/main/tests/integration/serializers/json-serializer-test.js @@ -1,7 +1,3 @@ -/* eslint no-prototype-builtins: 'off' */ -// prototype hasOwnProperty has no security issues here because it is not production code - -import { run } from '@ember/runloop'; import { underscore } from '@ember/string'; import { module, test } from 'qunit'; @@ -14,6 +10,10 @@ import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest'; import Transform from '@ember-data/serializer/transform'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +function hasOwn(obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key); +} + module('integration/serializer/json - JSONSerializer', function (hooks) { setupTest(hooks); @@ -91,9 +91,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { let post = store.createRecord('post', { title: 'Rails is omakase', comments: [] }); - run(() => { - post.set('id', 'test'); - }); + post.set('id', 'test'); let json = serializer.serialize(post._createSnapshot(), { includeId: true }); @@ -306,9 +304,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { id: '1', }); - run(function () { - post.comments.push(comment); - }); + post.comments.push(comment); let json = {}; @@ -334,22 +330,20 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { let store = this.owner.lookup('service:store'); - let post = run(() => - store.push({ - data: { - id: '1', - type: 'post', - attributes: { - title: 'Rails is omakase', - }, + let post = store.push({ + data: { + id: '1', + type: 'post', + attributes: { + title: 'Rails is omakase', }, - }) - ); + }, + }); let json = {}; store.serializerFor('post').serializeHasMany(post._createSnapshot(), json, { key: 'comments', options: {} }); - assert.notOk(json.hasOwnProperty('comments'), 'Does not add the relationship key to json'); + assert.notOk(hasOwn(json, 'comments'), 'Does not add the relationship key to json'); }); test('shouldSerializeHasMany', function (assert) { @@ -504,9 +498,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { let store = this.owner.lookup('service:store'); - run(function () { - store.serializerFor('post').normalizeResponse(store, store.modelFor('post'), posts, null, 'findAll'); - }); + store.serializerFor('post').normalizeResponse(store, store.modelFor('post'), posts, null, 'findAll'); assert.strictEqual(postNormalizeCount, 2, 'two posts are normalized'); }); @@ -609,17 +601,15 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { let store = this.owner.lookup('service:store'); - let parentPost = run(() => - store.push({ - data: { - type: 'post', - id: '2', - attributes: { - title: 'Rails is omakase', - }, + let parentPost = store.push({ + data: { + type: 'post', + id: '2', + attributes: { + title: 'Rails is omakase', }, - }) - ); + }, + }); let post = store.createRecord('post', { title: 'Rails is omakase', parentPost: parentPost, @@ -755,8 +745,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { let post = store.createRecord('post', { title: 'Rails is omakase' }); let payload = store.serializerFor('post').serialize(post._createSnapshot()); - assert.notOk(payload.hasOwnProperty('title'), 'Does not add the key to instance'); - assert.notOk(payload.hasOwnProperty('[object Object]'), 'Does not add some random key like [object Object]'); + assert.notOk(hasOwn(payload, 'title'), 'Does not add the key to instance'); + assert.notOk(hasOwn(payload, '[object Object]'), 'Does not add some random key like [object Object]'); }); test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` property', function (assert) { @@ -790,7 +780,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { var serializedProperty = serializer.keyForRelationship('comments', 'hasMany'); var payload = serializer.serialize(post._createSnapshot()); - assert.notOk(payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); + assert.notOk(hasOwn(payload, serializedProperty), 'Does not add the key to instance'); }); test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` property', function (assert) { @@ -824,7 +814,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); var payload = serializer.serialize(comment._createSnapshot()); - assert.notOk(payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); + assert.notOk(hasOwn(payload, serializedProperty), 'Does not add the key to instance'); }); test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` property', function (assert) { @@ -858,7 +848,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { var serializedProperty = serializer.keyForRelationship('comments', 'hasMany'); var payload = serializer.serialize(post._createSnapshot()); - assert.notOk(payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); + assert.notOk(hasOwn(payload, serializedProperty), 'Does not add the key to instance'); }); test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` property', function (assert) { @@ -892,7 +882,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); var payload = serializer.serialize(comment._createSnapshot()); - assert.notOk(payload.hasOwnProperty(serializedProperty), 'Does not add the key to instance'); + assert.notOk(hasOwn(payload, serializedProperty), 'Does not add the key to instance'); }); test('Serializer respects `serialize: true` on the attrs hash for a `hasMany` property', async function (assert) { @@ -929,7 +919,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { const serializedProperty = serializer.keyForRelationship('comments', 'hasMany'); const payload = serializer.serialize(post._createSnapshot()); - assert.ok(payload.hasOwnProperty(serializedProperty), 'Add the key to instance'); + assert.ok(hasOwn(payload, serializedProperty), 'Add the key to instance'); }); test('Serializer respects `serialize: true` on the attrs hash for a `belongsTo` property', function (assert) { @@ -963,7 +953,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); var payload = serializer.serialize(comment._createSnapshot()); - assert.ok(payload.hasOwnProperty(serializedProperty), 'Add the key to instance'); + assert.ok(hasOwn(payload, serializedProperty), 'Add the key to instance'); }); test('Serializer should merge attrs from superclasses', function (assert) { diff --git a/tests/main/tests/integration/store-test.js b/tests/main/tests/integration/store-test.js index f290b3bbd59..9185e92db8b 100644 --- a/tests/main/tests/integration/store-test.js +++ b/tests/main/tests/integration/store-test.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; diff --git a/tests/main/tests/integration/store/adapter-for-test.js b/tests/main/tests/integration/store/adapter-for-test.js index 89faca1592b..e7d72add8fc 100644 --- a/tests/main/tests/integration/store/adapter-for-test.js +++ b/tests/main/tests/integration/store/adapter-for-test.js @@ -1,4 +1,4 @@ -import { run } from '@ember/runloop'; +import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; @@ -181,7 +181,8 @@ module('integration/store - adapterFor', function (hooks) { assert.ok(adapter instanceof AppAdapter, 'precond - We found the correct adapter'); assert.ok(didInstantiate, 'precond - We instantiated the adapter'); - run(store, 'destroy'); + store.destroy(); + await settled(); assert.ok(didDestroy, 'adapter was destroyed'); }); diff --git a/tests/main/tests/integration/store/serializer-for-test.js b/tests/main/tests/integration/store/serializer-for-test.js index 1cb6d0b9abc..be6300d401a 100644 --- a/tests/main/tests/integration/store/serializer-for-test.js +++ b/tests/main/tests/integration/store/serializer-for-test.js @@ -1,4 +1,4 @@ -import { run } from '@ember/runloop'; +import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; @@ -193,7 +193,8 @@ module('integration/store - serializerFor', function (hooks) { assert.ok(serializer instanceof AppSerializer, 'precond - We found the correct serializer'); assert.ok(didInstantiate, 'precond - We instantiated the serializer'); - run(store, 'destroy'); + store.destroy(); + await settled(); assert.ok(didDestroy, 'serializer was destroyed'); }); diff --git a/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js b/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js index c50fd42424a..627cb7bf1e3 100644 --- a/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js +++ b/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js @@ -1,7 +1,4 @@ -import { run } from '@ember/runloop'; - import { module, test } from 'qunit'; -import { Promise as EmberPromise, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -29,7 +26,7 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( this.owner.register('serializer:application', RESTSerializer.extend()); }); - test('When an id is searched, the correct url should be generated', function (assert) { + test('When an id is searched, the correct url should be generated', async function (assert) { assert.expect(2); let store = this.owner.lookup('service:store'); @@ -45,15 +42,14 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( assert.strictEqual(url, '/places/1', 'should create the correct url'); } count++; - return resolve(); + return Promise.resolve(); }; - return run(() => { - return EmberPromise.all([adapter.findRecord(store, Person, 1, {}), adapter.findRecord(store, Place, 1, {})]); - }); + await adapter.findRecord(store, Person, '1', {}); + await adapter.findRecord(store, Place, '1', {}); }); - test(`id's should be sanatized`, function (assert) { + test(`id's should be sanatized`, async function (assert) { assert.expect(1); let store = this.owner.lookup('service:store'); @@ -61,10 +57,10 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( adapter.ajax = function (url, method) { assert.strictEqual(url, '/people/..%2Fplace%2F1', 'should create the correct url'); - return resolve(); + return Promise.resolve(); }; - return run(() => adapter.findRecord(store, Person, '../place/1', {})); + await adapter.findRecord(store, Person, '../place/1', {}); }); test('ajaxOptions() headers are set', function (assert) { @@ -227,23 +223,21 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); }); - test('_fetchRequest() returns a promise', function (assert) { + test('_fetchRequest() returns a promise', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); let noop = function () {}; - return run(() => { - let fetchPlacePromise = adapter._fetchRequest({ - url: '/places/1', - success: noop, - error: noop, - }); + let fetchPlacePromise = adapter._fetchRequest({ + url: '/places/1', + success: noop, + error: noop, + }); - assert.strictEqual(typeof fetchPlacePromise.then, 'function', '_fetchRequest does not return a promise'); + assert.strictEqual(typeof fetchPlacePromise.then, 'function', '_fetchRequest does not return a promise'); - return fetchPlacePromise; - }); + await fetchPlacePromise; }); module('ajax-options - ajax', function (hooks) { diff --git a/tests/main/tests/unit/model/init-properties-test.js b/tests/main/tests/unit/model/init-properties-test.js index 02a1d7fcde0..1521b698623 100644 --- a/tests/main/tests/unit/model/init-properties-test.js +++ b/tests/main/tests/unit/model/init-properties-test.js @@ -1,9 +1,7 @@ import { get } from '@ember/object'; -import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -157,7 +155,7 @@ module('unit/model - init properties', function (hooks) { let { adapter, store } = setupModels(this.owner, testState); adapter.findRecord = () => { - return resolve({ + return Promise.resolve({ data: { type: 'post', id: '1', @@ -207,7 +205,7 @@ module('unit/model - init properties', function (hooks) { let { adapter, store } = setupModels(this.owner, testState); adapter.queryRecord = () => { - return resolve({ + return Promise.resolve({ data: { type: 'post', id: '1', @@ -264,11 +262,9 @@ module('unit/model - init properties', function (hooks) { let store = this.owner.lookup('service:store'); - run(() => { - store.createRecord('post', { - title: 'My Post', - randomProp: 'An unknown prop', - }); + store.createRecord('post', { + title: 'My Post', + randomProp: 'An unknown prop', }); }); }); diff --git a/tests/main/tests/unit/model/merge-test.js b/tests/main/tests/unit/model/merge-test.js index b671b26502a..a78bffc9337 100644 --- a/tests/main/tests/unit/model/merge-test.js +++ b/tests/main/tests/unit/model/merge-test.js @@ -1,7 +1,4 @@ -import { next, run } from '@ember/runloop'; - import { module, test } from 'qunit'; -import { Promise as EmberPromise, reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -25,7 +22,7 @@ module('unit/model/merge - Merging', function (hooks) { this.store = this.owner.lookup('service:store'); }); - test('When a record is in flight, changes can be made', function (assert) { + test('When a record is in flight, changes can be made', async function (assert) { assert.expect(3); const ApplicationAdapter = Adapter.extend({ @@ -37,161 +34,144 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); let person = this.store.createRecord('person', { name: 'Tom Dale' }); + let save = person.save(); - // Make sure saving isn't resolved synchronously - return run(() => { - let save = person.save(); - - assert.strictEqual(person.name, 'Tom Dale'); + assert.strictEqual(person.name, 'Tom Dale'); - person.set('name', 'Thomas Dale'); + person.set('name', 'Thomas Dale'); - return save.then((person) => { - assert.true(person.hasDirtyAttributes, 'The person is still dirty'); - assert.strictEqual(person.name, 'Thomas Dale', 'The changes made still apply'); - }); + await save.then((person) => { + assert.true(person.hasDirtyAttributes, 'The person is still dirty'); + assert.strictEqual(person.name, 'Thomas Dale', 'The changes made still apply'); }); }); - test('Make sure snapshot is created at save time not at flush time', function (assert) { + test('Make sure snapshot is created at save time not at flush time', async function (assert) { assert.expect(5); const ApplicationAdapter = Adapter.extend({ updateRecord(store, type, snapshot) { assert.strictEqual(snapshot.attr('name'), 'Thomas Dale'); - return resolve(); + return Promise.resolve(); }, }); this.owner.register('adapter:application', ApplicationAdapter); - let person; - run(() => { - person = this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom', - }, + let person = this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', }, - }); - person.set('name', 'Thomas Dale'); + }, }); + person.set('name', 'Thomas Dale'); - return run(() => { - let promise = person.save(); + let promise = person.save(); - assert.strictEqual(person.name, 'Thomas Dale'); + assert.strictEqual(person.name, 'Thomas Dale'); - person.set('name', 'Tomasz Dale'); + person.set('name', 'Tomasz Dale'); - assert.strictEqual(person.name, 'Tomasz Dale', 'the local changes applied on top'); + assert.strictEqual(person.name, 'Tomasz Dale', 'the local changes applied on top'); - return promise.then((person) => { - assert.true(person.hasDirtyAttributes, 'The person is still dirty'); - assert.strictEqual(person.name, 'Tomasz Dale', 'The local changes apply'); - }); + await promise.then((person) => { + assert.true(person.hasDirtyAttributes, 'The person is still dirty'); + assert.strictEqual(person.name, 'Tomasz Dale', 'The local changes apply'); }); }); - test('When a record is in flight, pushes are applied underneath the in flight changes', function (assert) { + test('When a record is in flight, pushes are applied underneath the in flight changes', async function (assert) { assert.expect(6); const ApplicationAdapter = Adapter.extend({ updateRecord(store, type, snapshot) { // Make sure saving isn't resolved synchronously - return new EmberPromise((resolve) => { - next(null, resolve, { - data: { - id: '1', - type: 'person', - attributes: { name: 'Senor Thomas Dale, Esq.', city: 'Portland' }, - }, - }); + return new Promise((resolve) => { + setTimeout(() => { + resolve({ + data: { + id: '1', + type: 'person', + attributes: { name: 'Senor Thomas Dale, Esq.', city: 'Portland' }, + }, + }); + }, 0); }); }, }); this.owner.register('adapter:application', ApplicationAdapter); - let person; - - run(() => { - person = this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom', - }, + let person = this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom', }, - }); - person.set('name', 'Thomas Dale'); + }, }); + person.set('name', 'Thomas Dale'); - return run(() => { - var promise = person.save(); + const promise = person.save(); - assert.strictEqual(person.name, 'Thomas Dale'); + assert.strictEqual(person.name, 'Thomas Dale'); - person.set('name', 'Tomasz Dale'); + person.set('name', 'Tomasz Dale'); - this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tommy Dale', - city: 'PDX', - }, + this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tommy Dale', + city: 'PDX', }, - }); + }, + }); - assert.strictEqual(person.name, 'Tomasz Dale', 'the local changes applied on top'); - assert.strictEqual(person.city, 'PDX', 'the pushed change is available'); + assert.strictEqual(person.name, 'Tomasz Dale', 'the local changes applied on top'); + assert.strictEqual(person.city, 'PDX', 'the pushed change is available'); - return promise.then((person) => { - assert.true(person.hasDirtyAttributes, 'The person is still dirty'); - assert.strictEqual(person.name, 'Tomasz Dale', 'The local changes apply'); - assert.strictEqual(person.city, 'Portland', 'The updates from the server apply on top of the previous pushes'); - }); + await promise.then((person) => { + assert.true(person.hasDirtyAttributes, 'The person is still dirty'); + assert.strictEqual(person.name, 'Tomasz Dale', 'The local changes apply'); + assert.strictEqual(person.city, 'Portland', 'The updates from the server apply on top of the previous pushes'); }); }); test('When a record is dirty, pushes are overridden by local changes', function (assert) { let person; - run(() => { - person = this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - city: 'San Francisco', - }, + person = this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + city: 'San Francisco', }, - }); - person.set('name', 'Tomasz Dale'); + }, }); + person.set('name', 'Tomasz Dale'); assert.true(person.hasDirtyAttributes, 'the person is currently dirty'); assert.strictEqual(person.name, 'Tomasz Dale', 'the update was effective'); assert.strictEqual(person.city, 'San Francisco', 'the original data applies'); - run(() => { - this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Thomas Dale', - city: 'Portland', - }, + this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Thomas Dale', + city: 'Portland', }, - }); + }, }); assert.true(person.hasDirtyAttributes, 'the local changes are reapplied'); @@ -202,25 +182,21 @@ module('unit/model/merge - Merging', function (hooks) { test('When a record is invalid, pushes are overridden by local changes', async function (assert) { const ApplicationAdapter = Adapter.extend({ updateRecord() { - return reject(new InvalidError()); + return Promise.reject(new InvalidError()); }, }); this.owner.register('adapter:application', ApplicationAdapter); - let person; - - run(() => { - person = this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Brendan McLoughlin', - city: 'Boston', - }, + let person = this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Brendan McLoughlin', + city: 'Boston', }, - }); + }, }); person.set('name', 'Brondan McLoughlin'); @@ -236,17 +212,15 @@ module('unit/model/merge - Merging', function (hooks) { assert.strictEqual(person.name, 'Brondan McLoughlin', 'the update was effective'); assert.strictEqual(person.city, 'Boston', 'the original data applies'); - run(() => { - this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'bmac', - city: 'Prague', - }, + this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'bmac', + city: 'Prague', }, - }); + }, }); assert.true(person.hasDirtyAttributes, 'the local changes are reapplied'); @@ -255,7 +229,7 @@ module('unit/model/merge - Merging', function (hooks) { assert.strictEqual(person.city, 'Prague', 'if there are no local changes, the new data applied'); }); - test('A record with no changes can still be saved', function (assert) { + test('A record with no changes can still be saved', async function (assert) { assert.expect(1); const ApplicationAdapter = Adapter.extend({ @@ -266,26 +240,21 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = run(() => { - return this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, + let person = this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', }, - }); + }, }); - return run(() => { - return person.save().then((foo) => { - assert.strictEqual(person.name, 'Thomas Dale', 'the updates occurred'); - }); - }); + await person.save(); + assert.strictEqual(person.name, 'Thomas Dale', 'the updates occurred'); }); - test('A dirty record can be reloaded', function (assert) { + test('A dirty record can be reloaded', async function (assert) { assert.expect(3); const ApplicationAdapter = Adapter.extend({ @@ -298,27 +267,21 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person; - - run(() => { - person = this.store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, + let person = this.store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', }, - }); - person.set('name', 'Tomasz Dale'); + }, }); + person.set('name', 'Tomasz Dale'); - return run(() => { - return person.reload().then(() => { - assert.true(person.hasDirtyAttributes, 'the person is dirty'); - assert.strictEqual(person.name, 'Tomasz Dale', 'the local changes remain'); - assert.strictEqual(person.city, 'Portland', 'the new changes apply'); - }); + await person.reload().then(() => { + assert.true(person.hasDirtyAttributes, 'the person is dirty'); + assert.strictEqual(person.name, 'Tomasz Dale', 'the local changes remain'); + assert.strictEqual(person.city, 'Portland', 'the new changes apply'); }); }); }); diff --git a/tests/main/tests/unit/model/relationships/belongs-to-test.js b/tests/main/tests/unit/model/relationships/belongs-to-test.js index 5e19652cd7b..2637b5b992d 100644 --- a/tests/main/tests/unit/model/relationships/belongs-to-test.js +++ b/tests/main/tests/unit/model/relationships/belongs-to-test.js @@ -1,8 +1,6 @@ import { get } from '@ember/object'; -import { run } from '@ember/runloop'; import { module, test } from 'qunit'; -import { Promise } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -115,50 +113,46 @@ module('unit/model/relationships - belongsTo', function (hooks) { adapter.shouldBackgroundReloadRecord = () => false; - run(() => { - store.push({ - data: [ - { - type: 'tag', - id: '1', - attributes: { - name: 'whatever', - }, + store.push({ + data: [ + { + type: 'tag', + id: '1', + attributes: { + name: 'whatever', }, - { - type: 'person', - id: '2', - attributes: { - name: 'David J. Hamilton', - }, - relationships: { - tag: { - data: { - type: 'tag', - id: '1', - }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'David J. Hamilton', + }, + relationships: { + tag: { + data: { + type: 'tag', + id: '1', }, }, }, - ], - }); + }, + ], }); - return run(() => { - let person = store.peekRecord('person', 2); + let person = store.peekRecord('person', '2'); - let tagDidChange = () => assert.ok(false, 'observer is not called'); + let tagDidChange = () => assert.ok(false, 'observer is not called'); - person.addObserver('tag', tagDidChange); + person.addObserver('tag', tagDidChange); - assert.strictEqual(person.tag.name, 'whatever', 'relationship is correct'); + assert.strictEqual(person.tag.name, 'whatever', 'relationship is correct'); - // This needs to be removed so it is not triggered when test context is torn down - person.removeObserver('tag', tagDidChange); - }); + // This needs to be removed so it is not triggered when test context is torn down + person.removeObserver('tag', tagDidChange); }); - test('async belongsTo relationships work when the data hash has not been loaded', function (assert) { + test('async belongsTo relationships work when the data hash has not been loaded', async function (assert) { assert.expect(5); const Tag = Model.extend({ @@ -195,21 +189,17 @@ module('unit/model/relationships - belongsTo', function (hooks) { } }; - return run(() => { - return store - .findRecord('person', 1) - .then((person) => { - assert.strictEqual(get(person, 'name'), 'Tom Dale', 'The person is now populated'); - - return run(() => { - return get(person, 'tag'); - }); - }) - .then((tag) => { - assert.strictEqual(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); - assert.true(get(tag, 'isLoaded'), 'Tom Dale is now loaded'); - }); - }); + await store + .findRecord('person', '1') + .then((person) => { + assert.strictEqual(get(person, 'name'), 'Tom Dale', 'The person is now populated'); + + return person.tag; + }) + .then((tag) => { + assert.strictEqual(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.true(get(tag, 'isLoaded'), 'Tom Dale is now loaded'); + }); }); test('async belongsTo relationships are not grouped with coalesceFindRequests=false', async function (assert) { @@ -288,7 +278,7 @@ module('unit/model/relationships - belongsTo', function (hooks) { }; let persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; - let [tag1, tag2] = await Promise.all(persons.map((person) => get(person, 'tag'))); + let [tag1, tag2] = await Promise.all(persons.map((person) => person.tag)); assert.strictEqual(get(tag1, 'name'), 'friendly', 'Tom Dale is now friendly'); assert.true(get(tag1, 'isLoaded'), "Tom Dale's tag is now loaded"); @@ -371,7 +361,7 @@ module('unit/model/relationships - belongsTo', function (hooks) { }; let persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; - let [tag1, tag2] = await Promise.all(persons.map((person) => get(person, 'tag'))); + let [tag1, tag2] = await Promise.all(persons.map((person) => person.tag)); assert.strictEqual(get(tag1, 'name'), 'friendly', 'Tom Dale is now friendly'); assert.true(get(tag1, 'isLoaded'), "Tom Dale's tag is now loaded"); @@ -380,7 +370,7 @@ module('unit/model/relationships - belongsTo', function (hooks) { assert.true(get(tag2, 'isLoaded'), "Bob Dylan's tag is now loaded"); }); - test('async belongsTo relationships work when the data hash has already been loaded', function (assert) { + test('async belongsTo relationships work when the data hash has already been loaded', async function (assert) { assert.expect(3); const Tag = Model.extend({ @@ -397,42 +387,35 @@ module('unit/model/relationships - belongsTo', function (hooks) { let store = this.owner.lookup('service:store'); - run(() => { - store.push({ - data: [ - { - type: 'tag', - id: '2', - attributes: { - name: 'friendly', - }, + store.push({ + data: [ + { + type: 'tag', + id: '2', + attributes: { + name: 'friendly', }, - { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, - relationships: { - tag: { - data: { type: 'tag', id: '2' }, - }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + tag: { + data: { type: 'tag', id: '2' }, }, }, - ], - }); + }, + ], }); - return run(() => { - let person = store.peekRecord('person', 1); - assert.strictEqual(get(person, 'name'), 'Tom Dale', 'The person is now populated'); - return run(() => { - return get(person, 'tag'); - }).then((tag) => { - assert.strictEqual(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); - assert.true(get(tag, 'isLoaded'), 'Tom Dale is now loaded'); - }); - }); + let person = store.peekRecord('person', 1); + assert.strictEqual(get(person, 'name'), 'Tom Dale', 'The person is now populated'); + const tag = await person.tag; + assert.strictEqual(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); + assert.true(get(tag, 'isLoaded'), 'Tom Dale is now loaded'); }); deprecatedTest( @@ -523,16 +506,11 @@ module('unit/model/relationships - belongsTo', function (hooks) { adapter.shouldBackgroundReloadRecord = () => false; - store.createRecord('person', { id: '1', tag: undefined }); - - return run(() => { - return store.findRecord('person', '1').then((person) => { - assert.strictEqual(person.tag, null, 'undefined values should return null relationships'); - }); - }); + const person = store.createRecord('person', { tag: undefined }); + assert.strictEqual(person.tag, null, 'undefined values should return null relationships'); }); - test('When finding a hasMany relationship the inverse belongsTo relationship is available immediately', function (assert) { + test('When finding a hasMany relationship the inverse belongsTo relationship is available immediately', async function (assert) { const Occupation = Model.extend({ description: attr('string'), person: belongsTo('person', { async: false, inverse: 'occupations' }), @@ -563,42 +541,38 @@ module('unit/model/relationships - belongsTo', function (hooks) { adapter.coalesceFindRequests = true; - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, - relationships: { - occupations: { - data: [ - { type: 'occupation', id: '5' }, - { type: 'occupation', id: '2' }, - ], - }, + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + occupations: { + data: [ + { type: 'occupation', id: '5' }, + { type: 'occupation', id: '2' }, + ], }, }, - }); + }, }); - return run(() => { - return store - .findRecord('person', 1) - .then((person) => { - assert.true(get(person, 'isLoaded'), 'isLoaded should be true'); - assert.strictEqual(get(person, 'name'), 'Tom Dale', 'the person is still Tom Dale'); + await store + .findRecord('person', '1') + .then((person) => { + assert.true(get(person, 'isLoaded'), 'isLoaded should be true'); + assert.strictEqual(get(person, 'name'), 'Tom Dale', 'the person is still Tom Dale'); - return get(person, 'occupations'); - }) - .then((occupations) => { - assert.strictEqual(get(occupations, 'length'), 2, 'the list of occupations should have the correct length'); + return person.occupations; + }) + .then((occupations) => { + assert.strictEqual(get(occupations, 'length'), 2, 'the list of occupations should have the correct length'); - assert.strictEqual(get(occupations.at(0), 'description'), 'fifth', 'the occupation is the fifth'); - assert.true(get(occupations.at(0), 'isLoaded'), 'the occupation is now loaded'); - }); - }); + assert.strictEqual(get(occupations.at(0), 'description'), 'fifth', 'the occupation is the fifth'); + assert.true(get(occupations.at(0), 'isLoaded'), 'the occupation is now loaded'); + }); }); test('When finding a belongsTo relationship the inverse belongsTo relationship is available immediately', async function (assert) { @@ -716,7 +690,7 @@ module('unit/model/relationships - belongsTo', function (hooks) { ); }); - testInDebug('belongsTo gives a warning when provided with a serialize option', function (assert) { + testInDebug('belongsTo gives a warning when provided with a serialize option', async function (assert) { const Hobby = Model.extend({ name: attr('string'), }); @@ -734,49 +708,45 @@ module('unit/model/relationships - belongsTo', function (hooks) { adapter.shouldBackgroundReloadRecord = () => false; - run(() => { - store.push({ - data: [ - { - type: 'hobby', - id: '1', - attributes: { - name: 'fishing', - }, + store.push({ + data: [ + { + type: 'hobby', + id: '1', + attributes: { + name: 'fishing', }, - { - type: 'hobby', - id: '2', - attributes: { - name: 'coding', - }, + }, + { + type: 'hobby', + id: '2', + attributes: { + name: 'coding', }, - { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, - relationships: { - hobby: { - data: { type: 'hobby', id: '1' }, - }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + hobby: { + data: { type: 'hobby', id: '1' }, }, }, - ], - }); + }, + ], }); - return run(() => { - return store.findRecord('person', 1).then((person) => { - assert.expectWarning(() => { - get(person, 'hobby'); - }, /You provided a serialize option on the "hobby" property in the "person" class, this belongs in the serializer. See Serializer and it's implementations/); - }); + await store.findRecord('person', '1').then((person) => { + assert.expectWarning(() => { + person.hobby; + }, /You provided a serialize option on the "hobby" property in the "person" class, this belongs in the serializer. See Serializer and it's implementations/); }); }); - testInDebug('belongsTo gives a warning when provided with an embedded option', function (assert) { + testInDebug('belongsTo gives a warning when provided with an embedded option', async function (assert) { const Hobby = Model.extend({ name: attr('string'), }); @@ -794,45 +764,41 @@ module('unit/model/relationships - belongsTo', function (hooks) { adapter.shouldBackgroundReloadRecord = () => false; - run(() => { - store.push({ - data: [ - { - type: 'hobby', - id: '1', - attributes: { - name: 'fishing', - }, + store.push({ + data: [ + { + type: 'hobby', + id: '1', + attributes: { + name: 'fishing', }, - { - type: 'hobby', - id: '2', - attributes: { - name: 'coding', - }, + }, + { + type: 'hobby', + id: '2', + attributes: { + name: 'coding', }, - { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, - relationships: { - hobby: { - data: { type: 'hobby', id: '1' }, - }, + }, + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + hobby: { + data: { type: 'hobby', id: '1' }, }, }, - ], - }); + }, + ], }); - return run(() => { - return store.findRecord('person', 1).then((person) => { - assert.expectWarning(() => { - get(person, 'hobby'); - }, /You provided an embedded option on the "hobby" property in the "person" class, this belongs in the serializer. See EmbeddedRecordsMixin/); - }); + await store.findRecord('person', '1').then((person) => { + assert.expectWarning(() => { + person.hobby; + }, /You provided an embedded option on the "hobby" property in the "person" class, this belongs in the serializer. See EmbeddedRecordsMixin/); }); }); diff --git a/tests/main/tests/unit/model/rollback-attributes-test.js b/tests/main/tests/unit/model/rollback-attributes-test.js index 55595584d06..dd294d80fca 100644 --- a/tests/main/tests/unit/model/rollback-attributes-test.js +++ b/tests/main/tests/unit/model/rollback-attributes-test.js @@ -1,9 +1,7 @@ import { addObserver } from '@ember/object/observers'; -import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { reject } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -55,25 +53,21 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h let store = this.owner.lookup('service:store'); let person; - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - lastName: 'Dale', - }, + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + lastName: 'Dale', }, - }); - person = store.peekRecord('person', 1); - person.set('firstName', 'Thomas'); - - return person; + }, }); + person = store.peekRecord('person', 1); + person.set('firstName', 'Thomas'); assert.strictEqual(person.firstName, 'Thomas'); - run(() => person.rollbackAttributes()); + person.rollbackAttributes(); assert.strictEqual(person.firstName, undefined); assert.false(person.hasDirtyAttributes); @@ -131,7 +125,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h let adapter = store.adapterFor('application'); adapter.updateRecord = function (store, type, snapshot) { - return reject(); + return Promise.reject(); }; let person = store.push({ @@ -163,57 +157,53 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h } }); - test(`a deleted record's attributes can be rollbacked if it fails to save, record arrays are updated accordingly`, function (assert) { + test(`a deleted record's attributes can be rollbacked if it fails to save, record arrays are updated accordingly`, async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); adapter.deleteRecord = function (store, type, snapshot) { - return reject(); + return Promise.reject(); }; let person, people; - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - firstName: 'Tom', - lastName: 'Dale', - }, + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tom', + lastName: 'Dale', }, - }); - person = store.peekRecord('person', 1); - people = store.peekAll('person'); + }, }); + person = store.peekRecord('person', 1); + people = store.peekAll('person'); - run(() => person.deleteRecord()); + person.deleteRecord(); assert.strictEqual(people.length, 1, 'a deleted record appears in record array until it is saved'); assert.strictEqual(people.at(0), person, 'a deleted record appears in record array until it is saved'); - return run(() => { - return person - .save() - .catch(() => { - assert.true(person.isError); - assert.true(person.isDeleted); - - run(() => person.rollbackAttributes()); - - assert.false(person.isDeleted); - assert.false(person.isError); - assert.false(person.hasDirtyAttributes, 'must be not dirty'); - }) - .then(() => { - assert.strictEqual( - people.length, - 1, - 'the underlying record array is updated accordingly in an asynchronous way' - ); - }); - }); + await person + .save() + .catch(() => { + assert.true(person.isError); + assert.true(person.isDeleted); + + person.rollbackAttributes(); + + assert.false(person.isDeleted); + assert.false(person.isError); + assert.false(person.hasDirtyAttributes, 'must be not dirty'); + }) + .then(() => { + assert.strictEqual( + people.length, + 1, + 'the underlying record array is updated accordingly in an asynchronous way' + ); + }); }); test(`new record's attributes can be rollbacked`, function (assert) { @@ -223,7 +213,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h assert.true(person.isNew, 'must be new'); assert.true(person.hasDirtyAttributes, 'must be dirty'); - run(person, 'rollbackAttributes'); + person.rollbackAttributes(); assert.false(person.isNew, 'must not be new'); assert.false(person.hasDirtyAttributes, 'must not be dirty'); @@ -240,7 +230,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h let adapter = RESTAdapter.extend({ ajax(url, type, hash) { - return reject(error); + return Promise.reject(error); }, }); @@ -267,11 +257,11 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h } }); - test(`invalid record's attributes can be rollbacked after multiple failed calls - #3677`, function (assert) { + test(`invalid record's attributes can be rollbacked after multiple failed calls - #3677`, async function (assert) { let adapter = RESTAdapter.extend({ ajax(url, type, hash) { let error = new InvalidError(); - return reject(error); + return Promise.reject(error); }, }); @@ -280,43 +270,38 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h let store = this.owner.lookup('service:store'); - let person; - run(() => { - person = store.push({ - data: { - type: 'person', - id: '1', - attributes: { - firstName: 'original name', - }, + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'original name', }, - }); - - person.set('firstName', 'updated name'); + }, }); - return run(() => { - assert.strictEqual(person.firstName, 'updated name', 'precondition: firstName is changed'); - - return person - .save() - .catch(() => { - assert.true(person.hasDirtyAttributes, 'has dirty attributes'); - assert.strictEqual(person.firstName, 'updated name', 'firstName is still changed'); - - return person.save(); - }) - .catch(() => { - run(() => person.rollbackAttributes()); - - assert.false(person.hasDirtyAttributes, 'has no dirty attributes'); - assert.strictEqual( - person.firstName, - 'original name', - 'after rollbackAttributes() firstName has the original value' - ); - }); - }); + person.set('firstName', 'updated name'); + + assert.strictEqual(person.firstName, 'updated name', 'precondition: firstName is changed'); + + await person + .save() + .catch(() => { + assert.true(person.hasDirtyAttributes, 'has dirty attributes'); + assert.strictEqual(person.firstName, 'updated name', 'firstName is still changed'); + + return person.save(); + }) + .catch(() => { + person.rollbackAttributes(); + + assert.false(person.hasDirtyAttributes, 'has no dirty attributes'); + assert.strictEqual( + person.firstName, + 'original name', + 'after rollbackAttributes() firstName has the original value' + ); + }); }); test(`deleted record's attributes can be rollbacked`, function (assert) { @@ -324,24 +309,22 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h let person, people; - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - }, - }); - person = store.peekRecord('person', 1); - people = store.peekAll('person'); - person.deleteRecord(); + store.push({ + data: { + type: 'person', + id: '1', + }, }); + person = store.peekRecord('person', 1); + people = store.peekAll('person'); + person.deleteRecord(); assert.strictEqual(people.length, 1, 'a deleted record appears in the record array until it is saved'); assert.strictEqual(people.at(0), person, 'a deleted record appears in the record array until it is saved'); assert.true(person.isDeleted, 'must be deleted'); - run(() => person.rollbackAttributes()); + person.rollbackAttributes(); assert.strictEqual(people.length, 1, 'the rollbacked record should appear again in the record array'); assert.false(person.isDeleted, 'must not be deleted'); @@ -360,7 +343,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h ]); class TestAdapter extends RESTAdapter { ajax() { - return reject(thrownAdapterError); + return Promise.reject(thrownAdapterError); } } @@ -415,7 +398,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h ]); class TestAdapter extends RESTAdapter { ajax() { - return reject(thrownAdapterError); + return Promise.reject(thrownAdapterError); } } const { owner } = this; @@ -481,7 +464,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h let adapter = RESTAdapter.extend({ ajax(url, type, hash) { - return reject(error); + return Promise.reject(error); }, }); diff --git a/tests/main/tests/unit/store/adapter-interop-test.js b/tests/main/tests/unit/store/adapter-interop-test.js index b5899a931a0..986ff960c7d 100644 --- a/tests/main/tests/unit/store/adapter-interop-test.js +++ b/tests/main/tests/unit/store/adapter-interop-test.js @@ -1,9 +1,6 @@ -import { get, set } from '@ember/object'; -import { later } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { all, Promise as EmberPromise, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -33,7 +30,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho assert.strictEqual(id, '1', 'Adapter#find was called with the id passed into Store#find'); assert.strictEqual(snapshot.id, '1', 'Adapter#find was called with the record created from Store#find'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'test', @@ -59,7 +56,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho findMany(store, type, ids, snapshots) { assert.ok(true, 'Adapter#findMany was called'); assert.deepEqual(ids, ['1', '2'], 'Correct ids were passed in to findMany'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'test' }, { id: '2', type: 'test' }, @@ -75,7 +72,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let store = this.owner.lookup('service:store'); - await all([store.findRecord('test', '1'), store.findRecord('test', '2')]); + await Promise.all([store.findRecord('test', '1'), store.findRecord('test', '2')]); }); test('Coalesced Store#findRecord requests retain the `include` adapter option in the snapshots passed to adapter#findMany and adapter#findRecord', async function (assert) { @@ -107,7 +104,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho assert.deepEqual(snapshot.adapterOptions, options[snapshot.id], 'we were passed the right adapterOptions'); }); assert.deepEqual(ids, ['1', '2'], 'we were passed the expected ids'); - return resolve({ + return Promise.resolve({ data: snapshots.map(({ id }) => ({ id, type: type.modelName })), }); }, @@ -121,7 +118,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho assert.deepEqual(snapshot.adapterOptions, options[snapshot.id], 'we were passed the right adapterOptions'); assert.strictEqual(id, '3', 'we were passed the expected id'); - return resolve({ + return Promise.resolve({ data: { id, type: type.modelName }, }); }, @@ -135,7 +132,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let store = this.owner.lookup('service:store'); - await all( + await Promise.all( Object.keys(includedResourcesForIds).map((id) => store.findRecord('test', id, { include: includedResourcesForIds[id], adapterOptions: options[id] }) ) @@ -147,7 +144,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho const ApplicationAdapter = Adapter.extend({ findRecord(store, type, id, snapshot) { - return resolve({ data: { id: '1', type: 'test', attributes: { name: 'Scumbag Dale' } } }); + return Promise.resolve({ data: { id: '1', type: 'test', attributes: { name: 'Scumbag Dale' } } }); }, }); @@ -158,7 +155,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let store = this.owner.lookup('service:store'); await store.findRecord('test', '1').then((object) => { - assert.strictEqual(get(object, 'name'), 'Scumbag Dale', 'the data was pushed'); + assert.strictEqual(object.name, 'Scumbag Dale', 'the data was pushed'); }); }); @@ -168,7 +165,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho const ApplicationAdapter = Adapter.extend({ findRecord(store, type, id, snapshot) { assert.strictEqual(typeof id, 'string', 'id has been normalized to a string'); - return resolve({ data: { id, type: 'test', attributes: { name: 'Scumbag Sylvain' } } }); + return Promise.resolve({ data: { id, type: 'test', attributes: { name: 'Scumbag Sylvain' } } }); }, }); @@ -234,8 +231,8 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }); await store.findRecord('person', '1').then((tom) => { - assert.false(get(tom, 'hasDirtyAttributes'), 'precond - record is not dirty'); - assert.strictEqual(get(tom, 'name'), 'Tom Dale', 'returns the correct name'); + assert.false(tom.hasDirtyAttributes, 'precond - record is not dirty'); + assert.strictEqual(tom.name, 'Tom Dale', 'returns the correct name'); store.push({ data: { @@ -246,7 +243,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, }, }); - assert.strictEqual(get(tom, 'name'), 'Captain Underpants', 'updated record with new date'); + assert.strictEqual(tom.name, 'Captain Underpants', 'updated record with new date'); }); }); @@ -263,7 +260,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho query(store, type, query) { assert.strictEqual(type, store.modelFor('person'), 'The type was Person'); assert.strictEqual(query, passedQuery, 'The query was passed in'); - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); }, }); @@ -286,7 +283,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho const ApplicationAdapter = Adapter.extend({ query(store, type, query) { - return resolve([]); + return Promise.resolve([]); }, }); @@ -330,7 +327,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let results = store.peekAll('person'); - assert.strictEqual(get(results, 'length'), 1, 'record array should have the original object'); + assert.strictEqual(results.length, 1, 'record array should have the original object'); assert.strictEqual(results.at(0).name, 'Tom Dale', 'record has the correct information'); store.push({ @@ -358,13 +355,13 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let person = this.owner.lookup('service:store').createRecord('person'); - assert.true(get(person, 'isLoaded'), 'A newly created record is loaded'); - assert.true(get(person, 'isNew'), 'A newly created record is new'); - assert.true(get(person, 'hasDirtyAttributes'), 'A newly created record is dirty'); + assert.true(person.isLoaded, 'A newly created record is loaded'); + assert.true(person.isNew, 'A newly created record is new'); + assert.true(person.hasDirtyAttributes, 'A newly created record is dirty'); - set(person, 'name', 'Braaahm Dale'); + person.name = 'Braaahm Dale'; - assert.strictEqual(get(person, 'name'), 'Braaahm Dale', 'Even if no hash is supplied, `set` still worked'); + assert.strictEqual(person.name, 'Braaahm Dale', 'Even if no hash is supplied, `set` still worked'); }); testInDebug( @@ -396,11 +393,11 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let store = this.owner.lookup('service:store'); let person = store.createRecord('person', { name: 'Brohuda Katz' }); - assert.true(get(person, 'isLoaded'), 'A newly created record is loaded'); - assert.true(get(person, 'isNew'), 'A newly created record is new'); - assert.true(get(person, 'hasDirtyAttributes'), 'A newly created record is dirty'); + assert.true(person.isLoaded, 'A newly created record is loaded'); + assert.true(person.isNew, 'A newly created record is new'); + assert.true(person.hasDirtyAttributes, 'A newly created record is dirty'); - assert.strictEqual(get(person, 'name'), 'Brohuda Katz', 'The initial data hash is provided'); + assert.strictEqual(person.name, 'Brohuda Katz', 'The initial data hash is provided'); }); test('if an id is supplied in the initial data hash, it can be looked up using `store.find`', async function (assert) { @@ -650,7 +647,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho let tom = store.createRecord('person', { name: 'Tom Dale' }); let yehuda = store.createRecord('person', { name: 'Yehuda Katz' }); - await all([tom.save(), yehuda.save()]).then(() => { + await Promise.all([tom.save(), yehuda.save()]).then(() => { people.forEach((person, index) => { assert.strictEqual(person.id, String(index + 1), `The record's id should be correct.`); }); @@ -691,7 +688,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho store.identifierCache.getOrCreateRecordIdentifier({ type: 'test', id: '21' }), ]; - const result = await all(identifiers.map((id) => store.findRecord(id))); + const result = await Promise.all(identifiers.map((id) => store.findRecord(id))); let ids = result.map((x) => x.id); assert.deepEqual(ids, ['10', '20', '21'], 'The promise fulfills with the identifiers'); @@ -710,14 +707,14 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho findRecord(store, type, id, snapshot) { let record = { id, type: 'test' }; - return new EmberPromise(function (resolve, reject) { + return new Promise(function (resolve, reject) { if (id === 'igor') { resolve({ data: record }); } else { - later(function () { + setTimeout(function () { davidResolved = true; resolve({ data: record }); - }, 5); + }, 1); } }); }, @@ -745,7 +742,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }) ); - await all(wait); + await Promise.all(wait); }); test('the promise returned by `findRecord`, when it rejects, does not depend on the promises returned to other calls to `findRecord` that are in the same run loop, but different groups', async function (assert) { @@ -761,11 +758,11 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho findRecord(store, type, id, snapshot) { let record = { id, type: 'test' }; - return new EmberPromise((resolve, reject) => { + return new Promise((resolve, reject) => { if (id === 'igor') { reject({ data: record }); } else { - later(() => { + setTimeout(() => { davidResolved = true; resolve({ data: record }); }, 5); @@ -796,7 +793,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }) ); - await EmberPromise.all(wait); + await Promise.all(wait); }); testInDebug( diff --git a/tests/main/tests/unit/store/asserts-test.js b/tests/main/tests/unit/store/asserts-test.js index 35f8f8f0220..5f69fd4f90a 100644 --- a/tests/main/tests/unit/store/asserts-test.js +++ b/tests/main/tests/unit/store/asserts-test.js @@ -1,4 +1,4 @@ -import { run } from '@ember/runloop'; +import { settled } from '@ember/test-helpers'; import { module } from 'qunit'; @@ -67,11 +67,11 @@ module('unit/store/asserts - DS.Store methods produce useful assertion messages' 'serializerFor', ]; - test('Calling Store methods after the store has been destroyed asserts', function (assert) { + test('Calling Store methods after the store has been destroyed asserts', async function (assert) { const store = new Store(); store.shouldAssertMethodCallsOnDestroyedStore = true; assert.expect(STORE_ENTRY_METHODS.length); - run(() => store.destroy()); + await settled(); STORE_ENTRY_METHODS.forEach((methodName) => { assert.expectAssertion(() => { diff --git a/tests/main/tests/unit/store/push-test.js b/tests/main/tests/unit/store/push-test.js index e4a26c7d643..2c2ec4a2979 100644 --- a/tests/main/tests/unit/store/push-test.js +++ b/tests/main/tests/unit/store/push-test.js @@ -1,7 +1,7 @@ +// eslint-disable-next-line no-restricted-imports import { run } from '@ember/runloop'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -189,7 +189,7 @@ module('unit/store/push - Store#push', function (hooks) { assert.strictEqual(person.lastName, 'Jackson', 'existing fields are untouched'); }); - test('Calling push with a normalized hash containing IDs of related records returns a record', function (assert) { + test('Calling push with a normalized hash containing IDs of related records returns a record', async function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); @@ -205,7 +205,7 @@ module('unit/store/push - Store#push', function (hooks) { adapter.findRecord = function (store, type, id) { if (id === '1') { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'phone-number', @@ -220,7 +220,7 @@ module('unit/store/push - Store#push', function (hooks) { } if (id === '2') { - return resolve({ + return Promise.resolve({ data: { id: '2', type: 'phone-number', @@ -235,42 +235,40 @@ module('unit/store/push - Store#push', function (hooks) { } }; - return run(() => { - let normalized = store.normalize('person', { - id: 'wat', - type: 'person', - attributes: { - 'first-name': 'John', - 'last-name': 'Smith', - }, - relationships: { - 'phone-numbers': { - data: [ - { id: '1', type: 'phone-number' }, - { id: '2', type: 'phone-number' }, - ], - }, + let normalized = store.normalize('person', { + id: 'wat', + type: 'person', + attributes: { + 'first-name': 'John', + 'last-name': 'Smith', + }, + relationships: { + 'phone-numbers': { + data: [ + { id: '1', type: 'phone-number' }, + { id: '2', type: 'phone-number' }, + ], }, - }); - let person = store.push(normalized); + }, + }); + let person = store.push(normalized); - return person.phoneNumbers.then((phoneNumbers) => { - let items = phoneNumbers.map((item) => { - return item ? item.getProperties('id', 'number', 'person') : null; - }); - assert.deepEqual(items, [ - { - id: '1', - number: '5551212', - person: person, - }, - { - id: '2', - number: '5552121', - person: person, - }, - ]); + await person.phoneNumbers.then((phoneNumbers) => { + let items = phoneNumbers.map((item) => { + return item ? item.getProperties('id', 'number', 'person') : null; }); + assert.deepEqual(items, [ + { + id: '1', + number: '5551212', + person: person, + }, + { + id: '2', + number: '5552121', + person: person, + }, + ]); }); }); diff --git a/tests/main/tests/unit/store/unload-test.js b/tests/main/tests/unit/store/unload-test.js index 0b12c1c8a41..d5bb00b1253 100644 --- a/tests/main/tests/unit/store/unload-test.js +++ b/tests/main/tests/unit/store/unload-test.js @@ -1,8 +1,6 @@ import { get } from '@ember/object'; -import { run } from '@ember/runloop'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -31,7 +29,7 @@ module('unit/store/unload - Store unloading records', function (hooks) { Adapter.extend({ findRecord(store, type, id, snapshot) { tryToFind = true; - return resolve({ + return Promise.resolve({ data: { id, type: snapshot.modelName, attributes: { 'was-fetched': true } }, }); }, @@ -80,51 +78,45 @@ module('unit/store/unload - Store unloading records', function (hooks) { await promise; }); - test('unload a record', function (assert) { + test('unload a record', async function (assert) { assert.expect(2); - return run(() => { - store.push({ - data: { - type: 'record', - id: '1', - attributes: { - title: 'toto', - }, + store.push({ + data: { + type: 'record', + id: '1', + attributes: { + title: 'toto', }, - }); + }, + }); - return store.findRecord('record', 1).then((record) => { - assert.strictEqual(get(record, 'id'), '1', 'found record with id 1'); + const record = await store.findRecord('record', '1'); + assert.strictEqual(get(record, 'id'), '1', 'found record with id 1'); - run(() => store.unloadRecord(record)); + store.unloadRecord(record); - tryToFind = false; + tryToFind = false; - return store.findRecord('record', 1).then(() => { - assert.true(tryToFind, 'not found record with id 1'); - }); - }); - }); + await store.findRecord('record', '1'); + assert.true(tryToFind, 'not found record with id 1'); }); - test('unload followed by create of the same type + id', function (assert) { + test('unload followed by create of the same type + id', async function (assert) { let record = store.createRecord('record', { id: '1' }); assert.strictEqual(store.peekRecord('record', 1), record, 'record should exactly equal'); - return run(() => { - record.unloadRecord(); - let createdRecord = store.createRecord('record', { id: '1' }); - assert.notStrictEqual(record, createdRecord, 'newly created record is fresh (and was created)'); - }); + record.unloadRecord(); + let createdRecord = store.createRecord('record', { id: '1' }); + assert.notStrictEqual(record, createdRecord, 'newly created record is fresh (and was created)'); }); }); module('Store - unload record with relationships', function (hooks) { setupTest(hooks); - test('can commit store after unload record with relationships', function (assert) { + test('can commit store after unload record with relationships', async function (assert) { assert.expect(1); const Brand = Model.extend({ @@ -155,8 +147,11 @@ module('Store - unload record with relationships', function (hooks) { this.owner.register( 'adapter:application', Adapter.extend({ + shouldBackgroundReloadRecord() { + return false; + }, findRecord(store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: snapshot.modelName, @@ -169,56 +164,51 @@ module('Store - unload record with relationships', function (hooks) { }, createRecord(store, type, snapshot) { - return resolve(); + return Promise.resolve(); }, }) ); let store = this.owner.lookup('service:store'); - return run(() => { - store.push({ - data: [ - { - type: 'brand', - id: '1', - attributes: { - name: 'EmberJS', - }, + store.push({ + data: [ + { + type: 'brand', + id: '1', + attributes: { + name: 'EmberJS', }, - { - type: 'product', - id: '1', - attributes: { - description: 'toto', - }, - relationships: { - brand: { - data: { type: 'brand', id: '1' }, - }, + }, + { + type: 'product', + id: '1', + attributes: { + description: 'toto', + }, + relationships: { + brand: { + data: { type: 'brand', id: '1' }, }, }, - ], - }); + }, + ], + }); - let product = store.peekRecord('product', 1); - let like = store.createRecord('like', { id: '1', product: product }); + let product = store.peekRecord('product', 1); + let like = store.createRecord('like', { id: '1', product: product }); - return like.save(); - }) - .then(() => { - // TODO: this is strange, future travelers please address - run(() => store.unloadRecord(store.peekRecord('product', 1))); - }) - .then(() => { - return store.findRecord('product', 1); - }) - .then((product) => { - assert.strictEqual( - product.description, - 'cuisinart', - "The record was unloaded and the adapter's `findRecord` was called" - ); - }); + await like.save(); + + // TODO: this is strange, future travelers please address + store.unloadRecord(product); + + product = await store.findRecord('product', '1'); + + assert.strictEqual( + product.description, + 'cuisinart', + "The record was unloaded and the adapter's `findRecord` was called" + ); }); }); diff --git a/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js b/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js index 9c52cf1efa5..78c170640b7 100644 --- a/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js +++ b/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js @@ -1,5 +1,3 @@ -import { run } from '@ember/runloop'; - import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; @@ -62,7 +60,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio included: [hatData1, bigHatData1, smallHatData1], }; - const user = run(() => this.store.push(userData)); + const user = this.store.push(userData); const finalResult = user.hats.map((r) => r.type); @@ -117,7 +115,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio included, }; - const user = run(() => this.store.push(userData)), + const user = this.store.push(userData), finalResult = user.hats.map((r) => r.type), expectedResults = included.map((m) => m.type); @@ -173,7 +171,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio included, }; - const user = run(() => this.store.push(userData)), + const user = this.store.push(userData), finalResult = user.hats.map((r) => r.type), expectedResults = included.map((m) => m.type); @@ -229,7 +227,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }; const expectedAlienResults = alienIncluded.map((m) => m.type), - alien = run(() => this.store.push(alienData)), + alien = this.store.push(alienData), alienFinalHats = alien.hats.map((r) => r.type); assert.deepEqual(alienFinalHats, expectedAlienResults, 'We got all alien hats!'); @@ -303,13 +301,8 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio included: [bigHatData3, smallHatData3], }; - const bigPerson = run(() => { - return this.store.push(bigPersonData); - }); - - const smallPerson = run(() => { - return this.store.push(smallPersonData); - }); + const bigPerson = this.store.push(bigPersonData); + const smallPerson = this.store.push(smallPersonData); const finalBigResult = bigPerson.hats.slice(); const finalSmallResult = smallPerson.hats.slice(); @@ -400,10 +393,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio { type: 'grownup', id: motherPayload.id }, ]; const expectedTwinReference = { type: 'girl', id: sisterPayload.id }; - - const boyInstance = run(() => { - return this.store.push(payload); - }); + const boyInstance = this.store.push(payload); const familyResultReferences = boyInstance.family.slice().map((i) => { return { type: i.constructor.modelName, id: i.id }; @@ -500,10 +490,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio { type: 'grownup', id: motherPayload.id }, ]; const expectedTwinReference = { type: 'girl', id: sisterPayload.id }; - - const boyInstance = run(() => { - return this.store.push(payload); - }); + const boyInstance = this.store.push(payload); const familyResultReferences = boyInstance.family.slice().map((i) => { return { type: i.constructor.modelName, id: i.id }; @@ -593,7 +580,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }, }; - const hat = run(() => this.store.push(hatData)); + const hat = this.store.push(hatData); const expectedHatReference = { id: '1', type: 'big-hat' }; const expectedHatsReferences = [{ id: '1', type: 'big-hat' }]; @@ -629,32 +616,30 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio this.owner.register('model:big-hat', BigHat); this.owner.register('model:small-hat', SmallHat); - const user = run(() => - this.store.push({ - data: { - id: '1', - type: 'user', - relationships: { - hats: { - data: [ - { id: '1', type: 'big-hat' }, - { id: '1', type: 'small-hat' }, - ], - }, + const user = this.store.push({ + data: { + id: '1', + type: 'user', + relationships: { + hats: { + data: [ + { id: '1', type: 'big-hat' }, + { id: '1', type: 'small-hat' }, + ], }, }, - included: [ - { - id: '1', - type: 'big-hat', - }, - { - id: '1', - type: 'small-hat', - }, - ], - }) - ); + }, + included: [ + { + id: '1', + type: 'big-hat', + }, + { + id: '1', + type: 'small-hat', + }, + ], + }); const hats = user.hats; @@ -683,34 +668,32 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio this.owner.register('model:big-hat', Hat.extend({})); this.owner.register('model:small-hat', Hat.extend({})); - const user = run(() => - this.store.push({ - data: { + const user = this.store.push({ + data: { + id: '1', + type: 'user', + }, + included: [ + { id: '1', - type: 'user', - }, - included: [ - { - id: '1', - type: 'big-hat', - relationships: { - user: { - data: { id: '1', type: 'user' }, - }, + type: 'big-hat', + relationships: { + user: { + data: { id: '1', type: 'user' }, }, }, - { - id: '1', - type: 'small-hat', - relationships: { - user: { - data: { id: '1', type: 'user' }, - }, + }, + { + id: '1', + type: 'small-hat', + relationships: { + user: { + data: { id: '1', type: 'user' }, }, }, - ], - }) - ); + }, + ], + }); const hats = user.hats; @@ -794,13 +777,8 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio included: [bigHatData3, smallHatData3], }; - const bigPerson = run(() => { - return this.store.push(bigPersonData); - }); - - const smallPerson = run(() => { - return this.store.push(smallPersonData); - }); + const bigPerson = this.store.push(bigPersonData); + const smallPerson = this.store.push(smallPersonData); const finalBigResult = bigPerson.hats.slice(); const finalSmallResult = smallPerson.hats.slice(); @@ -842,32 +820,30 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio ); let runInvalidPush = () => { - return run(() => { - return this.store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - data: [{ type: 'comment', id: '1' }], - }, + return this.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], }, }, - included: [ - { - type: 'comment', - id: '1', - relationships: { - post: { - data: { - type: 'post', - id: '1', - }, + }, + included: [ + { + type: 'comment', + id: '1', + relationships: { + post: { + data: { + type: 'post', + id: '1', }, }, }, - ], - }); + }, + ], }); }; diff --git a/tests/main/tests/unit/utils/determine-body-promise-test.js b/tests/main/tests/unit/utils/determine-body-promise-test.js index 030cf52b36a..a5f3579ee7b 100644 --- a/tests/main/tests/unit/utils/determine-body-promise-test.js +++ b/tests/main/tests/unit/utils/determine-body-promise-test.js @@ -1,7 +1,6 @@ // Tests copied from ember-fetch addon import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { determineBodyPromise } from '@ember-data/adapter/-private'; @@ -14,7 +13,7 @@ class Response { } text() { - return resolve(this._text); + return Promise.resolve(this._text); } } diff --git a/tests/performance/app/adapters/application.js b/tests/performance/app/adapters/application.js index 83f27bb1319..7f63157a7fd 100644 --- a/tests/performance/app/adapters/application.js +++ b/tests/performance/app/adapters/application.js @@ -1,7 +1,5 @@ import EmberObject from '@ember/object'; -import { resolve } from 'rsvp'; - export default class ApplicationMockAdapter extends EmberObject { findAll() { return fetch('./fixtures/relationship-materialization-simple.json').then((response) => response.json()); @@ -13,6 +11,6 @@ export default class ApplicationMockAdapter extends EmberObject { return false; } deleteRecord = function () { - return resolve(); + return Promise.resolve(); }; } diff --git a/tests/performance/app/routes/destroy.js b/tests/performance/app/routes/destroy.js index 159bb96725b..3e9356aa91b 100644 --- a/tests/performance/app/routes/destroy.js +++ b/tests/performance/app/routes/destroy.js @@ -1,8 +1,6 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; -import { all } from 'rsvp'; - export default Route.extend({ store: service(), @@ -15,10 +13,10 @@ export default Route.extend({ performance.mark('start-destroy-records'); const children = await parent.children; - const childrenPromise = all(children.slice().map((child) => child.destroyRecord())); + const childrenPromise = Promise.all(children.slice().map((child) => child.destroyRecord())); const parentPromise = parent.destroyRecord(); - await all([childrenPromise, parentPromise]); + await Promise.all([childrenPromise, parentPromise]); performance.mark('end-destroy-records'); }, diff --git a/tests/performance/app/routes/unload-all.js b/tests/performance/app/routes/unload-all.js index 02a4ece9679..da4e567871d 100644 --- a/tests/performance/app/routes/unload-all.js +++ b/tests/performance/app/routes/unload-all.js @@ -1,5 +1,4 @@ import Route from '@ember/routing/route'; -import { run } from '@ember/runloop'; import { inject as service } from '@ember/service'; export default Route.extend({ @@ -15,9 +14,7 @@ export default Route.extend({ this.store.peekAll('parent').slice(); performance.mark('start-unload-all'); - run(() => { - this.store.unloadAll(); - }); + this.store.unloadAll(); performance.mark('end-unload-all'); }, }); diff --git a/tests/performance/app/routes/unload.js b/tests/performance/app/routes/unload.js index 871250753ce..9e3326942a4 100644 --- a/tests/performance/app/routes/unload.js +++ b/tests/performance/app/routes/unload.js @@ -1,5 +1,4 @@ import Route from '@ember/routing/route'; -import { run } from '@ember/runloop'; import { inject as service } from '@ember/service'; export default Route.extend({ @@ -14,9 +13,7 @@ export default Route.extend({ const children = await parent.children; // runloop to ensure destroy does not escape bounds of the test - run(() => { - children.slice().forEach((child) => child.unloadRecord()); - }); + children.slice().forEach((child) => child.unloadRecord()); performance.mark('end-unload-records'); }, }); diff --git a/tests/recommended-json-api/tests/test-helper.js b/tests/recommended-json-api/tests/test-helper.js index 147cf2a3d4d..58a28decd69 100644 --- a/tests/recommended-json-api/tests/test-helper.js +++ b/tests/recommended-json-api/tests/test-helper.js @@ -2,7 +2,6 @@ import { setApplication } from '@ember/test-helpers'; import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; -import RSVP from 'rsvp'; import { start } from 'ember-qunit'; @@ -13,10 +12,6 @@ import customQUnitAdapter from '@ember-data/unpublished-test-infra/test-support/ import Application from '../app'; import config from '../config/environment'; -if (window.Promise === undefined) { - window.Promise = RSVP.Promise; -} - // Handle testing feature flags if (QUnit.urlParams.enableoptionalfeatures) { window.EmberDataENV = { ENABLE_OPTIONAL_FEATURES: true }; @@ -34,18 +29,6 @@ if (window.Testem) { window.Testem.useCustomAdapter(customQUnitAdapter); } -QUnit.begin(function () { - RSVP.configure('onerror', (reason) => { - // only print error messages if they're exceptions; - // otherwise, let a future turn of the event loop - // handle the error. - // TODO kill this off - if (reason && reason instanceof Error) { - throw reason; - } - }); -}); - QUnit.config.testTimeout = 2000; QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', diff --git a/tests/request/tests/test-helper.js b/tests/request/tests/test-helper.js index 147cf2a3d4d..58a28decd69 100644 --- a/tests/request/tests/test-helper.js +++ b/tests/request/tests/test-helper.js @@ -2,7 +2,6 @@ import { setApplication } from '@ember/test-helpers'; import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; -import RSVP from 'rsvp'; import { start } from 'ember-qunit'; @@ -13,10 +12,6 @@ import customQUnitAdapter from '@ember-data/unpublished-test-infra/test-support/ import Application from '../app'; import config from '../config/environment'; -if (window.Promise === undefined) { - window.Promise = RSVP.Promise; -} - // Handle testing feature flags if (QUnit.urlParams.enableoptionalfeatures) { window.EmberDataENV = { ENABLE_OPTIONAL_FEATURES: true }; @@ -34,18 +29,6 @@ if (window.Testem) { window.Testem.useCustomAdapter(customQUnitAdapter); } -QUnit.begin(function () { - RSVP.configure('onerror', (reason) => { - // only print error messages if they're exceptions; - // otherwise, let a future turn of the event loop - // handle the error. - // TODO kill this off - if (reason && reason instanceof Error) { - throw reason; - } - }); -}); - QUnit.config.testTimeout = 2000; QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', diff --git a/tests/serializer-encapsulation/tests/integration/create-record-test.js b/tests/serializer-encapsulation/tests/integration/create-record-test.js index 9068d0359ac..f6363fe88c8 100644 --- a/tests/serializer-encapsulation/tests/integration/create-record-test.js +++ b/tests/serializer-encapsulation/tests/integration/create-record-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import Store from 'serializer-encapsulation-test-app/services/store'; import { setupTest } from 'ember-qunit'; @@ -81,7 +80,7 @@ module('Serializer Contract | running createRecord with minimum serializer', fun class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return resolve({ + return Promise.resolve({ id: '1m', type: 'person', attributes: { @@ -176,7 +175,7 @@ module('Serializer Contract | running createRecord with minimum serializer', fun class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return resolve({ + return Promise.resolve({ person: { id: '1m', type: 'person', diff --git a/tests/serializer-encapsulation/tests/integration/delete-record-test.js b/tests/serializer-encapsulation/tests/integration/delete-record-test.js index 0e46d859140..44d22814a5c 100644 --- a/tests/serializer-encapsulation/tests/integration/delete-record-test.js +++ b/tests/serializer-encapsulation/tests/integration/delete-record-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import Store from 'serializer-encapsulation-test-app/services/store'; import { setupTest } from 'ember-qunit'; @@ -81,7 +80,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun _payloads = [..._payloads]; ajax(url, type) { - return resolve(this._payloads.shift()); + return Promise.resolve(this._payloads.shift()); } } this.owner.register('adapter:application', TestAdapter); @@ -158,7 +157,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun _payloads = [..._payloads]; ajax(url, type) { - return resolve(this._payloads.shift()); + return Promise.resolve(this._payloads.shift()); } } this.owner.register('adapter:application', TestAdapter); @@ -222,7 +221,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun _payloads = [..._payloads]; ajax(url, type) { - return resolve(this._payloads.shift()); + return Promise.resolve(this._payloads.shift()); } } this.owner.register('adapter:application', TestAdapter); diff --git a/tests/serializer-encapsulation/tests/integration/errors-test.js b/tests/serializer-encapsulation/tests/integration/errors-test.js index 0d12902b761..d19268b129a 100644 --- a/tests/serializer-encapsulation/tests/integration/errors-test.js +++ b/tests/serializer-encapsulation/tests/integration/errors-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { reject } from 'rsvp'; import Store from 'serializer-encapsulation-test-app/services/store'; import { setupTest } from 'ember-qunit'; @@ -38,7 +37,7 @@ module( test('can retrieve errors after findRecord', async function (assert) { class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return reject({ + return Promise.reject({ errors: [ { status: '404', @@ -67,7 +66,7 @@ module( test('can retrieve errors after save', async function (assert) { class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return reject({ + return Promise.reject({ errors: [ { status: '400', diff --git a/tests/serializer-encapsulation/tests/integration/relationships-test.js b/tests/serializer-encapsulation/tests/integration/relationships-test.js index 42b46349450..407f32799c3 100644 --- a/tests/serializer-encapsulation/tests/integration/relationships-test.js +++ b/tests/serializer-encapsulation/tests/integration/relationships-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import Store from 'serializer-encapsulation-test-app/services/store'; import { setupTest } from 'ember-qunit'; @@ -84,7 +83,7 @@ module('Serializer Contract | running requests for async relationships with mini coalesceFindRequests = true; ajax(url, type) { - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); } } this.owner.register('adapter:application', TestAdapter); @@ -158,7 +157,7 @@ module('Serializer Contract | running requests for async relationships with mini coalesceFindRequests = true; ajax(url, type) { - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); } } this.owner.register('adapter:application', TestAdapter); @@ -224,7 +223,7 @@ module('Serializer Contract | running requests for async relationships with mini coalesceFindRequests = true; ajax(url, type) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', diff --git a/tests/serializer-encapsulation/tests/integration/requests-test.js b/tests/serializer-encapsulation/tests/integration/requests-test.js index 3b4faffe056..8a6856c4d84 100644 --- a/tests/serializer-encapsulation/tests/integration/requests-test.js +++ b/tests/serializer-encapsulation/tests/integration/requests-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import Store from 'serializer-encapsulation-test-app/services/store'; import { setupTest } from 'ember-qunit'; @@ -47,7 +46,7 @@ module('Serializer Contract | running requests with minimum serializer', functio class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); } } this.owner.register('adapter:application', TestAdapter); @@ -95,7 +94,7 @@ module('Serializer Contract | running requests with minimum serializer', functio class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return resolve({ + return Promise.resolve({ data: { type: 'person', id: 'urn:person:1', @@ -141,7 +140,7 @@ module('Serializer Contract | running requests with minimum serializer', functio class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); } } this.owner.register('adapter:application', TestAdapter); @@ -189,7 +188,7 @@ module('Serializer Contract | running requests with minimum serializer', functio class TestAdapter extends JSONAPIAdapter { ajax(url, type) { - return resolve({ + return Promise.resolve({ data: { type: 'person', id: 'urn:person:1', diff --git a/tests/serializer-encapsulation/tests/integration/update-record-test.js b/tests/serializer-encapsulation/tests/integration/update-record-test.js index 24df0a53c39..ec2fe1df0a1 100644 --- a/tests/serializer-encapsulation/tests/integration/update-record-test.js +++ b/tests/serializer-encapsulation/tests/integration/update-record-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import Store from 'serializer-encapsulation-test-app/services/store'; import { setupTest } from 'ember-qunit'; @@ -98,7 +97,7 @@ module('Serializer Contract | running createRecord [update] with minimum seriali _payloads = [..._payloads]; ajax(url, type) { - return resolve(this._payloads.shift()); + return Promise.resolve(this._payloads.shift()); } } this.owner.register('adapter:application', TestAdapter); @@ -201,7 +200,7 @@ module('Serializer Contract | running createRecord [update] with minimum seriali _payloads = [..._payloads]; ajax(url, type) { - return resolve(this._payloads.shift()); + return Promise.resolve(this._payloads.shift()); } } this.owner.register('adapter:application', TestAdapter); From 4897002394dc3ffceda1092acd6aecb82a286c59 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 11 Sep 2023 01:58:46 -0700 Subject: [PATCH 2/6] fixup --- pnpm-lock.yaml | 9 --------- tests/main/app/backburner-flush-override.js | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9bb79547415..775c6231324 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -57,9 +57,6 @@ importers: '@glimmer/component': specifier: ^1.1.2 version: 1.1.2(@babel/core@7.22.15) - '@glimmer/env': - specifier: ^0.1.7 - version: 0.1.7 '@types/jquery': specifier: ^3.5.18 version: 3.5.18 @@ -222,9 +219,6 @@ importers: '@embroider/macros': specifier: ^1.12.2 version: 1.13.1(@babel/core@7.22.15) - '@glimmer/env': - specifier: ^0.1.7 - version: 0.1.7 broccoli-merge-trees: specifier: ^4.2.0 version: 4.2.0 @@ -2607,9 +2601,6 @@ importers: '@glimmer/component': specifier: ^1.1.2 version: 1.1.2(@babel/core@7.22.15) - '@glimmer/env': - specifier: ^0.1.7 - version: 0.1.7 '@glimmer/tracking': specifier: ^1.1.2 version: 1.1.2 diff --git a/tests/main/app/backburner-flush-override.js b/tests/main/app/backburner-flush-override.js index b4fdbbe15d2..66be5bf23f6 100644 --- a/tests/main/app/backburner-flush-override.js +++ b/tests/main/app/backburner-flush-override.js @@ -2,6 +2,7 @@ An alternative render flush mechanism for glimmer */ import { Renderer } from '@ember/-internals/glimmer'; +// eslint-disable-next-line no-restricted-imports import { _backburner } from '@ember/runloop'; import * as RSVP from 'rsvp'; From c6ff09ed257f6d650e55e55c56bfed141e5babe2 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 11 Sep 2023 02:21:13 -0700 Subject: [PATCH 3/6] more rsvp burndown --- .../tests/integration/belongs-to-test.js | 11 +- .../tests/integration/coalescing-test.js | 29 ++-- .../tests/integration/has-many-test.js | 17 +-- .../tests/integration/mutations-test.js | 11 +- .../tests/integration/queries-test.js | 13 +- .../tests/integration/reload-test.js | 5 +- tests/graph/tests/test-helper.js | 17 --- tests/json-api/tests/test-helper.js | 17 --- .../relationships/belongs-to-test.js | 3 +- .../acceptance/relationships/has-many-test.js | 7 +- .../tracking-record-state-test.js | 1 - .../acceptance/tracking-model-id-test.js | 3 +- .../adapter/build-url-mixin-test.js | 3 +- .../adapter/client-side-delete-test.js | 3 +- .../integration/adapter/find-all-test.js | 10 +- .../tests/integration/adapter/find-test.js | 13 +- .../adapter/json-api-adapter-test.js | 3 +- .../tests/integration/adapter/queries-test.js | 7 +- .../adapter/record-persistence-test.js | 24 +-- .../integration/adapter/rest-adapter-test.js | 31 ++-- .../adapter/rest-adapter/-ajax-mocks.js | 8 +- .../integration/adapter/store-adapter-test.js | 142 +++++++++--------- .../integration/client-id-generation-test.js | 7 +- .../identifiers/configuration-test.ts | 18 +-- .../identifiers/lid-reflection-test.ts | 6 +- .../identifiers/polymorphic-scenarios-test.ts | 7 +- .../identifiers/record-identifier-for-test.ts | 3 +- .../integration/identifiers/scenarios-test.ts | 14 +- .../tests/integration/record-array-test.js | 9 +- .../adapter-populated-record-array-test.js | 1 - .../record-data/record-data-errors-test.ts | 1 - .../record-data/record-data-state-test.ts | 1 - .../records/collection-save-test.js | 13 +- .../integration/records/create-record-test.js | 3 +- .../integration/records/delete-record-test.js | 17 +-- .../tests/integration/records/error-test.js | 3 +- .../tests/integration/records/load-test.js | 9 +- .../records/property-changes-test.js | 3 +- .../tests/integration/records/reload-test.js | 31 ++-- .../integration/references/belongs-to-test.js | 15 +- .../integration/references/record-test.js | 8 +- .../inverse-relationship-load-test.js | 67 ++++----- .../relationships/json-api-links-test.js | 51 +++---- .../relationships/relationship-links-test.js | 9 +- .../relationships/reload-error-test.js | 3 +- .../integration/request-state-service-test.ts | 1 - tests/main/tests/integration/snapshot-test.js | 9 +- .../store/json-api-validation-test.js | 11 +- .../integration/store/query-record-test.js | 7 +- tests/main/tests/test-helper.js | 13 -- .../group-records-for-find-many-test.js | 5 +- tests/main/tests/unit/many-array-test.js | 3 +- tests/main/tests/unit/model-test.js | 17 +-- tests/main/tests/unit/promise-proxies-test.js | 13 +- .../adapter-populated-record-array-test.js | 4 +- .../unit/record-arrays/record-array-test.js | 6 +- 56 files changed, 336 insertions(+), 430 deletions(-) diff --git a/tests/adapter-encapsulation/tests/integration/belongs-to-test.js b/tests/adapter-encapsulation/tests/integration/belongs-to-test.js index 64c0bfcf90e..e49f1d3d634 100644 --- a/tests/adapter-encapsulation/tests/integration/belongs-to-test.js +++ b/tests/adapter-encapsulation/tests/integration/belongs-to-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import Store from 'adapter-encapsulation-test-app/services/store'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -165,7 +164,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'comment', 'snapshot is passed to findBelongsTo with correct modelName'); assert.strictEqual(snapshot.id, '3', 'snapshot is passed to findBelongsTo with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -276,7 +275,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'post', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, '2', 'snapshot is passed to findRecord with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } findBelongsTo() { @@ -355,7 +354,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'post', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, '2', 'snapshot is passed to findRecord with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -439,7 +438,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'comment', 'snapshot is passed to findBelongsTo with correct modelName'); assert.strictEqual(snapshot.id, '3', 'snapshot is passed to findBelongsTo with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -514,7 +513,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'post', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, '2', 'snapshot is passed to findRecord with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } diff --git a/tests/adapter-encapsulation/tests/integration/coalescing-test.js b/tests/adapter-encapsulation/tests/integration/coalescing-test.js index c39030f832c..7a4ee0b1ea0 100644 --- a/tests/adapter-encapsulation/tests/integration/coalescing-test.js +++ b/tests/adapter-encapsulation/tests/integration/coalescing-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import Store from 'adapter-encapsulation-test-app/services/store'; import { module, test } from 'qunit'; -import { all, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -90,14 +89,14 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, expectedId, 'snapshot is passed to findRecord with correct id'); - return resolve(expectedResultsCopy[findRecordCalled++]); + return Promise.resolve(expectedResultsCopy[findRecordCalled++]); } } owner.register('adapter:application', TestFindRecordAdapter); let promises = expectedResults.map((result) => result.data.id).map((id) => store.findRecord('person', id)); - let records = await all(promises); + let records = await Promise.all(promises); let serializedRecords = records.map((record) => record.serialize()); @@ -160,7 +159,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.strictEqual(snapshot.id, expectedIds[index], 'snapshot is passed to findMany with correct id'); }); - return resolve(expectedResultsCopy); + return Promise.resolve(expectedResultsCopy); } groupRecordsForFindMany(store, snapshots) { @@ -172,7 +171,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); let promises = expectedResults.data.map((result) => result.id).map((id) => store.findRecord('person', id)); - let records = await all(promises); + let records = await Promise.all(promises); let serializedRecords = records.slice().map((record) => record.serialize()); expectedResults = expectedResults.data.map((result) => ({ data: result })); @@ -247,7 +246,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { store.findRecord('person', '2', { include: 'users' }), // de-duped store.findRecord('person', '2', { include: 'users.foo' }), // de-duped ]; - let records = await all(promises); + let records = await Promise.all(promises); let foundIdentifiers = records.map((record) => recordIdentifierFor(record)); let expectedIdentifiers = [ person1, @@ -350,7 +349,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.strictEqual(snapshot.id, expectedIds[index], 'snapshot is passed to findMany with correct id'); }); - return resolve(expectedResults); + return Promise.resolve(expectedResults); } groupRecordsForFindMany(_store, snapshots) { @@ -371,7 +370,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { store.findRecord('person', '3', { include: 'users.foo', adapterOptions: { opt: '1' } }), store.findRecord('person', '4', { include: ['comments'], adapterOptions: { opt: '2' } }), ]; - let records = await all(promises); + let records = await Promise.all(promises); let foundIdentifiers = records.map((record) => recordIdentifierFor(record)); let expectedIdentifiers = [person1, person2, person3, person4]; expectedResults = expectedResults.data.map((result) => ({ data: result })); @@ -441,14 +440,14 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.strictEqual(snapshot.id, expectedIds[index], 'snapshot is passed to findMany with correct id'); }); - return resolve(expectedResultsCopy); + return Promise.resolve(expectedResultsCopy); } } owner.register('adapter:application', TestFindRecordAdapter); let promises = expectedResults.data.map((result) => result.id).map((id) => store.findRecord('person', id)); - let records = await all(promises); + let records = await Promise.all(promises); let serializedRecords = records.slice().map((record) => record.serialize()); expectedResults = expectedResults.data.map((result) => ({ data: result })); @@ -507,7 +506,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, expectedId, 'snapshot is passed to findRecord with correct id'); - return resolve(expectedResultsCopy[findRecordCalled++]); + return Promise.resolve(expectedResultsCopy[findRecordCalled++]); } findMany() { @@ -523,7 +522,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); let promises = expectedResults.map((result) => result.data.id).map((id) => store.findRecord('person', id)); - let records = await all(promises); + let records = await Promise.all(promises); let serializedRecords = records.map((record) => record.serialize()); @@ -600,7 +599,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { const request8 = store.findRecord('person', '1', options[7]); const request9 = store.findRecord('person', '1', options[8]); - await all([request, request2, request3, request4, request5, request6, request7, request8, request9]); + await Promise.all([request, request2, request3, request4, request5, request6, request7, request8, request9]); assert.strictEqual(store.peekAll('person').length, 1, 'only one record is in the store'); @@ -674,7 +673,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { const request8 = store.findRecord('person', '1', options[7]); const request9 = store.findRecord('person', '1', options[8]); - await all([request, request2, request3, request4, request5, request6, request7, request8, request9]); + await Promise.all([request, request2, request3, request4, request5, request6, request7, request8, request9]); assert.strictEqual(store.peekAll('person').length, 1, 'only one record is in the store'); @@ -745,7 +744,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { const request8 = store.findRecord('person', '1', options[7]); const request9 = store.findRecord('person', '1', options[8]); - await all([request, request2, request3, request4, request5, request6, request7, request8, request9]); + await Promise.all([request, request2, request3, request4, request5, request6, request7, request8, request9]); assert.strictEqual(store.peekAll('person').length, 1, 'only one record is in the store'); diff --git a/tests/adapter-encapsulation/tests/integration/has-many-test.js b/tests/adapter-encapsulation/tests/integration/has-many-test.js index 0829e788a2c..937aec892c1 100644 --- a/tests/adapter-encapsulation/tests/integration/has-many-test.js +++ b/tests/adapter-encapsulation/tests/integration/has-many-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import Store from 'adapter-encapsulation-test-app/services/store'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -185,7 +184,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'post', 'snapshot is passed to findHasMany with correct modelName'); assert.strictEqual(snapshot.id, '2', 'snapshot is passed to findHasMany with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -287,7 +286,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'comment', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, expectedId, 'snapshot is passed to findRecord with correct id'); - return resolve({ data: expectedResultCopy.data[index] }); + return Promise.resolve({ data: expectedResultCopy.data[index] }); } findMany() { @@ -363,7 +362,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'comment', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, expectedId, 'snapshot is passed to findRecord with correct id'); - return resolve({ data: expectedResultCopy.data[index] }); + return Promise.resolve({ data: expectedResultCopy.data[index] }); } findMany() { @@ -450,7 +449,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.id, expectedIds[index], 'snapshot is passed to findMany with correct id'); }); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -529,7 +528,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.id, expectedIds[index], 'snapshot is passed to findMany with correct id'); }); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -607,7 +606,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'post', 'snapshot is passed to findHasMany with correct modelName'); assert.strictEqual(snapshot.id, '2', 'snapshot is passed to findHasMany with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -690,7 +689,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.id, expectedIds[index], 'snapshot is passed to findMany with correct id'); }); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -757,7 +756,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'comment', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, expectedId, 'snapshot is passed to findRecord with correct id'); - return resolve({ data: expectedResultCopy.data[index] }); + return Promise.resolve({ data: expectedResultCopy.data[index] }); } findMany() { diff --git a/tests/adapter-encapsulation/tests/integration/mutations-test.js b/tests/adapter-encapsulation/tests/integration/mutations-test.js index c403f8f6cfc..5bd7b3d3aeb 100644 --- a/tests/adapter-encapsulation/tests/integration/mutations-test.js +++ b/tests/adapter-encapsulation/tests/integration/mutations-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import Store from 'adapter-encapsulation-test-app/services/store'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -110,7 +109,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to deleteRecord with correct modelName'); assert.deepEqual(data, expectedData, 'snapshot is passed to deleteRecord with correct data'); - return resolve(data); + return Promise.resolve(data); } deleteRecord(passedStore, type, snapshot) { @@ -207,7 +206,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to deleteRecord with correct modelName'); assert.deepEqual(data, expectedData, 'snapshot is passed to deleteRecord with correct data'); - return resolve(data); + return Promise.resolve(data); } } @@ -249,7 +248,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to deleteRecord with correct modelName'); assert.deepEqual(data, expectedData, 'snapshot is passed to deleteRecord with correct data'); - return resolve(data); + return Promise.resolve(data); } updateRecord(passedStore, type, snapshot) { @@ -265,7 +264,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to deleteRecord with correct modelName'); assert.deepEqual(data, expectedData, 'snapshot is passed to deleteRecord with correct data'); - return resolve(expectedData); + return Promise.resolve(expectedData); } } @@ -318,7 +317,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to deleteRecord with correct modelName'); assert.deepEqual(data, expectedData, 'snapshot is passed to deleteRecord with correct data'); - return resolve(expectedData); + return Promise.resolve(expectedData); } } diff --git a/tests/adapter-encapsulation/tests/integration/queries-test.js b/tests/adapter-encapsulation/tests/integration/queries-test.js index c644950cda6..29ab11bfa1f 100644 --- a/tests/adapter-encapsulation/tests/integration/queries-test.js +++ b/tests/adapter-encapsulation/tests/integration/queries-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import Store from 'adapter-encapsulation-test-app/services/store'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -66,7 +65,7 @@ module('integration/queries - Queries Tests', function (hooks) { assert.strictEqual(query.initialOption, 'bar', 'query is mutated'); assert.strictEqual(adapterOptions.otherOption, 'baz', 'adapterOptions is mutated'); - return resolve({ + return Promise.resolve({ data: [expectedResult], }); } @@ -80,7 +79,7 @@ module('integration/queries - Queries Tests', function (hooks) { assert.strictEqual(query.initialOption, 'bar', 'query is mutated'); assert.strictEqual(adapterOptions.otherOption, 'baz', 'adapterOptions is mutated'); - return resolve({ + return Promise.resolve({ data: expectedResult, }); } @@ -125,7 +124,7 @@ module('integration/queries - Queries Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to findRecord with correct modelName'); assert.strictEqual(snapshot.id, '12', 'snapshot is passed to findRecord with correct id'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -178,7 +177,7 @@ module('integration/queries - Queries Tests', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'snapshot is passed to findAll with correct modelName'); assert.strictEqual(snapshot.length, 0, 'snapshot is passed to findAll represnts empty array'); - return resolve(expectedResultCopy); + return Promise.resolve(expectedResultCopy); } } @@ -217,7 +216,7 @@ module('integration/queries - Queries Tests', function (hooks) { assert.deepEqual(query, { firstName: 'Gaurav' }, 'query is passed to queryRecord'); assert.deepEqual(options, {}, 'options is passsed to queryRecord'); - return resolve(expectedResult); + return Promise.resolve(expectedResult); } } @@ -264,7 +263,7 @@ module('integration/queries - Queries Tests', function (hooks) { assert.deepEqual(recordArray.slice(), [], 'recordArray is passsed to query'); assert.deepEqual(options, {}, 'options is passed to query'); - return resolve(expectedResult); + return Promise.resolve(expectedResult); } } diff --git a/tests/adapter-encapsulation/tests/integration/reload-test.js b/tests/adapter-encapsulation/tests/integration/reload-test.js index 3804c7d2b7d..31cd95c89b4 100644 --- a/tests/adapter-encapsulation/tests/integration/reload-test.js +++ b/tests/adapter-encapsulation/tests/integration/reload-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import Store from 'adapter-encapsulation-test-app/services/store'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -64,12 +63,12 @@ function setupReloadTest(options) { findAll() { this.requestsMade++; - return resolve(options.resolveFindAllWith || { data: [] }); + return Promise.resolve(options.resolveFindAllWith || { data: [] }); } findRecord() { this.requestsMade++; - return resolve(options.resolveFindRecordWith || { data: null }); + return Promise.resolve(options.resolveFindRecordWith || { data: null }); } } this.owner.register('adapter:application', TestMinimumAdapter); diff --git a/tests/graph/tests/test-helper.js b/tests/graph/tests/test-helper.js index 147cf2a3d4d..58a28decd69 100644 --- a/tests/graph/tests/test-helper.js +++ b/tests/graph/tests/test-helper.js @@ -2,7 +2,6 @@ import { setApplication } from '@ember/test-helpers'; import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; -import RSVP from 'rsvp'; import { start } from 'ember-qunit'; @@ -13,10 +12,6 @@ import customQUnitAdapter from '@ember-data/unpublished-test-infra/test-support/ import Application from '../app'; import config from '../config/environment'; -if (window.Promise === undefined) { - window.Promise = RSVP.Promise; -} - // Handle testing feature flags if (QUnit.urlParams.enableoptionalfeatures) { window.EmberDataENV = { ENABLE_OPTIONAL_FEATURES: true }; @@ -34,18 +29,6 @@ if (window.Testem) { window.Testem.useCustomAdapter(customQUnitAdapter); } -QUnit.begin(function () { - RSVP.configure('onerror', (reason) => { - // only print error messages if they're exceptions; - // otherwise, let a future turn of the event loop - // handle the error. - // TODO kill this off - if (reason && reason instanceof Error) { - throw reason; - } - }); -}); - QUnit.config.testTimeout = 2000; QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', diff --git a/tests/json-api/tests/test-helper.js b/tests/json-api/tests/test-helper.js index 0db5529ddea..22fe78a6ad5 100644 --- a/tests/json-api/tests/test-helper.js +++ b/tests/json-api/tests/test-helper.js @@ -2,7 +2,6 @@ import { setApplication } from '@ember/test-helpers'; import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; -import RSVP from 'rsvp'; import { start } from 'ember-qunit'; @@ -13,10 +12,6 @@ import customQUnitAdapter from '@ember-data/unpublished-test-infra/test-support/ import Application from '../app'; import config from '../config/environment'; -if (window.Promise === undefined) { - window.Promise = RSVP.Promise; -} - // Handle testing feature flags if (QUnit.urlParams.enableoptionalfeatures) { window.EmberDataENV = { ENABLE_OPTIONAL_FEATURES: true }; @@ -34,18 +29,6 @@ if (window.Testem) { window.Testem.useCustomAdapter(customQUnitAdapter); } -QUnit.begin(function () { - RSVP.configure('onerror', (reason) => { - // only print error messages if they're exceptions; - // otherwise, let a future turn of the event loop - // handle the error. - // TODO kill this off - if (reason && reason instanceof Error) { - throw reason; - } - }); -}); - QUnit.dump.maxDepth = 10; QUnit.config.testTimeout = 2000; QUnit.config.urlConfig.push({ diff --git a/tests/main/tests/acceptance/relationships/belongs-to-test.js b/tests/main/tests/acceptance/relationships/belongs-to-test.js index 534c5e2f4d3..6dba0b96ffc 100644 --- a/tests/main/tests/acceptance/relationships/belongs-to-test.js +++ b/tests/main/tests/acceptance/relationships/belongs-to-test.js @@ -1,7 +1,6 @@ import { render, settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { Promise, resolve } from 'rsvp'; import { hbs } from 'ember-cli-htmlbars'; import { render as legacyRender } from 'ember-data/test-support'; @@ -99,7 +98,7 @@ class TestAdapter extends JSONAPIAdapter { } deleteRecord() { - return resolve({ data: null }); + return Promise.resolve({ data: null }); } } diff --git a/tests/main/tests/acceptance/relationships/has-many-test.js b/tests/main/tests/acceptance/relationships/has-many-test.js index eaec1c06b16..e8ee1f718af 100644 --- a/tests/main/tests/acceptance/relationships/has-many-test.js +++ b/tests/main/tests/acceptance/relationships/has-many-test.js @@ -6,7 +6,6 @@ import { click, find, findAll, render, rerender } from '@ember/test-helpers'; import Component from '@glimmer/component'; import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { hbs } from 'ember-cli-htmlbars'; import { render as legacyRender } from 'ember-data/test-support'; @@ -59,13 +58,13 @@ class TestAdapter extends JSONAPIAdapter { if (payload === undefined) { this.assert.ok(false, 'Too many adapter requests have been made!'); - return resolve({ data: null }); + return Promise.resolve({ data: null }); } if (payload instanceof ServerError) { - return reject(payload); + return Promise.reject(payload); } - return resolve(payload); + return Promise.resolve(payload); } // find by link diff --git a/tests/main/tests/acceptance/relationships/tracking-record-state-test.js b/tests/main/tests/acceptance/relationships/tracking-record-state-test.js index 75a5f210a70..bfe9675a439 100644 --- a/tests/main/tests/acceptance/relationships/tracking-record-state-test.js +++ b/tests/main/tests/acceptance/relationships/tracking-record-state-test.js @@ -5,7 +5,6 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { hbs } from 'ember-cli-htmlbars'; import { setupRenderingTest } from 'ember-qunit'; diff --git a/tests/main/tests/acceptance/tracking-model-id-test.js b/tests/main/tests/acceptance/tracking-model-id-test.js index 4f4250cbd1f..19007aa0b40 100644 --- a/tests/main/tests/acceptance/tracking-model-id-test.js +++ b/tests/main/tests/acceptance/tracking-model-id-test.js @@ -2,7 +2,6 @@ import { render, settled } from '@ember/test-helpers'; import Component from '@glimmer/component'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { hbs } from 'ember-cli-htmlbars'; import { setupRenderingTest } from 'ember-qunit'; @@ -42,7 +41,7 @@ let layout = hbs` class TestAdapter extends JSONAPIAdapter { createRecord() { - return resolve({ + return Promise.resolve({ data: { id: '4', type: 'widget', diff --git a/tests/main/tests/integration/adapter/build-url-mixin-test.js b/tests/main/tests/integration/adapter/build-url-mixin-test.js index 565a1c632cb..c6beafab3f7 100644 --- a/tests/main/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/main/tests/integration/adapter/build-url-mixin-test.js @@ -1,7 +1,6 @@ import { decamelize, underscore } from '@ember/string'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { pluralize } from 'ember-inflector'; import { setupTest } from 'ember-qunit'; @@ -20,7 +19,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f adapter.ajax = function (url, verb, hash) { passedUrl = url; - return resolve(deepCopy(value)); + return Promise.resolve(deepCopy(value)); }; } diff --git a/tests/main/tests/integration/adapter/client-side-delete-test.js b/tests/main/tests/integration/adapter/client-side-delete-test.js index ed43c66889b..ceeb642300b 100644 --- a/tests/main/tests/integration/adapter/client-side-delete-test.js +++ b/tests/main/tests/integration/adapter/client-side-delete-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -32,7 +31,7 @@ module('integration/adapter/store-adapter - client-side delete', function (hooks adapter.deleteRecord = function (_store, _modelClass, snapshot) { if (snapshot.adapterOptions.clientSideDelete) { - return resolve(); + return Promise.resolve(); } assert.ok(false, 'unreachable'); diff --git a/tests/main/tests/integration/adapter/find-all-test.js b/tests/main/tests/integration/adapter/find-all-test.js index 6674a1606fd..a298da7c6ca 100644 --- a/tests/main/tests/integration/adapter/find-all-test.js +++ b/tests/main/tests/integration/adapter/find-all-test.js @@ -1,7 +1,7 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { defer, reject, resolve } from 'rsvp'; +import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -44,7 +44,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function // this will get called twice assert.ok(true, "the adapter's findAll method should be invoked"); - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -80,9 +80,9 @@ module('integration/adapter/find-all - Finding All Records of a Type', function assert.ok(true, "the adapter's findAll method should be invoked"); if (count++ === 0) { - return reject(); + return Promise.reject(); } else { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -148,7 +148,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function testInDebug('When all records are requested, assert the payload is not blank', async function (assert) { let adapter = store.adapterFor('person'); - adapter.findAll = () => resolve({}); + adapter.findAll = () => Promise.resolve({}); assert.expectAssertion( () => store.findAll('person'), diff --git a/tests/main/tests/integration/adapter/find-test.js b/tests/main/tests/integration/adapter/find-test.js index ec71c2b15f6..f5431c76539 100644 --- a/tests/main/tests/integration/adapter/find-test.js +++ b/tests/main/tests/integration/adapter/find-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { all, allSettled, Promise, reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -98,7 +97,7 @@ module('integration/adapter - Finding Records', function (hooks) { }, }); - await allSettled([firstPlayerRequest, secondPlayerRequest]); + await Promise.allSettled([firstPlayerRequest, secondPlayerRequest]); }); test('When a single record is requested, and the promise is rejected, .findRecord() is rejected.', async function (assert) { @@ -113,7 +112,7 @@ module('integration/adapter - Finding Records', function (hooks) { 'adapter:person', Adapter.extend({ findRecord() { - return reject(); + return Promise.reject(); }, }) ); @@ -140,7 +139,7 @@ module('integration/adapter - Finding Records', function (hooks) { 'adapter:person', Adapter.extend({ findRecord() { - return reject(); + return Promise.reject(); }, }) ); @@ -167,7 +166,7 @@ module('integration/adapter - Finding Records', function (hooks) { this.owner.register( 'adapter:person', Adapter.extend({ - findRecord: () => resolve({}), + findRecord: () => Promise.resolve({}), }) ); @@ -196,7 +195,7 @@ module('integration/adapter - Finding Records', function (hooks) { 'adapter:person', Adapter.extend({ coalesceFindRequests: true, - findMany: () => resolve({}), + findMany: () => Promise.resolve({}), }) ); @@ -204,7 +203,7 @@ module('integration/adapter - Finding Records', function (hooks) { const promises = [store.findRecord('person', '1'), store.findRecord('person', '2')]; try { - await all(promises); + await Promise.all(promises); } catch (e) { const expectedMessageRegex = "Assertion Failed: You made a 'findMany' request for 'person' records with ids '[1,2]', but the adapter's response did not have any data"; diff --git a/tests/main/tests/integration/adapter/json-api-adapter-test.js b/tests/main/tests/integration/adapter/json-api-adapter-test.js index 6ff354b1eb5..711e51811f3 100644 --- a/tests/main/tests/integration/adapter/json-api-adapter-test.js +++ b/tests/main/tests/integration/adapter/json-api-adapter-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -96,7 +95,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) passedVerb[index] = verb; passedHash[index] = hash; - return resolve(responses[index]); + return Promise.resolve(responses[index]); }; } diff --git a/tests/main/tests/integration/adapter/queries-test.js b/tests/main/tests/integration/adapter/queries-test.js index 7a332cbbecc..e1901195317 100644 --- a/tests/main/tests/integration/adapter/queries-test.js +++ b/tests/main/tests/integration/adapter/queries-test.js @@ -1,7 +1,6 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { Promise as EmberPromise, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -55,7 +54,7 @@ module('integration/adapter/queries - Queries', function (hooks) { adapter.query = function (store, type, query, recordArray) { assert.strictEqual(type, Person, 'the query method is called with the correct type'); - return EmberPromise.resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -95,7 +94,7 @@ module('integration/adapter/queries - Queries', function (hooks) { let adapter = store.adapterFor('application'); adapter.query = function () { - return resolve({ data: [{ id: 'first', type: 'person' }] }); + return Promise.resolve({ data: [{ id: 'first', type: 'person' }] }); }; let personsQuery = await store.query('person', {}); @@ -146,7 +145,7 @@ module('integration/adapter/queries - Queries', function (hooks) { adapter.query = function (store, type, query, recordArray) { assert.strictEqual(type, Person, 'the query method is called with the correct type'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', attributes: { name: 'Peter Wagenet' } }, }); }; diff --git a/tests/main/tests/integration/adapter/record-persistence-test.js b/tests/main/tests/integration/adapter/record-persistence-test.js index d8e39faf316..9d57073e3c6 100644 --- a/tests/main/tests/integration/adapter/record-persistence-test.js +++ b/tests/main/tests/integration/adapter/record-persistence-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import { allSettled, hash, resolve } from 'rsvp'; +import { hash } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -35,7 +35,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.strictEqual(type, Person, "The type of the record is 'Person'"); assert.strictEqual(snapshot.record, tom, 'The record in the snapshot is the correct one'); - return resolve(); + return Promise.resolve(); }; const tom = store.push({ @@ -81,7 +81,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.strictEqual(type, Person, "The type of the record is 'Person'"); assert.strictEqual(snapshot.record, tom, 'The record in the snapshot is the correct one'); - return resolve({ data: { id: '1', type: 'person', attributes: { name: 'Tom Dale' } } }); + return Promise.resolve({ data: { id: '1', type: 'person', attributes: { name: 'Tom Dale' } } }); }; tom = store.createRecord('person', { name: 'Tom Dale' }); @@ -114,7 +114,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( let tom; adapter.createRecord = function (store, type, snapshot) { - return resolve({ data: { id: '1', type: 'person', attributes: { name: 'Tom Dale' } } }); + return Promise.resolve({ data: { id: '1', type: 'person', attributes: { name: 'Tom Dale' } } }); }; tom = store.createRecord('person', { name: 'Tom Dale' }); @@ -149,7 +149,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.strictEqual(type, Person, "The type of the record is 'Person'"); assert.strictEqual(snapshot.record, tom, 'The record in the snapshot is the correct one'); - return resolve(); + return Promise.resolve(); }; store.push({ @@ -193,7 +193,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( adapter.updateRecord = function (_store, _type, snapshot) { if (snapshot.id === '1') { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', @@ -205,7 +205,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( }); } - return resolve({ + return Promise.resolve({ data: { id: '2', type: 'person', @@ -244,7 +244,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.true(tom.hasDirtyAttributes, 'Tom is dirty'); assert.true(yehuda.hasDirtyAttributes, 'Yehuda is dirty'); - let [{ value: savedTom }, { value: savedYehuda }] = await allSettled([tom.save(), yehuda.save()]); + let [{ value: savedTom }, { value: savedYehuda }] = await Promise.allSettled([tom.save(), yehuda.save()]); assert.strictEqual(savedTom, tom, 'The record is correct'); assert.strictEqual(savedYehuda, yehuda, 'The record is correct'); @@ -288,7 +288,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); - adapter.deleteRecord = () => resolve(); + adapter.deleteRecord = () => Promise.resolve(); store.push({ data: [ @@ -317,8 +317,8 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.false(tom.isDeleted, 'Tom is not deleted'); assert.false(yehuda.isDeleted, 'Yehuda is not deleted'); - await allSettled([tom.deleteRecord(), yehuda.deleteRecord()]); - await allSettled([tom.save(), yehuda.save()]); + await Promise.allSettled([tom.deleteRecord(), yehuda.deleteRecord()]); + await Promise.allSettled([tom.save(), yehuda.save()]); assert.true(tom.isDeleted, 'Tom is marked as deleted'); assert.true(yehuda.isDeleted, 'Yehuda is marked as deleted'); @@ -359,7 +359,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.strictEqual(type, Person, "The type of the record is 'Person'"); assert.strictEqual(snapshot.record, tom, 'The record in the snapshot is the correct one'); - return resolve({ data: { id: '1' } }); + return Promise.resolve({ data: { id: '1' } }); }; tom = store.createRecord('person', { name: 'Tom Dale' }); diff --git a/tests/main/tests/integration/adapter/rest-adapter-test.js b/tests/main/tests/integration/adapter/rest-adapter-test.js index d22257aa8a1..18e8a87ec03 100644 --- a/tests/main/tests/integration/adapter/rest-adapter-test.js +++ b/tests/main/tests/integration/adapter/rest-adapter-test.js @@ -3,7 +3,6 @@ import { underscore } from '@ember/string'; import Pretender from 'pretender'; import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { singularize } from 'ember-inflector'; import { setupTest } from 'ember-qunit'; @@ -61,9 +60,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { passedHash = hash; passedUrl = passedHash.url; passedVerb = passedHash.method; - return resolve({ + return Promise.resolve({ text() { - return resolve(JSON.stringify(deepCopy(value))); + return Promise.resolve(JSON.stringify(deepCopy(value))); }, ok: true, status: 200, @@ -75,15 +74,15 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { passedVerb = verb; passedHash = hash; - return resolve(deepCopy(value)); + return Promise.resolve(deepCopy(value)); }; } function ajaxError(responseText, status = 400, headers = {}) { adapter._fetchRequest = () => { - return resolve({ + return Promise.resolve({ text() { - return resolve(responseText); + return Promise.resolve(responseText); }, ok: false, status, @@ -109,9 +108,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { function ajaxZero() { adapter._fetchRequest = () => { - return resolve({ + return Promise.resolve({ text() { - return resolve(); + return Promise.resolve(); }, ok: false, status: 0, @@ -2120,12 +2119,12 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(id, '1'); - return resolve({ comments: { id: '1' } }); + return Promise.resolve({ comments: { id: '1' } }); }; adapter.findMany = function (store, type, ids, snapshots) { assert.deepEqual(ids, ['2', '3']); - return resolve({ comments: [{ id: '2' }, { id: '3' }] }); + return Promise.resolve({ comments: [{ id: '2' }, { id: '3' }] }); }; store.push({ @@ -2172,12 +2171,12 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(id, '1'); - return resolve({ comments: { id: '1' } }); + return Promise.resolve({ comments: { id: '1' } }); }; adapter.findMany = function (store, type, ids, snapshots) { assert.deepEqual(ids, ['2', '3']); - return resolve({ comments: [{ id: '2' }, { id: '3' }] }); + return Promise.resolve({ comments: [{ id: '2' }, { id: '3' }] }); }; store.push({ @@ -2325,12 +2324,12 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.ok(true, 'Found ' + id); } - return resolve({ comments: { id: id } }); + return Promise.resolve({ comments: { id: id } }); }; adapter.findMany = function (store, type, ids, snapshots) { assert.ok(false, 'findMany should not be called - we expect 2 calls to find for a2000 and b2000'); - return reject(); + return Promise.reject(); }; post.comments; @@ -2379,12 +2378,12 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { adapter.findRecord = function (store, type, id, snapshot) { assert.ok(false, 'findRecord should not be called - we expect 1 call to findMany for a100 and b100'); - return reject(); + return Promise.reject(); }; adapter.findMany = function (store, type, ids, snapshots) { assert.deepEqual(ids, [a100, b100]); - return resolve({ comments: [{ id: a100 }, { id: b100 }] }); + return Promise.resolve({ comments: [{ id: a100 }, { id: b100 }] }); }; await post.comments; diff --git a/tests/main/tests/integration/adapter/rest-adapter/-ajax-mocks.js b/tests/main/tests/integration/adapter/rest-adapter/-ajax-mocks.js index 8eddebea5e0..3565eaf9215 100644 --- a/tests/main/tests/integration/adapter/rest-adapter/-ajax-mocks.js +++ b/tests/main/tests/integration/adapter/rest-adapter/-ajax-mocks.js @@ -1,5 +1,3 @@ -import { resolve } from 'rsvp'; - import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy'; /** @@ -19,9 +17,9 @@ function ajaxResponse(adapter, value) { passedHash = hash; passedUrl = passedHash.url; passedVerb = passedHash.method; - return resolve({ + return Promise.resolve({ text() { - return resolve(JSON.stringify(deepCopy(value))); + return Promise.resolve(JSON.stringify(deepCopy(value))); }, ok: true, status: 200, @@ -33,7 +31,7 @@ function ajaxResponse(adapter, value) { passedVerb = verb; passedHash = hash; - return resolve(deepCopy(value)); + return Promise.resolve(deepCopy(value)); }; return () => { diff --git a/tests/main/tests/integration/adapter/store-adapter-test.js b/tests/main/tests/integration/adapter/store-adapter-test.js index e5ca30b6a85..d5d1a947cbd 100644 --- a/tests/main/tests/integration/adapter/store-adapter-test.js +++ b/tests/main/tests/integration/adapter/store-adapter-test.js @@ -1,7 +1,7 @@ import { get, set } from '@ember/object'; import { module, test } from 'qunit'; -import { hash, Promise as EmberPromise, reject, resolve } from 'rsvp'; +import { hash } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -50,7 +50,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration let adapter = store.adapterFor('application'); adapter.query = function (store, type, query, recordArray) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -105,7 +105,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration hash['updated-at'] = 'now'; count++; - return resolve({ + return Promise.resolve({ data: { id: recordId, type: 'person', @@ -162,7 +162,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.true(snapshot.record.isSaving, 'record is saving'); - return resolve(); + return Promise.resolve(); }; store.push({ @@ -224,12 +224,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration count++; if (count === 1) { assert.strictEqual(snapshot.attr('name'), 'Tom Dale'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', attributes: { name: 'Tom Dale', 'updated-at': 'now' } }, }); } else if (count === 2) { assert.strictEqual(snapshot.attr('name'), 'Yehuda Katz'); - return resolve({ + return Promise.resolve({ data: { id: '2', type: 'person', @@ -297,7 +297,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration count++; - return resolve(); + return Promise.resolve(); }; store.push({ @@ -331,7 +331,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration tom.deleteRecord(); yehuda.deleteRecord(); - return EmberPromise.all([tom.save(), yehuda.save()]); + return Promise.all([tom.save(), yehuda.save()]); }); test('by default, destroyRecord calls deleteRecord once per record without requiring .save', async function (assert) { @@ -357,7 +357,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration count++; - return resolve(); + return Promise.resolve(); }; store.push({ @@ -388,7 +388,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration let tom = records.tom; let yehuda = records.yehuda; - return EmberPromise.all([tom.destroyRecord(), yehuda.destroyRecord()]); + return Promise.all([tom.destroyRecord(), yehuda.destroyRecord()]); }); test('if an existing model is edited then deleted, deleteRecord is called on the adapter', async function (assert) { @@ -404,7 +404,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.strictEqual(snapshot.id, 'deleted-record', 'should pass correct record to deleteRecord'); assert.strictEqual(count, 1, 'should only call deleteRecord method of adapter once'); - return resolve(); + return Promise.resolve(); }; adapter.updateRecord = function () { @@ -444,9 +444,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function (store, type, snapshot) { if (count++ === 0) { - return reject(error); + return Promise.reject(error); } else { - return resolve(); + return Promise.resolve(); } }; @@ -486,7 +486,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.strictEqual(type, Person, 'the type is correct'); if (snapshot.attr('name').indexOf('Bro') === -1) { - return reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -498,7 +498,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ]) ); } else { - return resolve(); + return Promise.resolve(); } }; @@ -538,7 +538,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.createRecord = function (store, type, snapshot) { if (snapshot.attr('name').indexOf('Bro') === -1) { - return reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -550,7 +550,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ]) ); } else { - return resolve(); + return Promise.resolve(); } }; @@ -597,7 +597,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration saveCount++; if (snapshot.attr('name').indexOf('Bro') === -1) { - return reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -609,7 +609,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ]) ); } else { - return resolve(); + return Promise.resolve(); } }; @@ -659,7 +659,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration let error = new AdapterError(); adapter.createRecord = function (store, type, snapshot) { - return reject(error); + return Promise.reject(error); }; let person = store.createRecord('person', { id: '1', name: 'John Doe' }); @@ -680,7 +680,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.strictEqual(type, Person, 'the type is correct'); if (snapshot.attr('name').indexOf('Bro') === -1) { - return reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -692,7 +692,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ]) ); } else { - return resolve(); + return Promise.resolve(); } }; @@ -742,7 +742,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function (store, type, snapshot) { if (snapshot.attr('name').indexOf('Bro') === -1) { - return reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -754,7 +754,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ]) ); } else { - return resolve(); + return Promise.resolve(); } }; @@ -817,7 +817,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.strictEqual(type, Person, 'the type is correct'); saveCount++; if (snapshot.attr('name').indexOf('Bro') === -1) { - return reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -829,7 +829,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ]) ); } else { - return resolve(); + return Promise.resolve(); } }; @@ -891,7 +891,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function (store, type, snapshot) { - return reject(error); + return Promise.reject(error); }; let person = store.push({ @@ -925,7 +925,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(type, Person, 'the type is correct'); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; await store.findRecord('person', '1'); @@ -954,7 +954,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', @@ -969,36 +969,34 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }; adapter.updateRecord = function (store, type, snapshot) { - return new EmberPromise((resolve, reject) => { - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, - relationships: { - dogs: { - data: [ - { type: 'dog', id: '1' }, - { type: 'dog', id: '2' }, - ], - }, + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', + }, + relationships: { + dogs: { + data: [ + { type: 'dog', id: '1' }, + { type: 'dog', id: '2' }, + ], }, }, - included: [ - { - type: 'dog', - id: '2', - attributes: { - name: 'Scruffles', - }, + }, + included: [ + { + type: 'dog', + id: '2', + attributes: { + name: 'Scruffles', }, - ], - }); - - resolve({ data: { id: '1', type: 'dog', attributes: { name: 'Scruffy' } } }); + }, + ], }); + + return Promise.resolve({ data: { id: '1', type: 'dog', attributes: { name: 'Scruffy' } } }); }; adapter.findMany = function (store, type, ids, snapshots) { @@ -1029,7 +1027,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findHasMany = function (store, snapshot, link, relationship) { assert.strictEqual(count++, 0, 'findHasMany is only called once'); - return resolve({ data: [{ id: '1', type: 'dog', attributes: { name: 'Scruffy' } }] }); + return Promise.resolve({ data: [{ id: '1', type: 'dog', attributes: { name: 'Scruffy' } }] }); }; store.push({ @@ -1088,7 +1086,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration this.owner.register('model:person', Person); adapter.createRecord = function (store, type, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', @@ -1118,7 +1116,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.createRecord = function (store, type, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); - return resolve(); + return Promise.resolve(); }; let record = store.createRecord('person', { name: 'Tom Dale', id: '1' }); @@ -1134,7 +1132,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.updateRecord = function (store, type, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); - return resolve(); + return Promise.resolve(); }; let person; @@ -1162,7 +1160,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.deleteRecord = function (store, type, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); - return resolve(); + return Promise.resolve(); }; let person; @@ -1190,7 +1188,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findRecord = function (store, type, id, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; await store.findRecord('person', '1'); @@ -1211,7 +1209,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findMany = function (store, type, ids, snapshots) { assert.ok(snapshots[0] instanceof Snapshot, 'snapshots[0] is an instance of Snapshot'); assert.ok(snapshots[1] instanceof Snapshot, 'snapshots[1] is an instance of Snapshot'); - return resolve({ + return Promise.resolve({ data: [ { id: '2', type: 'dog' }, { id: '3', type: 'dog' }, @@ -1253,7 +1251,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findHasMany = function (store, snapshot, link, relationship) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); - return resolve({ + return Promise.resolve({ data: [ { id: '2', type: 'dog' }, { id: '3', type: 'dog' }, @@ -1295,7 +1293,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findBelongsTo = function (store, snapshot, link, relationship) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); - return resolve({ data: { id: '2', type: 'dog' } }); + return Promise.resolve({ data: { id: '2', type: 'dog' } }); }; let person; @@ -1326,7 +1324,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.updateRecord = function (store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; store.push({ @@ -1350,7 +1348,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.createRecord = function (store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; await store.createRecord('person', { name: 'Tom' }).save({ adapterOptions: { subscribe: true } }); @@ -1364,7 +1362,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.deleteRecord = function (store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; store.push({ @@ -1388,7 +1386,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findRecord = function (store, type, id, snapshot) { assert.deepEqual(snapshot.adapterOptions, { query: { embed: true } }); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; await store.findRecord('person', '1', { adapterOptions: { query: { embed: true } } }); @@ -1432,7 +1430,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findRecord = (store, type, id, snapshot) => { assert.strictEqual(snapshot.include, 'books', 'include passed to adapter.findRecord'); - return resolve({ data: { id: '1', type: 'person' } }); + return Promise.resolve({ data: { id: '1', type: 'person' } }); }; await store.findRecord('person', '1', { include: 'books' }); @@ -1447,7 +1445,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findAll = function (store, type, sinceToken, arraySnapshot) { let adapterOptions = arraySnapshot.adapterOptions; assert.deepEqual(adapterOptions, { query: { embed: true } }); - return resolve({ data: [{ id: '1', type: 'person' }] }); + return Promise.resolve({ data: [{ id: '1', type: 'person' }] }); }; await store.findAll('person', { adapterOptions: { query: { embed: true } } }); @@ -1461,7 +1459,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration adapter.findAll = function (store, type, sinceToken, arraySnapshot) { assert.strictEqual(arraySnapshot.include, 'books', 'include passed to adapter.findAll'); - return resolve({ data: [{ id: '1', type: 'person' }] }); + return Promise.resolve({ data: [{ id: '1', type: 'person' }] }); }; await store.findAll('person', { include: 'books' }); @@ -1488,7 +1486,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }; } findHasMany() { - return resolve({ + return Promise.resolve({ comments: [ { id: '1', name: 'FIRST' }, { id: '2', name: 'Rails is unagi' }, diff --git a/tests/main/tests/integration/client-id-generation-test.js b/tests/main/tests/integration/client-id-generation-test.js index 9efd55a8cff..3f85cdf9dc2 100644 --- a/tests/main/tests/integration/client-id-generation-test.js +++ b/tests/main/tests/integration/client-id-generation-test.js @@ -1,7 +1,6 @@ import { get } from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -61,7 +60,7 @@ module('integration - Client Id Generation', function (hooks) { if (type === 'comment') { assert.strictEqual(snapshot.id, 'id-1', "Comment passed to `createRecord` has 'id-1' assigned"); - return resolve({ + return Promise.resolve({ data: { type, id: snapshot.id, @@ -69,7 +68,7 @@ module('integration - Client Id Generation', function (hooks) { }); } else { assert.strictEqual(snapshot.id, 'id-2', "Post passed to `createRecord` has 'id-2' assigned"); - return resolve({ + return Promise.resolve({ data: { type, id: snapshot.id, @@ -111,7 +110,7 @@ module('integration - Client Id Generation', function (hooks) { adapter.createRecord = function (store, type, record) { assert.strictEqual(typeof get(record, 'id'), 'object', 'correct type'); - return resolve({ data: { id: id++, type: type.modelName } }); + return Promise.resolve({ data: { id: id++, type: type.modelName } }); }; let comment = store.createRecord('misc'); diff --git a/tests/main/tests/integration/identifiers/configuration-test.ts b/tests/main/tests/integration/identifiers/configuration-test.ts index db508366f8c..ff675b8a8d8 100644 --- a/tests/main/tests/integration/identifiers/configuration-test.ts +++ b/tests/main/tests/integration/identifiers/configuration-test.ts @@ -1,10 +1,7 @@ import EmberObject, { set } from '@ember/object'; -// eslint-disable-next-line no-restricted-imports -import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { all, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -143,7 +140,7 @@ module('Integration | Identifiers - configuration', function (hooks) { } class TestAdapter extends Adapter { createRecord() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'user', @@ -207,7 +204,7 @@ module('Integration | Identifiers - configuration', function (hooks) { } class TestAdapter extends Adapter { createRecord() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'user', @@ -276,7 +273,7 @@ module('Integration | Identifiers - configuration', function (hooks) { } class TestAdapter extends Adapter { updateRecord() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'user', @@ -352,7 +349,8 @@ module('Integration | Identifiers - configuration', function (hooks) { }); const store = new Store(); - run(() => store.destroy()); + store.destroy(); + await settled(); assert.ok(resetMethodCalled, 'We called the reset method when the application was torn down'); }); @@ -364,7 +362,7 @@ module('Integration | Identifiers - configuration', function (hooks) { } class TestAdapter extends Adapter { findRecord() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'user', @@ -430,7 +428,7 @@ module('Integration | Identifiers - configuration', function (hooks) { // we expect that the username based identifier will be abandoned expectedIdentifier = originalUserByUsernameIdentifier; - const [userByUsername, userById] = await all([userByUsernamePromise, userByIdPromise]); + const [userByUsername, userById] = await Promise.all([userByUsernamePromise, userByIdPromise]); const finalUserByUsernameIdentifier = recordIdentifierFor(userByUsername); const finalUserByIdIdentifier = recordIdentifierFor(userById); @@ -470,7 +468,7 @@ module('Integration | Identifiers - configuration', function (hooks) { const adapter = store.adapterFor('application'); adapter.deleteRecord = () => { - return resolve({ + return Promise.resolve({ data: null, }); }; diff --git a/tests/main/tests/integration/identifiers/lid-reflection-test.ts b/tests/main/tests/integration/identifiers/lid-reflection-test.ts index dec8802197c..130c023f820 100644 --- a/tests/main/tests/integration/identifiers/lid-reflection-test.ts +++ b/tests/main/tests/integration/identifiers/lid-reflection-test.ts @@ -1,7 +1,7 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { defer, resolve } from 'rsvp'; +import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -169,7 +169,7 @@ module('Integration | Identifiers - lid reflection', function (hooks: NestedHook const record = snapshot.record as Cake; const cakeLid = recordIdentifierFor(record).lid; const ingredientLid = recordIdentifierFor(record.ingredients.at(0)).lid; - return resolve({ + return Promise.resolve({ data: { type: 'cake', id: '1', @@ -254,7 +254,7 @@ module('Integration | Identifiers - lid reflection', function (hooks: NestedHook createRecord(store, ModelClass, snapshot: Snapshot) { const record = snapshot.record as Cake; const lid = recordIdentifierFor(record.topping).lid; - return resolve({ + return Promise.resolve({ data: { type: 'cake', id: '1', diff --git a/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts b/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts index 7d5f6d5c163..1ab85fc4cac 100644 --- a/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts +++ b/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -72,7 +71,7 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari return false; } findRecord(_, __, id) { - return resolve({ + return Promise.resolve({ data: { id, type: 'ferrari', @@ -110,7 +109,7 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari } findRecord(_, { modelName: type }, id) { if (type === 'dealership') { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'dealership', @@ -134,7 +133,7 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari requests.push({ type, id }); // return the polymorphic type instead of 'car'; type = id === '1' ? 'ferrari' : 'bmw'; - return resolve({ + return Promise.resolve({ data: { id, type, diff --git a/tests/main/tests/integration/identifiers/record-identifier-for-test.ts b/tests/main/tests/integration/identifiers/record-identifier-for-test.ts index 3dd56aa4663..2bae5d91dae 100644 --- a/tests/main/tests/integration/identifiers/record-identifier-for-test.ts +++ b/tests/main/tests/integration/identifiers/record-identifier-for-test.ts @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -37,7 +36,7 @@ module('Integration | Identifiers - recordIdentifierFor', function (hooks) { test(`Saving newly created records updates the associated id on the identifier`, async function (assert) { class TestAdapter extends Adapter { createRecord() { - return resolve({ + return Promise.resolve({ data: { type: 'user', id: '1', diff --git a/tests/main/tests/integration/identifiers/scenarios-test.ts b/tests/main/tests/integration/identifiers/scenarios-test.ts index f75f6929634..98bae8dcfbd 100644 --- a/tests/main/tests/integration/identifiers/scenarios-test.ts +++ b/tests/main/tests/integration/identifiers/scenarios-test.ts @@ -1,7 +1,6 @@ import EmberObject, { set } from '@ember/object'; import { module, test } from 'qunit'; -import { all, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -55,7 +54,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { calls.findRecord++; } isQuery = false; - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'user', @@ -265,7 +264,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { calls.findRecord++; } isQuery = false; - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'user', @@ -457,7 +456,10 @@ module('Integration | Identifiers - scenarios', function (hooks) { const recordByUsernamePromise = store.findRecord('user', '@runspired'); const recordByIdPromise = store.findRecord('user', '1'); - const [recordByUsername, recordById] = (await all([recordByUsernamePromise, recordByIdPromise])) as [User, User]; + const [recordByUsername, recordById] = (await Promise.all([recordByUsernamePromise, recordByIdPromise])) as [ + User, + User, + ]; const identifierByUsername = recordIdentifierFor(recordByUsername); const identifierById = recordIdentifierFor(recordById); @@ -637,7 +639,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { if (hasSaved && id === '@runspired') { throw new Error(`No record found for the username @runspired`); } - return resolve({ + return Promise.resolve({ data: { type: 'user', id: '1', @@ -650,7 +652,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { adapter.updateRecord = () => { hasSaved = true; - return resolve({ + return Promise.resolve({ data: { type: 'user', id: '1', diff --git a/tests/main/tests/integration/record-array-test.js b/tests/main/tests/integration/record-array-test.js index 5aa870de433..b520055f657 100644 --- a/tests/main/tests/integration/record-array-test.js +++ b/tests/main/tests/integration/record-array-test.js @@ -2,7 +2,6 @@ import { get } from '@ember/object'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -126,7 +125,7 @@ module('integration/record-array - RecordArray', function (hooks) { 'adapter:application', Adapter.extend({ deleteRecord() { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }, shouldBackgroundReloadRecord() { return false; @@ -305,7 +304,7 @@ module('integration/record-array - RecordArray', function (hooks) { 'adapter:application', Adapter.extend({ deleteRecord() { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }, }) ); @@ -346,7 +345,7 @@ module('integration/record-array - RecordArray', function (hooks) { 'adapter:application', Adapter.extend({ deleteRecord() { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }, }) ); @@ -502,7 +501,7 @@ module('integration/record-array - RecordArray', function (hooks) { adapter.query = function (store, type, query, recordArray) { assert.false(recordArray.isLoaded, 'not loaded yet'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, diff --git a/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js b/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js index 7774437f55f..9c999b67758 100644 --- a/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js +++ b/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js @@ -1,7 +1,6 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { Promise } from 'rsvp'; import { setupTest } from 'ember-qunit'; diff --git a/tests/main/tests/integration/record-data/record-data-errors-test.ts b/tests/main/tests/integration/record-data/record-data-errors-test.ts index c2517c957d0..a8f969697fc 100644 --- a/tests/main/tests/integration/record-data/record-data-errors-test.ts +++ b/tests/main/tests/integration/record-data/record-data-errors-test.ts @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { Promise } from 'rsvp'; import Store from 'ember-data/store'; import { setupTest } from 'ember-qunit'; diff --git a/tests/main/tests/integration/record-data/record-data-state-test.ts b/tests/main/tests/integration/record-data/record-data-state-test.ts index 937ef51e871..9829740f007 100644 --- a/tests/main/tests/integration/record-data/record-data-state-test.ts +++ b/tests/main/tests/integration/record-data/record-data-state-test.ts @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { Promise } from 'rsvp'; import Store from 'ember-data/store'; import { setupTest } from 'ember-qunit'; diff --git a/tests/main/tests/integration/records/collection-save-test.js b/tests/main/tests/integration/records/collection-save-test.js index c977540b970..c7c95956414 100644 --- a/tests/main/tests/integration/records/collection-save-test.js +++ b/tests/main/tests/integration/records/collection-save-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -34,7 +33,7 @@ module('integration/records/collection_save - Save Collection of Records', funct let posts = store.peekAll('post'); adapter.createRecord = function (store, type, snapshot) { - return resolve({ data: { id: id++, type: 'post' } }); + return Promise.resolve({ data: { id: id++, type: 'post' } }); }; await posts.save().then(() => { @@ -52,7 +51,7 @@ module('integration/records/collection_save - Save Collection of Records', funct let posts = store.peekAll('post'); adapter.createRecord = function (store, type, snapshot) { - return reject(); + return Promise.reject(); }; try { @@ -77,14 +76,14 @@ module('integration/records/collection_save - Save Collection of Records', funct adapter.createRecord = function (store, type, snapshot) { if (count++ === 0) { - return reject(); + return Promise.reject(); } else { - return resolve({ data: { id: id++, type: 'post' } }); + return Promise.resolve({ data: { id: id++, type: 'post' } }); } }; adapter.updateRecord = function (store, type, snapshot) { - return resolve({ data: { id: snapshot.id, type: 'post' } }); + return Promise.resolve({ data: { id: snapshot.id, type: 'post' } }); }; await posts @@ -109,7 +108,7 @@ module('integration/records/collection_save - Save Collection of Records', funct let posts = store.peekAll('post'); adapter.createRecord = function (store, type, snapshot) { - return reject({ title: 'invalid' }); + return Promise.reject({ title: 'invalid' }); }; await posts.save().catch(() => { diff --git a/tests/main/tests/integration/records/create-record-test.js b/tests/main/tests/integration/records/create-record-test.js index e87870d68ad..6d9ae8ff332 100644 --- a/tests/main/tests/integration/records/create-record-test.js +++ b/tests/main/tests/integration/records/create-record-test.js @@ -1,7 +1,6 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -148,7 +147,7 @@ module('Store.createRecord() coverage', function (hooks) { assert.ok(false, 'Adapter should not make any findBelongsTo Requests'); }, createRecord() { - return resolve({ + return Promise.resolve({ data: { type: 'pet', id: '2', diff --git a/tests/main/tests/integration/records/delete-record-test.js b/tests/main/tests/integration/records/delete-record-test.js index b7bf7d8a644..cf8ded55712 100644 --- a/tests/main/tests/integration/records/delete-record-test.js +++ b/tests/main/tests/integration/records/delete-record-test.js @@ -4,7 +4,6 @@ import EmberObject, { get } from '@ember/object'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { all, Promise as EmberPromise } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -56,7 +55,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { let adapter = store.adapterFor('application'); adapter.deleteRecord = function () { - return EmberPromise.resolve(); + return Promise.resolve(); }; store.push({ @@ -106,7 +105,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { let adapter = store.adapterFor('application'); adapter.deleteRecord = function () { - return EmberPromise.resolve(); + return Promise.resolve(); }; store.push({ @@ -157,7 +156,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { let adapter = store.adapterFor('application'); adapter.deleteRecord = function () { - return EmberPromise.resolve(); + return Promise.resolve(); }; store.push({ @@ -201,7 +200,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { let adapter = store.adapterFor('application'); adapter.createRecord = function () { - return EmberPromise.reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -244,7 +243,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }; adapter.createRecord = function () { - return EmberPromise.reject( + return Promise.reject( new InvalidError([ { title: 'Invalid Attribute', @@ -289,7 +288,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { adapter.createRecord = function () { assert.ok(true, 'save operation resolves'); - return EmberPromise.resolve({ + return Promise.resolve({ data: { id: '123', type: 'person', @@ -302,7 +301,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { promises = [adam.destroyRecord(), dave.save()]; - await all(promises); + await Promise.all(promises); }); test('Calling save on a newly created then deleted record should not error', async function (assert) { @@ -395,7 +394,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { let adapter = store.adapterFor('application'); adapter.deleteRecord = function () { - return EmberPromise.resolve(); + return Promise.resolve(); }; // Push the company as a long-lived record that will be referenced by the group diff --git a/tests/main/tests/integration/records/error-test.js b/tests/main/tests/integration/records/error-test.js index 6b5494bfdc7..73389e69f18 100644 --- a/tests/main/tests/integration/records/error-test.js +++ b/tests/main/tests/integration/records/error-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import RSVP from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -198,7 +197,7 @@ module('integration/records/error', function (hooks) { let adapter = store.adapterFor('application'); adapter.createRecord = () => { - return RSVP.reject( + return Promise.reject( new InvalidError([ { detail: 'Must be unique', diff --git a/tests/main/tests/integration/records/load-test.js b/tests/main/tests/integration/records/load-test.js index 3829aa9a83f..ff7f6a99a0d 100644 --- a/tests/main/tests/integration/records/load-test.js +++ b/tests/main/tests/integration/records/load-test.js @@ -2,7 +2,6 @@ import EmberObject from '@ember/object'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -127,7 +126,7 @@ module('integration/load - Loading Records', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ findRecord() { - return reject(); + return Promise.reject(); }, }) ); @@ -142,7 +141,7 @@ module('integration/load - Loading Records', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ findRecord() { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }, }) ); @@ -219,10 +218,10 @@ module('integration/load - Loading Records', function (hooks) { let payload = payloads.shift(); if (payload === undefined) { - return reject(new Error('Invalid Request')); + return Promise.reject(new Error('Invalid Request')); } - return resolve(payload); + return Promise.resolve(payload); }, }) ); diff --git a/tests/main/tests/integration/records/property-changes-test.js b/tests/main/tests/integration/records/property-changes-test.js index e1e8b41dfd6..19f459a04cf 100644 --- a/tests/main/tests/integration/records/property-changes-test.js +++ b/tests/main/tests/integration/records/property-changes-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -106,7 +105,7 @@ module('integration/records/property-changes - Property changes', function (hook let adapter = store.adapterFor('application'); adapter.updateRecord = function (store, type, snapshot) { - return resolve({ data: { id: 'wat', type: 'person', attributes: { 'last-name': 'Katz' } } }); + return Promise.resolve({ data: { id: 'wat', type: 'person', attributes: { 'last-name': 'Katz' } } }); }; store.push({ diff --git a/tests/main/tests/integration/records/reload-test.js b/tests/main/tests/integration/records/reload-test.js index 0282f3721ba..ee6e9f3a10d 100644 --- a/tests/main/tests/integration/records/reload-test.js +++ b/tests/main/tests/integration/records/reload-test.js @@ -1,7 +1,6 @@ import { get } from '@ember/object'; import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -56,7 +55,7 @@ module('integration/reload - Reloading Records', function (hooks) { findRecord(store, type, id, snapshot) { if (count === 0) { count++; - return resolve({ data: { id: id, type: 'person', attributes: { name: 'Tom Dale' } } }); + return Promise.resolve({ data: { id: id, type: 'person', attributes: { name: 'Tom Dale' } } }); } else if (count === 1) { assert.strictEqual( snapshot.adapterOptions, @@ -64,7 +63,7 @@ module('integration/reload - Reloading Records', function (hooks) { 'We passed adapterOptions via reload' ); count++; - return resolve({ + return Promise.resolve({ data: { id: id, type: 'person', attributes: { name: 'Braaaahm Dale' } }, }); } else { @@ -114,9 +113,9 @@ module('integration/reload - Reloading Records', function (hooks) { findRecord() { assert.true(tom.isReloading, 'Tom is reloading'); if (count++ === 0) { - return reject(); + return Promise.reject(); } else { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', attributes: { name: 'Thomas Dale' } }, }); } @@ -165,7 +164,7 @@ module('integration/reload - Reloading Records', function (hooks) { findRecord(store, type, id, snapshot) { assert.ok(true, 'We should call findRecord'); - return resolve(getTomDale()); + return Promise.resolve(getTomDale()); }, }) ); @@ -220,7 +219,7 @@ module('integration/reload - Reloading Records', function (hooks) { findRecord(store, type, id, snapshot) { switch (type.modelName) { case 'person': - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', @@ -236,7 +235,7 @@ module('integration/reload - Reloading Records', function (hooks) { }, }); case 'tag': - return resolve({ data: { id: id, type: 'tag', attributes: { name: tagsById[id] } } }); + return Promise.resolve({ data: { id: id, type: 'tag', attributes: { name: tagsById[id] } } }); } }, }) @@ -283,7 +282,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findRecord() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -340,7 +339,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findRecord() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -388,7 +387,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findRecord() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -445,7 +444,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findRecord() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -495,7 +494,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findBelongsTo() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -555,7 +554,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findBelongsTo() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -606,7 +605,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findHasMany() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: [ { type: 'person', @@ -668,7 +667,7 @@ module('integration/reload - Reloading Records', function (hooks) { JSONAPIAdapter.extend({ findHasMany() { assert.ok('We called findRecord'); - return resolve({ + return Promise.resolve({ data: [ { type: 'person', diff --git a/tests/main/tests/integration/references/belongs-to-test.js b/tests/main/tests/integration/references/belongs-to-test.js index d07b9124911..b608133f8ec 100644 --- a/tests/main/tests/integration/references/belongs-to-test.js +++ b/tests/main/tests/integration/references/belongs-to-test.js @@ -1,7 +1,6 @@ import { get } from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -332,7 +331,7 @@ module('integration/references/belongs-to', function (hooks) { adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'family', @@ -368,7 +367,7 @@ module('integration/references/belongs-to', function (hooks) { adapter.findRecord = function (store, type, id, snapshot) { assert.deepEqual(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'team', @@ -405,7 +404,7 @@ module('integration/references/belongs-to', function (hooks) { assert.strictEqual(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); assert.strictEqual(link, '/families/1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'family', @@ -444,7 +443,7 @@ module('integration/references/belongs-to', function (hooks) { assert.strictEqual(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); assert.strictEqual(link, '/families/1', 'link was passed correctly'); - return resolve({ + return Promise.resolve({ data: null, meta: { it: 'works' }, }); @@ -484,7 +483,7 @@ module('integration/references/belongs-to', function (hooks) { count++; assert.strictEqual(count, 1); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'family', @@ -525,7 +524,7 @@ module('integration/references/belongs-to', function (hooks) { count++; assert.strictEqual(count, 1); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'family', @@ -570,7 +569,7 @@ module('integration/references/belongs-to', function (hooks) { assert.strictEqual(link, '/families/1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'family', diff --git a/tests/main/tests/integration/references/record-test.js b/tests/main/tests/integration/references/record-test.js index c2b864afbf0..edcd6e79edc 100644 --- a/tests/main/tests/integration/references/record-test.js +++ b/tests/main/tests/integration/references/record-test.js @@ -1,7 +1,7 @@ import { get } from '@ember/object'; import { module, test } from 'qunit'; -import { defer, resolve } from 'rsvp'; +import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -157,7 +157,7 @@ module('integration/references/record', function (hooks) { let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', @@ -227,7 +227,7 @@ module('integration/references/record', function (hooks) { count++; assert.strictEqual(count, 1); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', @@ -249,7 +249,7 @@ module('integration/references/record', function (hooks) { let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', diff --git a/tests/main/tests/integration/relationships/inverse-relationship-load-test.js b/tests/main/tests/integration/relationships/inverse-relationship-load-test.js index 30ea6643738..b7e47f7a3be 100644 --- a/tests/main/tests/integration/relationships/inverse-relationship-load-test.js +++ b/tests/main/tests/integration/relationships/inverse-relationship-load-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -30,9 +29,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findHasMany: () => { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -118,9 +117,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findHasMany: () => { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -207,12 +206,12 @@ module('inverse relationship load test', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ deleteRecord() { - return resolve({ + return Promise.resolve({ data: null, }); }, findHasMany: () => { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -290,12 +289,12 @@ module('inverse relationship load test', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ deleteRecord() { - return resolve({ + return Promise.resolve({ data: null, }); }, findBelongsTo() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'dog', @@ -362,12 +361,12 @@ module('inverse relationship load test', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ deleteRecord() { - return resolve({ + return Promise.resolve({ data: null, }); }, findBelongsTo() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'dog', @@ -434,12 +433,12 @@ module('inverse relationship load test', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ deleteRecord() { - return resolve({ + return Promise.resolve({ data: null, }); }, findBelongsTo() { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'dog', @@ -497,9 +496,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findHasMany: () => { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -580,9 +579,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findHasMany: () => { - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -663,9 +662,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findBelongsTo: () => { - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -737,9 +736,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findBelongsTo: () => { - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -827,10 +826,10 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findRecord: (_store, _type, id) => { const dog = id === '1' ? scooby : scrappy; - return resolve({ + return Promise.resolve({ data: dog, }); }, @@ -924,10 +923,10 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findRecord: (_store, _type, id) => { const dog = id === '1' ? scooby : scrappy; - return resolve({ + return Promise.resolve({ data: dog, }); }, @@ -1021,10 +1020,10 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findRecord: (_store, _type, id) => { const dog = id === '1' ? scooby : scrappy; - return resolve({ + return Promise.resolve({ data: dog, }); }, @@ -1116,10 +1115,10 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findRecord: (_store, _type, id) => { const dog = id === '1' ? scooby : scrappy; - return resolve({ + return Promise.resolve({ data: dog, }); }, @@ -1241,10 +1240,10 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findRecord: (_store, _type, id) => { const dog = id === '1' ? scooby : scrappy; - return resolve({ + return Promise.resolve({ data: dog, }); }, @@ -1360,9 +1359,9 @@ module('inverse relationship load test', function (hooks) { owner.register( 'adapter:application', JSONAPIAdapter.extend({ - deleteRecord: () => resolve({ data: null }), + deleteRecord: () => Promise.resolve({ data: null }), findBelongsTo: () => { - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -1381,7 +1380,7 @@ module('inverse relationship load test', function (hooks) { }, findRecord: (_store, _type, id) => { const dog = id === '1' ? scooby : scrappy; - return resolve({ + return Promise.resolve({ data: dog, }); }, diff --git a/tests/main/tests/integration/relationships/json-api-links-test.js b/tests/main/tests/integration/relationships/json-api-links-test.js index cd44c912959..43822d374d8 100644 --- a/tests/main/tests/integration/relationships/json-api-links-test.js +++ b/tests/main/tests/integration/relationships/json-api-links-test.js @@ -1,7 +1,6 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -34,7 +33,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f 'adapter:user', class extends JSONAPISerializer { findRecord(store, type, id) { - return resolve({ + return Promise.resolve({ data: { id, type: 'user', @@ -53,7 +52,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f 'adapter:organisation', class extends JSONAPISerializer { findRecord(store, type, id) { - return resolve({ + return Promise.resolve({ data: { type: 'organisation', id, @@ -155,7 +154,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f }, findRecord(_, __, id) { assert.notStrictEqual(id, '1', `adapter findRecord called for all IDs except "1", called for "${id}"`); - return resolve({ + return Promise.resolve({ data: { type: 'pet', id, @@ -225,7 +224,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f const Adapter = JSONAPIAdapter.extend({ findHasMany(_, __, link) { assert.strictEqual(link, './user/1/pets', 'We fetched via the correct link'); - return resolve({ + return Promise.resolve({ data: [ { type: 'pet', @@ -307,7 +306,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f const Adapter = JSONAPIAdapter.extend({ findHasMany(_, __, link) { assert.strictEqual(link, './user/1/pets', 'We fetched via the correct link'); - return resolve({ + return Promise.resolve({ data: [ { type: 'pet', @@ -391,7 +390,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f const Adapter = JSONAPIAdapter.extend({ findHasMany(_, __, link) { assert.strictEqual(link, './user/1/pets', 'We fetched via the correct link'); - return resolve({ + return Promise.resolve({ data: [ { type: 'pet', @@ -478,7 +477,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f const Adapter = JSONAPIAdapter.extend({ findHasMany(_, __, link) { assert.strictEqual(link, './user/1/pets', 'We fetched via the correct link'); - return resolve({ + return Promise.resolve({ data: [ { type: 'pet', @@ -548,7 +547,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f const Adapter = JSONAPIAdapter.extend({ findHasMany(_, __, link) { assert.strictEqual(link, './user/1/pets', 'We fetched via the correct link'); - return resolve({ + return Promise.resolve({ data: [ { type: 'pet', @@ -691,7 +690,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi payloads.user.data.relationships.pets.links.related, 'We fetched the appropriate link' ); - return resolve(deepCopy(payloads.pets)); + return Promise.resolve(deepCopy(payloads.pets)); }; // setup user @@ -733,7 +732,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi 'We fetched the appropriate link' ); } - return resolve(deepCopy(payloads.pets)); + return Promise.resolve(deepCopy(payloads.pets)); }; // setup user @@ -781,7 +780,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi 'We fetched the appropriate link' ); } - return resolve(deepCopy(payloads.home)); + return Promise.resolve(deepCopy(payloads.home)); }; // setup user @@ -820,7 +819,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi !homeRelWasEmpty && link === payloads.user.data.relationships.home.links.related, 'We fetched the appropriate link' ); - return resolve(deepCopy(payloads.home)); + return Promise.resolve(deepCopy(payloads.home)); }; // setup user @@ -992,7 +991,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi payloads.user.data.relationships.pets.links.related, 'We fetched the appropriate link' ); - return resolve(deepCopy(payloads.pets)); + return Promise.resolve(deepCopy(payloads.pets)); }; // setup user and pets @@ -1024,7 +1023,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi payloads.user.data.relationships.pets.links.related, 'We fetched the appropriate link' ); - return resolve(deepCopy(payloads.pets)); + return Promise.resolve(deepCopy(payloads.pets)); }; // setup user and pets @@ -1059,7 +1058,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi payloads.user.data.relationships.home.links.related, 'We fetched the appropriate link' ); - return resolve(deepCopy(payloads.home)); + return Promise.resolve(deepCopy(payloads.home)); }; // setup user and home @@ -1094,7 +1093,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi payloads.user.data.relationships.home.links.related, 'We fetched the appropriate link' ); - return resolve(deepCopy(payloads.home)); + return Promise.resolve(deepCopy(payloads.home)); }; // setup user @@ -1317,7 +1316,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'pet', id: '1', @@ -1376,7 +1375,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'pet', id: '1', @@ -1436,7 +1435,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'home', id: '1', @@ -1495,7 +1494,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'home', id: '1', @@ -1557,7 +1556,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'pet', id: '1', @@ -1627,7 +1626,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'pet', id: '1', @@ -1704,7 +1703,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'home', id: '1', @@ -1774,7 +1773,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { assert.ok(true, 'We should call findRecord'); - return resolve({ + return Promise.resolve({ data: { type: 'home', id: '1', @@ -1944,7 +1943,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi ); } - return resolve({ + return Promise.resolve({ data: [], }); }; diff --git a/tests/main/tests/integration/relationships/relationship-links-test.js b/tests/main/tests/integration/relationships/relationship-links-test.js index 78fefc55b9c..5c0c739899b 100644 --- a/tests/main/tests/integration/relationships/relationship-links-test.js +++ b/tests/main/tests/integration/relationships/relationship-links-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -20,7 +19,7 @@ module('JSON:API links access on relationships', function (hooks) { class ApplicationAdapter extends EmberObject { findRecord() {} findHasMany() { - return resolve({ + return Promise.resolve({ data: [], }); } @@ -98,7 +97,7 @@ module('JSON:API links access on relationships', function (hooks) { class ApplicationAdapter extends EmberObject { findRecord() {} findHasMany() { - return resolve({ + return Promise.resolve({ data: [], }); } @@ -176,7 +175,7 @@ module('JSON:API links access on relationships', function (hooks) { class ApplicationAdapter extends EmberObject { findRecord() {} findHasMany() { - return resolve({ + return Promise.resolve({ data: [], }); } @@ -242,7 +241,7 @@ module('JSON:API links access on relationships', function (hooks) { class ApplicationAdapter extends EmberObject { findRecord() {} findHasMany() { - return resolve({ + return Promise.resolve({ data: [], links: { self: { href: '/some/other/path' }, diff --git a/tests/main/tests/integration/relationships/reload-error-test.js b/tests/main/tests/integration/relationships/reload-error-test.js index 094bf7a9009..37c2d20ab45 100644 --- a/tests/main/tests/integration/relationships/reload-error-test.js +++ b/tests/main/tests/integration/relationships/reload-error-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { reject } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -26,7 +25,7 @@ module('Relationships | unloading new records', function (hooks) { return false; } findRecord() { - return reject(new Error(`Bad Request`)); + return Promise.reject(new Error(`Bad Request`)); } } diff --git a/tests/main/tests/integration/request-state-service-test.ts b/tests/main/tests/integration/request-state-service-test.ts index c4917019c7b..682322239c7 100644 --- a/tests/main/tests/integration/request-state-service-test.ts +++ b/tests/main/tests/integration/request-state-service-test.ts @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { Promise } from 'rsvp'; import { setupTest } from 'ember-qunit'; diff --git a/tests/main/tests/integration/snapshot-test.js b/tests/main/tests/integration/snapshot-test.js index d4d4e9aa8c0..5055084d2c3 100644 --- a/tests/main/tests/integration/snapshot-test.js +++ b/tests/main/tests/integration/snapshot-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -112,7 +111,7 @@ module('integration/snapshot - Snapshot', function (hooks) { const record = store._instanceCache.peek({ identifier, bucket: 'record' }); assert.false(!!record, 'We do not have a materialized record'); assert.strictEqual(snapshot.__attributes, null, 'attributes were not populated initially'); - return resolve({ + return Promise.resolve({ data: { type: 'post', id: '1', @@ -448,7 +447,7 @@ module('integration/snapshot - Snapshot', function (hooks) { assert.expect(2); store.adapterFor('application').findBelongsTo = function (store, snapshot, link, relationship) { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }; store.push({ @@ -502,7 +501,7 @@ module('integration/snapshot - Snapshot', function (hooks) { assert.expect(4); store.adapterFor('application').findBelongsTo = function (store, snapshot, link, relationship) { - return resolve({ data: { id: '1', type: 'post', attributes: { title: 'Hello World' } } }); + return Promise.resolve({ data: { id: '1', type: 'post', attributes: { title: 'Hello World' } } }); }; store.push({ @@ -971,7 +970,7 @@ module('integration/snapshot - Snapshot', function (hooks) { assert.expect(2); store.adapterFor('application').findHasMany = function (store, snapshot, link, relationship) { - return resolve({ + return Promise.resolve({ data: [{ id: '2', type: 'comment', attributes: { body: 'This is comment' } }], }); }; diff --git a/tests/main/tests/integration/store/json-api-validation-test.js b/tests/main/tests/integration/store/json-api-validation-test.js index 514b620a9b7..87f9d2d4daf 100644 --- a/tests/main/tests/integration/store/json-api-validation-test.js +++ b/tests/main/tests/integration/store/json-api-validation-test.js @@ -1,5 +1,4 @@ import QUnit, { module } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -21,7 +20,7 @@ async function payloadError(owner, payload, expectedError, assert) { 'adapter:person', Adapter.extend({ findRecord() { - return resolve(payload); + return Promise.resolve(payload); }, }) ); @@ -68,7 +67,7 @@ module('integration/store/json-validation', function (hooks) { 'adapter:person', Adapter.extend({ findRecord() { - return resolve({ data: {} }); + return Promise.resolve({ data: {} }); }, }) ); @@ -94,7 +93,7 @@ module('integration/store/json-validation', function (hooks) { 'adapter:person', Adapter.extend({ findRecord() { - return resolve({ data: {} }); + return Promise.resolve({ data: {} }); }, }) ); @@ -120,7 +119,7 @@ module('integration/store/json-validation', function (hooks) { 'adapter:person', Adapter.extend({ findRecord() { - return resolve({ data: {} }); + return Promise.resolve({ data: {} }); }, }) ); @@ -151,7 +150,7 @@ module('integration/store/json-validation', function (hooks) { 'adapter:person', Adapter.extend({ findRecord() { - return resolve({ data: {} }); + return Promise.resolve({ data: {} }); }, }) ); diff --git a/tests/main/tests/integration/store/query-record-test.js b/tests/main/tests/integration/store/query-record-test.js index 7a63f732499..f06e1062fa9 100644 --- a/tests/main/tests/integration/store/query-record-test.js +++ b/tests/main/tests/integration/store/query-record-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -47,7 +46,7 @@ module('integration/store/query-record - Query one record with a query hash', fu Adapter.extend({ queryRecord(store, type, query) { assert.strictEqual(type, Person, 'the query method is called with the correct type'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', attributes: { name: 'Peter Wagenet' } }, }); }, @@ -64,7 +63,7 @@ module('integration/store/query-record - Query one record with a query hash', fu 'adapter:person', Adapter.extend({ queryRecord(store, type, query) { - return reject(); + return Promise.reject(); }, }) ); @@ -97,7 +96,7 @@ module('integration/store/query-record - Query one record with a query hash', fu 'adapter:person', Adapter.extend({ queryRecord(store, type, query) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', diff --git a/tests/main/tests/test-helper.js b/tests/main/tests/test-helper.js index fe7d374e1f2..275ca183764 100644 --- a/tests/main/tests/test-helper.js +++ b/tests/main/tests/test-helper.js @@ -2,7 +2,6 @@ import { setApplication } from '@ember/test-helpers'; import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; -import RSVP from 'rsvp'; import { start } from 'ember-qunit'; @@ -26,18 +25,6 @@ if (window.Testem) { window.Testem.useCustomAdapter(customQUnitAdapter); } -QUnit.begin(function () { - RSVP.configure('onerror', (reason) => { - // only print error messages if they're exceptions; - // otherwise, let a future turn of the event loop - // handle the error. - // TODO kill this off - if (reason && reason instanceof Error) { - throw reason; - } - }); -}); - QUnit.config.testTimeout = 2000; start({ setupTestIsolationValidation: true }); diff --git a/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js b/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js index 2060e834fe9..20c474009dd 100644 --- a/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js +++ b/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js @@ -1,7 +1,6 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { Promise as EmberPromise } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -49,7 +48,7 @@ module( lengths.push(fullUrl.length); let testRecords = options.data.ids.map((id) => ({ id })); - return EmberPromise.resolve({ testRecords: testRecords }); + return Promise.resolve({ testRecords: testRecords }); } } @@ -84,7 +83,7 @@ module( assert.strictEqual(requests[0].url, '/testRecords'); assert.deepEqual(requests[0].ids, ['my-id:1', 'my-id:2']); - await EmberPromise.all(wait); + await Promise.all(wait); }); test('_stripIDFromURL works with id being encoded - #4190', function (assert) { diff --git a/tests/main/tests/unit/many-array-test.js b/tests/main/tests/unit/many-array-test.js index 1540112978a..6edd7dbcb2a 100644 --- a/tests/main/tests/unit/many-array-test.js +++ b/tests/main/tests/unit/many-array-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -26,7 +25,7 @@ module('unit/many_array - ManyArray', function (hooks) { const store = this.owner.lookup('service:store'); store.saveRecord = function (record) { assert.ok(true, 'record.save() was called'); - return resolve(); + return Promise.resolve(); }; store.push({ diff --git a/tests/main/tests/unit/model-test.js b/tests/main/tests/unit/model-test.js index c6f4e40234b..788cc6de947 100644 --- a/tests/main/tests/unit/model-test.js +++ b/tests/main/tests/unit/model-test.js @@ -1,7 +1,6 @@ import { computed, get, observer, set } from '@ember/object'; import { module, test } from 'qunit'; -import { reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -71,7 +70,7 @@ module('unit/model - Model', function (hooks) { test('supports canonical updates via pushedData in root.deleted.saved', async function (assert) { adapter.deleteRecord = () => { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }; let record = store.push({ @@ -116,7 +115,7 @@ module('unit/model - Model', function (hooks) { testInDebug('Does not support dirtying in root.deleted.saved', async function (assert) { adapter.deleteRecord = () => { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }; let record = store.push({ @@ -669,7 +668,7 @@ module('unit/model - Model', function (hooks) { test('ensure model exits loading state, materializes data and fulfills promise only after data is available', async function (assert) { assert.expect(2); adapter.findRecord = () => - resolve({ + Promise.resolve({ data: { id: '1', type: 'person', @@ -934,7 +933,7 @@ module('unit/model - Model', function (hooks) { test('resetting a property to the current in-flight value causes it to become clean when the save completes', async function (assert) { adapter.updateRecord = function () { - return resolve(); + return Promise.resolve(); }; store.push({ @@ -992,7 +991,7 @@ module('unit/model - Model', function (hooks) { test('an invalid record becomes clean again if changed property is reset', async function (assert) { adapter.updateRecord = () => { - return reject( + return Promise.reject( new InvalidError([ { source: { @@ -1040,7 +1039,7 @@ module('unit/model - Model', function (hooks) { test('an invalid record stays dirty if only invalid property is reset', async function (assert) { adapter.updateRecord = () => { - return reject( + return Promise.reject( new InvalidError([ { source: { @@ -1177,7 +1176,7 @@ module('unit/model - Model', function (hooks) { likes: [undefined, 'Cheese'], }); - return resolve({ data: { id: '1', type: 'mascot' } }); + return Promise.resolve({ data: { id: '1', type: 'mascot' } }); }; let cat; @@ -1235,7 +1234,7 @@ module('unit/model - Model', function (hooks) { test('changedAttributes() reset after save', async function (assert) { adapter.updateRecord = function (store, type, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'person', diff --git a/tests/main/tests/unit/promise-proxies-test.js b/tests/main/tests/unit/promise-proxies-test.js index fab814607fb..98c61411b12 100644 --- a/tests/main/tests/unit/promise-proxies-test.js +++ b/tests/main/tests/unit/promise-proxies-test.js @@ -1,7 +1,6 @@ import { A } from '@ember/array'; import { module, test } from 'qunit'; -import { Promise as EmberPromise } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -16,7 +15,7 @@ module('PromiseManyArray', function () { let content = A(); - content.reload = () => EmberPromise.resolve(content); + content.reload = () => Promise.resolve(content); let array = PromiseManyArray.create({ content, @@ -34,11 +33,11 @@ module('PromiseManyArray', function () { let array; content.reload = () => { - let p = EmberPromise.resolve(content); + let p = Promise.resolve(content); array._update(p); return p; }; - let promise = EmberPromise.resolve(content); + let promise = Promise.resolve(content); array = PromiseManyArray.create({ promise, @@ -79,7 +78,7 @@ module('PromiseManyArray', function () { let content = A([1, 2, 3]); - let promise = EmberPromise.resolve(content); + let promise = Promise.resolve(content); let array = PromiseManyArray.create({ promise, @@ -96,7 +95,7 @@ module('PromiseManyArray', function () { assert.true(array.isSettled, 'should be settled'); assert.true(array.isFulfilled, 'should be fulfilled'); - array._update(EmberPromise.resolve(content)); + array._update(Promise.resolve(content)); assert.false(array.isRejected, 'should NOT be rejected'); assert.true(array.isPending, 'should be pending'); @@ -142,7 +141,7 @@ module('unit/PromiseBelongsTo', function (hooks) { }, }, }; - return EmberPromise.resolve(ChildRecord); + return Promise.resolve(ChildRecord); } } diff --git a/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js b/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js index b4eb1d6952a..0343bc393b5 100644 --- a/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js +++ b/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js @@ -1,5 +1,5 @@ import { module, skip, test } from 'qunit'; -import RSVP from 'rsvp'; +import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -64,7 +64,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR test('#update uses _update enabling query specific behavior', async function (assert) { let queryCalled = 0; - let deferred = RSVP.defer(); + let deferred = defer(); const store = { query(modelName, query, options) { diff --git a/tests/main/tests/unit/record-arrays/record-array-test.js b/tests/main/tests/unit/record-arrays/record-array-test.js index a0eaf611319..565545b2401 100644 --- a/tests/main/tests/unit/record-arrays/record-array-test.js +++ b/tests/main/tests/unit/record-arrays/record-array-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import RSVP from 'rsvp'; +import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -87,7 +87,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#update', async function (assert) { let findAllCalled = 0; - let deferred = RSVP.defer(); + let deferred = defer(); const store = { findAll(modelName, options) { @@ -124,7 +124,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#update while updating', async function (assert) { let findAllCalled = 0; - let deferred = RSVP.defer(); + let deferred = defer(); const store = { findAll(modelName, options) { findAllCalled++; From 3326a9ffc868ee46c7da408bb35fb48b6979aa49 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 11 Sep 2023 02:48:33 -0700 Subject: [PATCH 4/6] fixup --- package.json | 7 +++++++ pnpm-lock.yaml | 4 ++++ .../acceptance/relationships/tracking-record-state-test.js | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 681b1694ff5..b6485b71412 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,13 @@ } }, "pnpm": { + "packageExtensions": { + "@glimmer/syntax": { + "dependencies": { + "@glimmer/env": "^0.1.7" + } + } + }, "overrides": { "ember-auto-import": "^2.6.3", "@embroider/macros": "^1.12.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 775c6231324..e82734f4bda 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,6 +15,8 @@ overrides: '@ember/string': 3.1.1 ember-compatibility-helpers: ^1.2.6 +packageExtensionsChecksum: 412ea1f7b0456edcf429c4fd07d165d2 + patchedDependencies: ember-cli-babel@8.0.0: hash: u45mf2ptxi5n6ldhiqont5zk3y @@ -5111,6 +5113,7 @@ packages: /@glimmer/syntax@0.84.2: resolution: {integrity: sha512-SPBd1tpIR9XeaXsXsMRCnKz63eLnIZ0d5G9QC4zIBFBC3pQdtG0F5kWeuRVCdfTIFuR+5WBMfk5jvg+3gbQhjg==} dependencies: + '@glimmer/env': 0.1.7 '@glimmer/interfaces': 0.84.2 '@glimmer/util': 0.84.2 '@handlebars/parser': 2.0.0 @@ -5119,6 +5122,7 @@ packages: /@glimmer/syntax@0.84.3: resolution: {integrity: sha512-ioVbTic6ZisLxqTgRBL2PCjYZTFIwobifCustrozRU2xGDiYvVIL0vt25h2c1ioDsX59UgVlDkIK4YTAQQSd2A==} dependencies: + '@glimmer/env': 0.1.7 '@glimmer/interfaces': 0.84.3 '@glimmer/util': 0.84.3 '@handlebars/parser': 2.0.0 diff --git a/tests/main/tests/acceptance/relationships/tracking-record-state-test.js b/tests/main/tests/acceptance/relationships/tracking-record-state-test.js index bfe9675a439..85edcab515b 100644 --- a/tests/main/tests/acceptance/relationships/tracking-record-state-test.js +++ b/tests/main/tests/acceptance/relationships/tracking-record-state-test.js @@ -31,7 +31,7 @@ module('tracking state flags on a record', function (hooks) { tag.rev; // subscribe if (_isDirty && !_isUpdating) { _isUpdating = true; - resolve(desc.get.call(this)).then((v) => { + Promise.resolve(desc.get.call(this)).then((v) => { _value = v; _isDirty = false; tag.rev++; @@ -127,7 +127,7 @@ module('tracking state flags on a record', function (hooks) { class Adapter { createRecord() { assert.ok(true, 'createRecord was called to save'); - return resolve({ data: { type: 'person', id: `${serverId++}` } }); + return Promise.resolve({ data: { type: 'person', id: `${serverId++}` } }); } static create() { return new this(); From 60f3b9fb6deeebf4b2fa3bc4b5b2716717b320be Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 11 Sep 2023 03:12:56 -0700 Subject: [PATCH 5/6] fix tests --- .../integration/record-arrays/peeked-records-test.js | 11 ++++++++++- tests/main/tests/unit/store/asserts-test.js | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/main/tests/integration/record-arrays/peeked-records-test.js b/tests/main/tests/integration/record-arrays/peeked-records-test.js index 266187b8a5a..731d338828d 100644 --- a/tests/main/tests/integration/record-arrays/peeked-records-test.js +++ b/tests/main/tests/integration/record-arrays/peeked-records-test.js @@ -121,6 +121,7 @@ module('integration/peeked-records', function (hooks) { let aNewlyCreatedRecord = store.createRecord('person', { name: 'James', }); + await settled(); assert.watchedPropertyCounts(watcher, { length: 2, '[]': 2 }, 'RecordArray state when a new record is created'); @@ -142,7 +143,10 @@ module('integration/peeked-records', function (hooks) { }); let records = store.peekAll('person'); - assert.strictEqual(records.length, 1); + assert.strictEqual(records.length, 1, 'we see the new record'); + + // we should not have notified the array yet because ember schedules this async + await settled(); assert.watchedPropertyCounts(watcher, { length: 2, '[]': 2 }, 'RecordArray state when a new record is created'); aNewlyCreatedRecord.unloadRecord(); @@ -163,6 +167,9 @@ module('integration/peeked-records', function (hooks) { name: 'James', }); + // we should not have notified the array yet because ember schedules this async + await settled(); + assert.watchedPropertyCounts(watcher, { length: 2, '[]': 2 }, 'RecordArray state when a new record is created'); aNewlyCreatedRecord.unloadRecord(); @@ -181,6 +188,8 @@ module('integration/peeked-records', function (hooks) { name: 'James', }); + await settled(); + assert.watchedPropertyCounts(watcher, { length: 2, '[]': 2 }, 'RecordArray state when a new record is created'); aNewlyCreatedRecord.unloadRecord(); diff --git a/tests/main/tests/unit/store/asserts-test.js b/tests/main/tests/unit/store/asserts-test.js index 5f69fd4f90a..5b1586c7db5 100644 --- a/tests/main/tests/unit/store/asserts-test.js +++ b/tests/main/tests/unit/store/asserts-test.js @@ -8,7 +8,7 @@ import Model from '@ember-data/model'; import Store from '@ember-data/store'; import test from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; -module('unit/store/asserts - DS.Store methods produce useful assertion messages', function (hooks) { +module('unit/store/asserts - Store methods produce useful assertion messages', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { let { owner } = this; @@ -71,6 +71,7 @@ module('unit/store/asserts - DS.Store methods produce useful assertion messages' const store = new Store(); store.shouldAssertMethodCallsOnDestroyedStore = true; assert.expect(STORE_ENTRY_METHODS.length); + store.destroy(); await settled(); STORE_ENTRY_METHODS.forEach((methodName) => { From 09f00af82dd24e1a982bc35477d7bd99f4285be9 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Mon, 11 Sep 2023 03:57:44 -0700 Subject: [PATCH 6/6] fix more tests --- tests/main/app/backburner-flush-override.js | 107 --- .../tests/integration/records/unload-test.js | 250 ++++--- .../integration/references/has-many-test.js | 397 +++++------ .../relationships/belongs-to-test.js | 355 +++++----- .../relationships/one-to-one-test.js | 614 ++++++++---------- tests/main/tests/integration/store-test.js | 22 +- tests/main/tests/unit/store/push-test.js | 597 ++++++++--------- 7 files changed, 1001 insertions(+), 1341 deletions(-) delete mode 100644 tests/main/app/backburner-flush-override.js diff --git a/tests/main/app/backburner-flush-override.js b/tests/main/app/backburner-flush-override.js deleted file mode 100644 index 66be5bf23f6..00000000000 --- a/tests/main/app/backburner-flush-override.js +++ /dev/null @@ -1,107 +0,0 @@ -/* - An alternative render flush mechanism for glimmer -*/ -import { Renderer } from '@ember/-internals/glimmer'; -// eslint-disable-next-line no-restricted-imports -import { _backburner } from '@ember/runloop'; - -import * as RSVP from 'rsvp'; - -const HAS_RAF = typeof requestAnimationFrame !== 'undefined'; -const HAS_RIC = typeof requestIdleCallback !== 'undefined'; -const RENDER_DEBOUNCE_COUNT = 5; -const MICROTASK_DEBOUNCE_COUNT = 2; - -// race various things to flush -function _performRace(resolve) { - let resolved = false; - const complete = () => { - if (resolved) return; - resolved = true; - resolve(); - }; - - if (HAS_RAF) - requestAnimationFrame(() => { - if (!resolved) { - if (HAS_RIC) requestIdleCallback(complete); - setTimeout(complete, 0); - } - }); - if (HAS_RIC) requestIdleCallback(complete); - setTimeout(complete, 0); -} - -function race() { - return new Promise(_performRace); -} - -async function awaitSettled(renderer, debounceCount = MICROTASK_DEBOUNCE_COUNT) { - let startCount = renderer._revalidateCalls; - let successCount = 0; - let keepWaiting = true; - - // once we've elected to flush, we wait for the current microtask queue - // to "settle" to begin - while (keepWaiting) { - await Promise.resolve(); - - if (renderer._revalidateCalls === startCount) { - successCount++; - - if (successCount === debounceCount) { - // break loop - keepWaiting = false; - break; - } - } else { - startCount = this._revalidateCalls; - successCount = 0; - } - } - - renderer._revalidateCalls = 0; - renderer._revalidate(); - renderer._nextRevalidate = null; -} - -// add this to tests/main to find tests that only work due to rsvp Promise flush -export function restoreRSVP() { - // restore native promise behavior to RSVP - RSVP.configure('async', (callback, promise) => { - Promise.resolve().then(() => { - callback(promise); - }); - }); -} - -// add this to tests/main to find tests that only work due to backburner flush timing -export function installOverride(debounceCount = MICROTASK_DEBOUNCE_COUNT) { - // debounce autoruns to capture more potential activity - const flush = _backburner._boundAutorunEnd; - const original = _backburner._ensureInstance; - - _backburner._revalidateCalls = 0; - _backburner._ensureInstance = function () { - _backburner._scheduleInstanceCounter++; - return original.apply(_backburner, arguments); - }; - _backburner._revalidate = flush; - _backburner._platform.next = () => { - awaitSettled(_backburner, debounceCount); - }; -} - -// add this to tests/main to find tests that only work due to render flush timing -// This doesn't quite work yet, likely need to patch Ember to remove the heavy -// runloop validation entanglements. -export function installRendererOverride(debounceCount = RENDER_DEBOUNCE_COUNT) { - Renderer.prototype._scheduleRevalidate = function betterRenderFlush() { - if (this._revalidateCalls) { - this._revalidateCalls++; - } else { - this._revalidateCalls = 1; - } - if (!this._nextRevalidate) this._nextRevalidate = race().then(() => awaitSettled(this, debounceCount)); - }; -} diff --git a/tests/main/tests/integration/records/unload-test.js b/tests/main/tests/integration/records/unload-test.js index cb9c721546f..ddb27be7e78 100644 --- a/tests/main/tests/integration/records/unload-test.js +++ b/tests/main/tests/integration/records/unload-test.js @@ -185,71 +185,65 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(adam, null, 'we have no person'); }); - test('can unload all records for a given type', function (assert) { + test('can unload all records for a given type', async function (assert) { assert.expect(6); let car; - run(function () { - store.push({ - data: [ - { - type: 'person', - id: '1', - attributes: { - name: 'Adam Sunderland', - }, - }, - { - type: 'person', - id: '2', - attributes: { - name: 'Bob Bobson', - }, - }, - ], - }); - let adam = store.peekRecord('person', 1); - let bob = store.peekRecord('person', 2); - - car = store.push({ - data: { - type: 'car', + store.push({ + data: [ + { + type: 'person', id: '1', attributes: { - make: 'VW', - model: 'Beetle', + name: 'Adam Sunderland', }, - relationships: { - person: { - data: { type: 'person', id: '1' }, - }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', }, }, - }); - bob = store.peekRecord('car', 1); + ], + }); + let adam = store.peekRecord('person', 1); + let bob = store.peekRecord('person', 2); + + car = store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'VW', + model: 'Beetle', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, }); + bob = store.peekRecord('car', 1); assert.strictEqual(store.peekAll('person').length, 2, 'two person records loaded'); assert.strictEqual(store.peekAll('car').length, 1, 'one car record loaded'); - run(function () { - car.person; - store.unloadAll('person'); - }); + await car.person; + store.unloadAll('person'); assert.strictEqual(store.peekAll('person').length, 0); assert.strictEqual(store.peekAll('car').length, 1); - run(function () { - store.push({ - data: { - id: '1', - type: 'person', - attributes: { - name: 'Richard II', - }, + store.push({ + data: { + id: '1', + type: 'person', + attributes: { + name: 'Richard II', }, - }); + }, }); car = store.peekRecord('car', 1); @@ -262,52 +256,48 @@ module('integration/unload - Unloading Records', function (hooks) { test('can unload all records', function (assert) { assert.expect(4); - run(function () { - store.push({ - data: [ - { - type: 'person', - id: '1', - attributes: { - name: 'Adam Sunderland', - }, - }, - { - type: 'person', - id: '2', - attributes: { - name: 'Bob Bobson', - }, - }, - ], - }); - let adam = store.peekRecord('person', 1); - let bob = store.peekRecord('person', 2); - - store.push({ - data: { - type: 'car', + store.push({ + data: [ + { + type: 'person', id: '1', attributes: { - make: 'VW', - model: 'Beetle', + name: 'Adam Sunderland', }, - relationships: { - person: { - data: { type: 'person', id: '1' }, - }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', }, }, - }); - bob = store.peekRecord('car', 1); + ], + }); + let adam = store.peekRecord('person', '1'); + let bob = store.peekRecord('person', '2'); + + store.push({ + data: { + type: 'car', + id: '1', + attributes: { + make: 'VW', + model: 'Beetle', + }, + relationships: { + person: { + data: { type: 'person', id: '1' }, + }, + }, + }, }); + bob = store.peekRecord('car', '1'); assert.strictEqual(store.peekAll('person').length, 2, 'two person records loaded'); assert.strictEqual(store.peekAll('car').length, 1, 'one car record loaded'); - run(function () { - store.unloadAll(); - }); + store.unloadAll(); assert.strictEqual(store.peekAll('person').length, 0); assert.strictEqual(store.peekAll('car').length, 0); @@ -642,35 +632,29 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('unloading all records also updates record array from peekAll()', function (assert) { - run(function () { - store.push({ - data: [ - { - type: 'person', - id: '1', - attributes: { - name: 'Adam Sunderland', - }, + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Adam Sunderland', }, - { - type: 'person', - id: '2', - attributes: { - name: 'Bob Bobson', - }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Bob Bobson', }, - ], - }); - let adam = store.peekRecord('person', 1); - let bob = store.peekRecord('person', 2); + }, + ], }); let all = store.peekAll('person'); assert.strictEqual(all.length, 2); - run(function () { - store.unloadAll('person'); - }); + store.unloadAll('person'); assert.strictEqual(all.length, 0); }); @@ -756,9 +740,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(peopleBoats.at(0), boat, 'Our person has the right boat'); assert.strictEqual(boatPerson, person, 'Our boat has the right person'); - run(() => { - store.unloadAll('boat'); - }); + store.unloadAll('boat'); // ensure that our new state is correct assert.strictEqual(relationshipState.remoteState.length, 1, 'remoteMembers size should still be 1'); @@ -766,11 +748,9 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(relationshipState.removals, null, 'removals should be empty'); assert.strictEqual(get(peopleBoats, 'length'), 0, 'Our person thinks they have no boats'); - run(() => - store.push({ - data: makeBoatOneForPersonOne(), - }) - ); + store.push({ + data: makeBoatOneForPersonOne(), + }); store.peekRecord('boat', '1'); @@ -845,23 +825,21 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('(regression) unloadRecord followed by push in the same run-loop', async function (assert) { - let person = run(() => - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Could be Anybody', - }, - relationships: { - boats: { - data: [{ type: 'boat', id: '1' }], - }, + let person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Could be Anybody', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '1' }], }, }, - included: [makeBoatOneForPersonOne()], - }) - ); + }, + included: [makeBoatOneForPersonOne()], + }); let boat = store.peekRecord('boat', '1'); let relationshipState = person.hasMany('boats').hasManyRelationship; @@ -870,9 +848,9 @@ module('integration/unload - Unloading Records', function (hooks) { assert.notStrictEqual(store.peekRecord('person', '1'), null); assert.notStrictEqual(store.peekRecord('boat', '1'), null); - // ensure the relationship was established (we reach through the async proxy here) - let peopleBoats = run(() => person.boats.content); - let boatPerson = run(() => boat.person.content); + // ensure the relationship was established + let peopleBoats = await person.boats; + let boatPerson = await boat.person; assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should be 1'); @@ -880,18 +858,16 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(peopleBoats.at(0), boat, 'Our person has the right boat'); assert.strictEqual(boatPerson, person, 'Our boat has the right person'); - run(() => boat.unloadRecord()); + boat.unloadRecord(); // ensure that our new state is correct assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should still be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should still be 1'); assert.strictEqual(get(peopleBoats, 'length'), 0, 'Our person thinks they have no boats'); - run(() => - store.push({ - data: makeBoatOneForPersonOne(), - }) - ); + store.push({ + data: makeBoatOneForPersonOne(), + }); let reloadedBoat = store.peekRecord('boat', '1'); diff --git a/tests/main/tests/integration/references/has-many-test.js b/tests/main/tests/integration/references/has-many-test.js index 85424313f3b..848109e3c15 100755 --- a/tests/main/tests/integration/references/has-many-test.js +++ b/tests/main/tests/integration/references/has-many-test.js @@ -1,9 +1,4 @@ -import { get } from '@ember/object'; -// eslint-disable-next-line no-restricted-imports -import { run } from '@ember/runloop'; - import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupRenderingTest } from 'ember-qunit'; @@ -262,7 +257,7 @@ module('integration/references/has-many', function (hooks) { ]; const records = await personsReference.push(data); - assert.strictEqual(get(records, 'length'), 2); + assert.strictEqual(records.length, 2); assert.strictEqual(records.at(0).name, 'Vito'); assert.strictEqual(records.at(1).name, 'Michael'); }); @@ -298,7 +293,7 @@ module('integration/references/has-many', function (hooks) { const data = [{ data: { type: 'mafia-boss', id: '1', attributes: { name: 'Vito' } } }]; const records = await personsReference.push(data); - assert.strictEqual(get(records, 'length'), 1); + assert.strictEqual(records.length, 1); assert.strictEqual(records.at(0).name, 'Vito'); }); @@ -327,47 +322,37 @@ module('integration/references/has-many', function (hooks) { }, "The 'person' type does not implement 'animal' and thus cannot be assigned to the 'pets' relationship in 'person'. If this relationship should be polymorphic, mark person.pets as `polymorphic: true` and person.owner as implementing it via `as: 'animal'`."); }); - testInDebug('push(object) supports legacy, non-JSON-API-conform payload', function (assert) { - var done = assert.async(); - + testInDebug('push(object) supports legacy, non-JSON-API-conform payload', async function (assert) { let store = this.owner.lookup('service:store'); - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [ - { type: 'person', id: '1' }, - { type: 'person', id: '2' }, - ], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [ + { type: 'person', id: '1' }, + { type: 'person', id: '2' }, + ], }, }, - }); + }, }); var personsReference = family.hasMany('persons'); - run(function () { - var payload = { - data: [ - { data: { type: 'person', id: '1', attributes: { name: 'Vito' } } }, - { data: { type: 'person', id: '2', attributes: { name: 'Michael' } } }, - ], - }; - - personsReference.push(payload).then(function (records) { - assert.strictEqual(get(records, 'length'), 2); - assert.strictEqual(records.at(0).name, 'Vito'); - assert.strictEqual(records.at(1).name, 'Michael'); + var payload = { + data: [ + { data: { type: 'person', id: '1', attributes: { name: 'Vito' } } }, + { data: { type: 'person', id: '2', attributes: { name: 'Michael' } } }, + ], + }; - done(); - }); - }); + const records = await personsReference.push(payload); + assert.strictEqual(records.length, 2); + assert.strictEqual(records.at(0).name, 'Vito'); + assert.strictEqual(records.at(1).name, 'Michael'); }); test('push valid json:api', async function (assert) { @@ -398,7 +383,7 @@ module('integration/references/has-many', function (hooks) { assert.ok(pushResult.then, 'HasManyReference.push returns a promise'); const records = await pushResult; - assert.strictEqual(get(records, 'length'), 2); + assert.strictEqual(records.length, 2); assert.strictEqual(records.at(0).name, 'Vito'); assert.strictEqual(records.at(1).name, 'Michael'); }); @@ -406,22 +391,19 @@ module('integration/references/has-many', function (hooks) { test('value() returns null when reference is not yet loaded', function (assert) { let store = this.owner.lookup('service:store'); - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [ - { type: 'person', id: '1' }, - { type: 'person', id: '2' }, - ], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [ + { type: 'person', id: '1' }, + { type: 'person', id: '2' }, + ], }, }, - }); + }, }); var personsReference = family.hasMany('persons'); @@ -431,87 +413,70 @@ module('integration/references/has-many', function (hooks) { test('value() returns the referenced records when all records are loaded', function (assert) { let store = this.owner.lookup('service:store'); - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [ - { type: 'person', id: '1' }, - { type: 'person', id: '2' }, - ], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [ + { type: 'person', id: '1' }, + { type: 'person', id: '2' }, + ], }, }, - }); - store.push({ data: { type: 'person', id: '1', attributes: { name: 'Vito' } } }); - store.push({ data: { type: 'person', id: '2', attributes: { name: 'Michael' } } }); + }, }); + store.push({ data: { type: 'person', id: '1', attributes: { name: 'Vito' } } }); + store.push({ data: { type: 'person', id: '2', attributes: { name: 'Michael' } } }); - run(function () { - var personsReference = family.hasMany('persons'); - var records = personsReference.value(); - assert.strictEqual(get(records, 'length'), 2); - assert.true(records.every((v) => v.isLoaded)); - }); + var personsReference = family.hasMany('persons'); + var records = personsReference.value(); + assert.strictEqual(records.length, 2); + assert.true(records.every((v) => v.isLoaded)); }); test('value() returns an empty array when the reference is loaded and empty', function (assert) { let store = this.owner.lookup('service:store'); - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [], }, }, - }); + }, }); - run(function () { - var personsReference = family.hasMany('persons'); - var records = personsReference.value(); - assert.strictEqual(get(records, 'length'), 0); - }); + var personsReference = family.hasMany('persons'); + var records = personsReference.value(); + assert.strictEqual(records.length, 0); }); test('_isLoaded() returns an true array when the reference is loaded and empty', function (assert) { let store = this.owner.lookup('service:store'); - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [], }, }, - }); + }, }); - run(function () { - var personsReference = family.hasMany('persons'); - var isLoaded = personsReference._isLoaded(); - assert.true(isLoaded); - }); + var personsReference = family.hasMany('persons'); + var isLoaded = personsReference._isLoaded(); + assert.true(isLoaded); }); - test('load() fetches the referenced records', function (assert) { - var done = assert.async(); - + test('load() fetches the referenced records', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -519,7 +484,7 @@ module('integration/references/has-many', function (hooks) { adapter.findMany = function (store, type, id, snapshots) { assert.strictEqual(snapshots[0].adapterOptions, adapterOptions, 'adapterOptions are passed in'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'person', attributes: { name: 'Vito' } }, { id: '2', type: 'person', attributes: { name: 'Michael' } }, @@ -527,40 +492,30 @@ module('integration/references/has-many', function (hooks) { }); }; - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [ - { type: 'person', id: '1' }, - { type: 'person', id: '2' }, - ], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [ + { type: 'person', id: '1' }, + { type: 'person', id: '2' }, + ], }, }, - }); + }, }); var personsReference = family.hasMany('persons'); - run(function () { - personsReference.load({ adapterOptions }).then(function (records) { - assert.strictEqual(get(records, 'length'), 2); - assert.strictEqual(records.at(0).name, 'Vito'); - assert.strictEqual(records.at(1).name, 'Michael'); - - done(); - }); - }); + const records = await personsReference.load({ adapterOptions }); + assert.strictEqual(records.length, 2); + assert.strictEqual(records.at(0).name, 'Vito'); + assert.strictEqual(records.at(1).name, 'Michael'); }); - test('load() fetches link when remoteType is link', function (assert) { - var done = assert.async(); - + test('load() fetches link when remoteType is link', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -570,7 +525,7 @@ module('integration/references/has-many', function (hooks) { assert.strictEqual(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); assert.strictEqual(link, '/families/1/persons'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'person', attributes: { name: 'Vito' } }, { id: '2', type: 'person', attributes: { name: 'Michael' } }, @@ -578,36 +533,28 @@ module('integration/references/has-many', function (hooks) { }); }; - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - links: { related: '/families/1/persons' }, - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + links: { related: '/families/1/persons' }, }, }, - }); + }, }); var personsReference = family.hasMany('persons'); assert.strictEqual(personsReference.remoteType(), 'link'); - run(function () { - personsReference.load({ adapterOptions }).then(function (records) { - assert.strictEqual(get(records, 'length'), 2); - assert.strictEqual(records.at(0).name, 'Vito'); - assert.strictEqual(records.at(1).name, 'Michael'); - - done(); - }); - }); + const records = await personsReference.load({ adapterOptions }); + assert.strictEqual(records.length, 2); + assert.strictEqual(records.at(0).name, 'Vito'); + assert.strictEqual(records.at(1).name, 'Michael'); }); - test('load() fetches link when remoteType is link but an empty set of records is returned', function (assert) { + test('load() fetches link when remoteType is link but an empty set of records is returned', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -617,32 +564,27 @@ module('integration/references/has-many', function (hooks) { assert.strictEqual(snapshot.adapterOptions, adapterOptions, 'adapterOptions are passed in'); assert.strictEqual(link, '/families/1/persons'); - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); }; - let family; - run(() => { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - links: { related: '/families/1/persons' }, - }, + let family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + links: { related: '/families/1/persons' }, }, }, - }); + }, }); let personsReference = family.hasMany('persons'); assert.strictEqual(personsReference.remoteType(), 'link'); - return run(() => { - return personsReference.load({ adapterOptions }).then((records) => { - assert.strictEqual(get(records, 'length'), 0); - assert.strictEqual(get(personsReference.value(), 'length'), 0); - }); + await personsReference.load({ adapterOptions }).then((records) => { + assert.strictEqual(records.length, 0); + assert.strictEqual(personsReference.value()?.length, 0); }); }); @@ -697,9 +639,7 @@ module('integration/references/has-many', function (hooks) { assert.strictEqual(count, 1, 'we only requested records once'); }); - test('reload()', function (assert) { - var done = assert.async(); - + test('reload()', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -707,7 +647,7 @@ module('integration/references/has-many', function (hooks) { adapter.findMany = function (store, type, id, snapshots) { assert.strictEqual(snapshots[0].adapterOptions, adapterOptions, 'adapterOptions are passed in'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'person', attributes: { name: 'Vito Coreleone' } }, { id: '2', type: 'person', attributes: { name: 'Michael Coreleone' } }, @@ -715,42 +655,32 @@ module('integration/references/has-many', function (hooks) { }); }; - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - data: [ - { type: 'person', id: '1' }, - { type: 'person', id: '2' }, - ], - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + data: [ + { type: 'person', id: '1' }, + { type: 'person', id: '2' }, + ], }, }, - }); - store.push({ data: { type: 'person', id: '1', attributes: { name: 'Vito' } } }); - store.push({ data: { type: 'person', id: '2', attributes: { name: 'Michael' } } }); + }, }); + store.push({ data: { type: 'person', id: '1', attributes: { name: 'Vito' } } }); + store.push({ data: { type: 'person', id: '2', attributes: { name: 'Michael' } } }); var personsReference = family.hasMany('persons'); - run(function () { - personsReference.reload({ adapterOptions }).then(function (records) { - assert.strictEqual(get(records, 'length'), 2); - assert.strictEqual(records.at(0).name, 'Vito Coreleone'); - assert.strictEqual(records.at(1).name, 'Michael Coreleone'); - - done(); - }); - }); + const records = await personsReference.reload({ adapterOptions }); + assert.strictEqual(records.length, 2); + assert.strictEqual(records.at(0).name, 'Vito Coreleone'); + assert.strictEqual(records.at(1).name, 'Michael Coreleone'); }); - test('reload() fetches link when remoteType is link', function (assert) { - var done = assert.async(); - + test('reload() fetches link when remoteType is link', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -763,14 +693,14 @@ module('integration/references/has-many', function (hooks) { assert.strictEqual(link, '/families/1/persons'); if (count === 1) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'person', attributes: { name: 'Vito' } }, { id: '2', type: 'person', attributes: { name: 'Michael' } }, ], }); } else { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'person', attributes: { name: 'Vito Coreleone' } }, { id: '2', type: 'person', attributes: { name: 'Michael Coreleone' } }, @@ -779,38 +709,31 @@ module('integration/references/has-many', function (hooks) { } }; - var family; - run(function () { - family = store.push({ - data: { - type: 'family', - id: '1', - relationships: { - persons: { - links: { related: '/families/1/persons' }, - }, + var family = store.push({ + data: { + type: 'family', + id: '1', + relationships: { + persons: { + links: { related: '/families/1/persons' }, }, }, - }); + }, }); var personsReference = family.hasMany('persons'); assert.strictEqual(personsReference.remoteType(), 'link'); - run(function () { - personsReference - .load({ adapterOptions }) - .then(function () { - return personsReference.reload({ adapterOptions }); - }) - .then(function (records) { - assert.strictEqual(get(records, 'length'), 2); - assert.strictEqual(records.at(0).name, 'Vito Coreleone'); - assert.strictEqual(records.at(1).name, 'Michael Coreleone'); - - done(); - }); - }); + await personsReference + .load({ adapterOptions }) + .then(function () { + return personsReference.reload({ adapterOptions }); + }) + .then(function (records) { + assert.strictEqual(records.length, 2); + assert.strictEqual(records.at(0).name, 'Vito Coreleone'); + assert.strictEqual(records.at(1).name, 'Michael Coreleone'); + }); }); test('push record with nested includes (async has-many), chained HasManyReference#value()', async function (assert) { @@ -913,7 +836,7 @@ module('integration/references/has-many', function (hooks) { let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshots) { - return resolve({ + return Promise.resolve({ data: { type: 'family', id: '1', diff --git a/tests/main/tests/integration/relationships/belongs-to-test.js b/tests/main/tests/integration/relationships/belongs-to-test.js index bbd8cc052ea..d22497227cd 100644 --- a/tests/main/tests/integration/relationships/belongs-to-test.js +++ b/tests/main/tests/integration/relationships/belongs-to-test.js @@ -1,9 +1,7 @@ import EmberObject from '@ember/object'; -// eslint-disable-next-line no-restricted-imports -import { run } from '@ember/runloop'; import { module, test } from 'qunit'; -import { hash, resolve } from 'rsvp'; +import { hash } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -61,7 +59,7 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' 'adapter:company', JSONAPIAdapter.extend({ findBelongsTo(store, type, snapshot) { - return resolve({ + return Promise.resolve({ links: { related: 'company/1/parent-company', }, @@ -114,7 +112,7 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' 'adapter:company', JSONAPIAdapter.extend({ createRecord(store, type, snapshot) { - return resolve({ + return Promise.resolve({ data: { type: 'company', id: '123', @@ -143,7 +141,7 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' JSONAPIAdapter.extend({ findRecord() { assert.strictEqual(++petFindRecordCalls, 1, 'We call findRecord only once for our pet'); - return resolve({ + return Promise.resolve({ data: { type: 'pet', id: '1', @@ -167,7 +165,7 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' JSONAPIAdapter.extend({ findRecord() { assert.strictEqual(++personFindRecordCalls, 1, 'We call findRecord only once for our person'); - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -443,7 +441,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = (store, type, snapshot) => { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'app', @@ -486,7 +484,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = function (store, type, id, snapshot) { assert.ok(true, "The adapter's find method should be called"); - return resolve({ + return Promise.resolve({ data: { id, type: snapshot.modelName, @@ -521,23 +519,21 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function // test null id assert.expectAssertion(() => { - run(() => { - let post = store.push({ - data: { - id: '1', - type: 'post', - relationships: { - user: { - data: { - id: null, - type: 'user', - }, + let post = store.push({ + data: { + id: '1', + type: 'post', + relationships: { + user: { + data: { + id: null, + type: 'user', }, }, }, - }); - post.user; + }, }); + post.user; }, /Assertion Failed: Encountered a relationship identifier without an id for the belongsTo relationship 'user' on , expected an identifier but found/); }); @@ -548,23 +544,21 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function // test missing type assert.expectAssertion(() => { - run(() => { - let post = store.push({ - data: { - id: '2', - type: 'post', - relationships: { - user: { - data: { - id: '1', - type: null, - }, + let post = store.push({ + data: { + id: '2', + type: 'post', + relationships: { + user: { + data: { + id: '1', + type: null, }, }, }, - }); - post.user; + }, }); + post.user; }, /Assertion Failed: Encountered a relationship identifier without a type for the belongsTo relationship 'user' on , expected an identifier with type 'user' but found/); }); @@ -593,47 +587,43 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } ); - test('The store can load a polymorphic belongsTo association', function (assert) { + test('The store can load a polymorphic belongsTo association', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; - run(() => { - store.push({ - data: { - id: '1', - type: 'post', - }, - }); + store.push({ + data: { + id: '1', + type: 'post', + }, + }); - store.push({ - data: { - id: '2', - type: 'comment', - relationships: { - message: { - data: { - id: '1', - type: 'post', - }, + store.push({ + data: { + id: '2', + type: 'comment', + relationships: { + message: { + data: { + id: '1', + type: 'post', }, }, }, - }); + }, }); - return run(() => { - return hash({ - message: store.findRecord('post', 1), - comment: store.findRecord('comment', 2), - }).then((records) => { - assert.strictEqual(records.comment.message, records.message); - }); + await hash({ + message: store.findRecord('post', '1'), + comment: store.findRecord('comment', '2'), + }).then((records) => { + assert.strictEqual(records.comment.message, records.message); }); }); - test('The store can serialize a polymorphic belongsTo association', function (assert) { + test('The store can serialize a polymorphic belongsTo association', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -646,38 +636,36 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function json['message_type'] = 'post'; }; - return run(() => { - store.push({ - data: { - id: '1', - type: 'post', - }, - }); + store.push({ + data: { + id: '1', + type: 'post', + }, + }); - store.push({ - data: { - id: '2', - type: 'comment', - relationships: { - message: { - data: { - id: '1', - type: 'post', - }, + store.push({ + data: { + id: '2', + type: 'comment', + relationships: { + message: { + data: { + id: '1', + type: 'post', }, }, }, - }); + }, + }); - return store.findRecord('comment', 2).then((comment) => { - let serialized = comment.serialize({ includeId: true }); - assert.strictEqual(serialized.data.relationships.message.data.id, '1'); - assert.strictEqual(serialized.data.relationships.message.data.type, 'posts'); - }); + await store.findRecord('comment', '2').then((comment) => { + let serialized = comment.serialize({ includeId: true }); + assert.strictEqual(serialized.data.relationships.message.data.id, '1'); + assert.strictEqual(serialized.data.relationships.message.data.type, 'posts'); }); }); - test('A serializer can materialize a belongsTo as a link that gets sent back to findBelongsTo', function (assert) { + test('A serializer can materialize a belongsTo as a link that gets sent back to findBelongsTo', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -694,20 +682,18 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function this.owner.register('model:group', Group); this.owner.register('model:person', Person); - run(() => { - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - group: { - links: { - related: '/people/1/group', - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + group: { + links: { + related: '/people/1/group', }, }, }, - }); + }, }); adapter.findRecord = function (store, type, id, snapshot) { @@ -719,7 +705,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.strictEqual(relationship.key, 'group'); assert.strictEqual(link, '/people/1/group'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'group', @@ -732,20 +718,18 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); }; - return run(() => { - return store - .findRecord('person', 1) - .then((person) => { - return person.group; - }) - .then((group) => { - assert.ok(group instanceof Group, 'A group object is loaded'); - assert.strictEqual(group.id, '1', 'It is the group we are expecting'); - }); - }); + await store + .findRecord('person', 1) + .then((person) => { + return person.group; + }) + .then((group) => { + assert.ok(group instanceof Group, 'A group object is loaded'); + assert.strictEqual(group.id, '1', 'It is the group we are expecting'); + }); }); - test('A record with an async belongsTo relationship always returns a promise for that relationship', function (assert) { + test('A record with an async belongsTo relationship always returns a promise for that relationship', async function (assert) { let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); @@ -762,20 +746,18 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function this.owner.register('model:seat', Seat); this.owner.register('model:person', Person); - run(() => { - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - seat: { - links: { - related: '/people/1/seat', - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + seat: { + links: { + related: '/people/1/seat', }, }, }, - }); + }, }); adapter.findRecord = function (store, type, id, snapshot) { @@ -783,22 +765,20 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; adapter.findBelongsTo = function (store, snapshot, link, relationship) { - return resolve({ data: { id: '1', type: 'seat' } }); + return Promise.resolve({ data: { id: '1', type: 'seat' } }); }; - return run(() => { - return store.findRecord('person', 1).then((person) => { - return person.seat.then((seat) => { - // this assertion fails too - // ok(seat.person === person, 'parent relationship should be populated'); - seat.set('person', person); - assert.ok(person.seat.then, 'seat should be a PromiseObject'); - }); + await store.findRecord('person', '1').then((person) => { + return person.seat.then((seat) => { + // this assertion fails too + // ok(seat.person === person, 'parent relationship should be populated'); + seat.set('person', person); + assert.ok(person.seat.then, 'seat should be a PromiseObject'); }); }); }); - test('A record with an async belongsTo relationship returning null should resolve null', function (assert) { + test('A record with an async belongsTo relationship returning null should resolve null', async function (assert) { assert.expect(1); let store = this.owner.lookup('service:store'); @@ -817,20 +797,18 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function this.owner.register('model:group', Group); this.owner.register('model:person', Person); - run(() => { - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - group: { - links: { - related: '/people/1/group', - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + group: { + links: { + related: '/people/1/group', }, }, }, - }); + }, }); adapter.findRecord = function (store, type, id, snapshot) { @@ -838,10 +816,10 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; adapter.findBelongsTo = function (store, snapshot, link, relationship) { - return resolve({ data: null }); + return Promise.resolve({ data: null }); }; - return store + await store .findRecord('person', '1') .then((person) => { return person.group; @@ -856,14 +834,12 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let store = this.owner.lookup('service:store'); - run(() => { - let igor = store.createRecord('user', { name: 'Igor' }); - let post = store.createRecord('post', { title: "Igor's unimaginative blog post" }); + let igor = store.createRecord('user', { name: 'Igor' }); + let post = store.createRecord('post', { title: "Igor's unimaginative blog post" }); - igor.set('favouriteMessage', post); + igor.set('favouriteMessage', post); - assert.strictEqual(igor.favouriteMessage.title, "Igor's unimaginative blog post"); - }); + assert.strictEqual(igor.favouriteMessage.title, "Igor's unimaginative blog post"); }); test('relationship changes shouldn’t cause async fetches', async function (assert) { @@ -1024,22 +1000,19 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function testInDebug('A sync belongsTo errors out if the record is unloaded', function (assert) { let store = this.owner.lookup('service:store'); - let message; - run(() => { - message = store.push({ - data: { - id: '1', - type: 'message', - relationships: { - user: { - data: { - id: '2', - type: 'user', - }, + let message = store.push({ + data: { + id: '1', + type: 'message', + relationships: { + user: { + data: { + id: '2', + type: 'user', }, }, }, - }); + }, }); assert.expectAssertion(() => { @@ -1142,7 +1115,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1167,7 +1140,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1197,7 +1170,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1222,7 +1195,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1356,7 +1329,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'author', 'url is correct'); assert.ok(true, "The adapter's findBelongsTo method should be called"); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'author', @@ -1399,7 +1372,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.ok(true, "The adapter's findBelongsTo method should be called"); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'author', @@ -1499,7 +1472,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'author-new-link', 'url is correct'); assert.ok(true, "The adapter's findBelongsTo method should be called"); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'author', @@ -1562,7 +1535,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'author-updated-link', 'url is correct'); assert.ok(true, "The adapter's findBelongsTo method should be called"); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'author', @@ -1707,7 +1680,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let adapter = store.adapterFor('application'); adapter.findRecord = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'chapter', @@ -1721,7 +1694,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; adapter.findBelongsTo = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1743,7 +1716,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.strictEqual(book.name, 'book title'); adapter.findBelongsTo = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1785,7 +1758,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); adapter.findRecord = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1828,7 +1801,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); adapter.findRecord = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1842,7 +1815,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.strictEqual(book.name, 'book title'); adapter.findRecord = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'book', @@ -1877,7 +1850,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }, /Encountered a relationship identifier without a type for the belongsTo relationship 'book' on , expected an identifier with type 'book'/); }); - test("belongsTo relationship with links doesn't trigger extra change notifications - #4942", function (assert) { + test("belongsTo relationship with links doesn't trigger extra change notifications - #4942", async function (assert) { class Chapter extends Model { @attr title; @belongsTo('book', { async: true, inverse: 'chapters' }) book; @@ -1886,20 +1859,18 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function let store = this.owner.lookup('service:store'); - run(() => { - store.push({ - data: { - type: 'chapter', - id: '1', - relationships: { - book: { - data: { type: 'book', id: '1' }, - links: { related: '/chapter/1/book' }, - }, + store.push({ + data: { + type: 'chapter', + id: '1', + relationships: { + book: { + data: { type: 'book', id: '1' }, + links: { related: '/chapter/1/book' }, }, }, - included: [{ type: 'book', id: '1' }], - }); + }, + included: [{ type: 'book', id: '1' }], }); let chapter = store.peekRecord('chapter', '1'); @@ -1909,9 +1880,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function count++; }); - run(() => { - chapter.book; - }); + await chapter.book; assert.strictEqual(count, 0); }); diff --git a/tests/main/tests/integration/relationships/one-to-one-test.js b/tests/main/tests/integration/relationships/one-to-one-test.js index d2deb870d77..d1718b0ec36 100644 --- a/tests/main/tests/integration/relationships/one-to-one-test.js +++ b/tests/main/tests/integration/relationships/one-to-one-test.js @@ -1,9 +1,6 @@ -// eslint-disable-next-line no-restricted-imports -import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -29,7 +26,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); const ApplicationAdapter = Adapter.extend({ - deleteRecord: () => resolve(), + deleteRecord: () => Promise.resolve(), }); const ApplicationSerializer = class extends JSONAPISerializer {}; @@ -45,41 +42,39 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun Server loading tests */ - test('Relationship is available from both sides even if only loaded from one side - async', function (assert) { + test('Relationship is available from both sides even if only loaded from one side - async', async function (assert) { let store = this.owner.lookup('service:store'); var stanley, stanleysFriend; - run(function () { - stanley = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - bestFriend: { - data: { - id: '2', - type: 'user', - }, + stanley = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: '2', + type: 'user', }, }, }, - }); - stanleysFriend = store.push({ - data: { - id: '2', - type: 'user', - attributes: { - name: "Stanley's friend", - }, + }, + }); + stanleysFriend = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: "Stanley's friend", }, - }); + }, + }); - stanleysFriend.bestFriend.then(function (fetchedUser) { - assert.strictEqual(fetchedUser, stanley, 'User relationship was set up correctly'); - }); + await stanleysFriend.bestFriend.then(function (fetchedUser) { + assert.strictEqual(fetchedUser, stanley, 'User relationship was set up correctly'); }); }); @@ -87,126 +82,117 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun let store = this.owner.lookup('service:store'); var job, user; - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: true, - }, + job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: true, }, - }); - user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - job: { - data: { - id: '2', - type: 'job', - }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: '2', + type: 'job', }, }, }, - }); + }, }); assert.strictEqual(job.user, user, 'User relationship was set up correctly'); }); - test('Fetching a belongsTo that is set to null removes the record from a relationship - async', function (assert) { + test('Fetching a belongsTo that is set to null removes the record from a relationship - async', async function (assert) { let store = this.owner.lookup('service:store'); var stanleysFriend; - run(function () { - stanleysFriend = store.push({ - data: { - id: '2', - type: 'user', - attributes: { - name: "Stanley's friend", - }, - relationships: { - bestFriend: { - data: { - id: '1', - type: 'user', - }, + stanleysFriend = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: "Stanley's friend", + }, + relationships: { + bestFriend: { + data: { + id: '1', + type: 'user', }, }, }, - }); - store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - bestFriend: { - data: null, - }, + }, + }); + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: null, }, }, - }); - stanleysFriend.bestFriend.then(function (fetchedUser) { - assert.strictEqual(fetchedUser, null, 'User relationship was removed correctly'); - }); + }, + }); + await stanleysFriend.bestFriend.then(function (fetchedUser) { + assert.strictEqual(fetchedUser, null, 'User relationship was removed correctly'); }); }); test('Fetching a belongsTo that is set to null removes the record from a relationship - sync', function (assert) { let store = this.owner.lookup('service:store'); - var job; - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: true, - }, + var job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: true, }, - }); - store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - job: { - data: { - id: '2', - type: 'job', - }, + }, + }); + store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: '2', + type: 'job', }, }, }, - }); + }, }); - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: true, - }, - relationships: { - user: { - data: null, - }, + job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: true, + }, + relationships: { + user: { + data: null, }, }, - }); + }, }); assert.strictEqual(job.user, null, 'User relationship was removed correctly'); }); @@ -387,35 +373,31 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun Local edits */ - test('Setting a OneToOne relationship reflects correctly on the other side- async', function (assert) { + test('Setting a OneToOne relationship reflects correctly on the other side- async', async function (assert) { let store = this.owner.lookup('service:store'); var stanley, stanleysFriend; - run(function () { - stanley = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, + stanley = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', }, - }); - stanleysFriend = store.push({ - data: { - id: '2', - type: 'user', - attributes: { - name: "Stanley's friend", - }, + }, + }); + stanleysFriend = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: "Stanley's friend", }, - }); + }, }); - run(function () { - stanley.set('bestFriend', stanleysFriend); - stanleysFriend.bestFriend.then(function (fetchedUser) { - assert.strictEqual(fetchedUser, stanley, 'User relationship was updated correctly'); - }); + stanley.set('bestFriend', stanleysFriend); + await stanleysFriend.bestFriend.then(function (fetchedUser) { + assert.strictEqual(fetchedUser, stanley, 'User relationship was updated correctly'); }); }); @@ -423,29 +405,25 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun let store = this.owner.lookup('service:store'); var job, user; - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: true, - }, - }, - }); - user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, + job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: true, }, - }); + }, }); - run(function () { - user.set('job', job); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + }, }); + user.job = job; assert.strictEqual(job.user, user, 'User relationship was set up correctly'); }); @@ -480,56 +458,52 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); assert.expectAssertion(function () { - stanley.set('bestFriend', resolve(igor)); - }, '[object Object] is not a record instantiated by @ember-data/store'); + stanley.bestFriend = Promise.resolve(igor); + }, '[object Promise] is not a record instantiated by @ember-data/store'); }); - test('Setting a OneToOne relationship to null reflects correctly on the other side - async', function (assert) { + test('Setting a OneToOne relationship to null reflects correctly on the other side - async', async function (assert) { let store = this.owner.lookup('service:store'); var stanley, stanleysFriend; - run(function () { - stanley = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - bestFriend: { - data: { - id: '2', - type: 'user', - }, + stanley = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: '2', + type: 'user', }, }, }, - }); - stanleysFriend = store.push({ - data: { - id: '2', - type: 'user', - attributes: { - name: "Stanley's friend", - }, - relationships: { - bestFriend: { - data: { - id: '1', - type: 'user', - }, + }, + }); + stanleysFriend = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: "Stanley's friend", + }, + relationships: { + bestFriend: { + data: { + id: '1', + type: 'user', }, }, }, - }); + }, }); - run(function () { - stanley.set('bestFriend', null); // :( - stanleysFriend.bestFriend.then(function (fetchedUser) { - assert.strictEqual(fetchedUser, null, 'User relationship was removed correctly'); - }); + stanley.bestFriend = null; // :( + await stanleysFriend.bestFriend.then(function (fetchedUser) { + assert.strictEqual(fetchedUser, null, 'User relationship was removed correctly'); }); }); @@ -537,46 +511,42 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun let store = this.owner.lookup('service:store'); var job, user; - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: false, - }, - relationships: { - user: { - data: { - id: '1', - type: 'user', - }, + job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: false, + }, + relationships: { + user: { + data: { + id: '1', + type: 'user', }, }, }, - }); - user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - job: { - data: { - id: '2', - type: 'job', - }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: '2', + type: 'job', }, }, }, - }); + }, }); - run(function () { - user.set('job', null); - }); + user.job = null; assert.strictEqual(job.user, null, 'User relationship was removed correctly'); }); @@ -646,51 +616,47 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun let store = this.owner.lookup('service:store'); var job, user, newBetterJob; - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: false, - }, + job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: false, }, - }); - user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - job: { - data: { - id: '2', - type: 'job', - }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: '2', + type: 'job', }, }, }, - }); + }, }); assert.strictEqual(job.user, user, 'Job and user initially setup correctly'); - run(function () { - newBetterJob = store.push({ - data: { - id: '3', - type: 'job', - attributes: { - isGood: true, - }, + newBetterJob = store.push({ + data: { + id: '3', + type: 'job', + attributes: { + isGood: true, }, - }); - - newBetterJob.set('user', user); + }, }); + newBetterJob.user = user; + assert.strictEqual(user.job, newBetterJob, 'Job updated correctly'); assert.strictEqual(job.user, null, 'Old relationship nulled out correctly'); assert.strictEqual(newBetterJob.user, user, 'New job setup correctly'); @@ -700,49 +666,43 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun Rollback attributes tests */ - test('Rollbacking attributes of deleted record restores the relationship on both sides - async', function (assert) { + test('Rollbacking attributes of deleted record restores the relationship on both sides - async', async function (assert) { let store = this.owner.lookup('service:store'); var stanley, stanleysFriend; - run(function () { - stanley = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - bestFriend: { - data: { - id: '2', - type: 'user', - }, + stanley = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + bestFriend: { + data: { + id: '2', + type: 'user', }, }, }, - }); - stanleysFriend = store.push({ - data: { - id: '2', - type: 'user', - attributes: { - name: "Stanley's friend", - }, + }, + }); + stanleysFriend = store.push({ + data: { + id: '2', + type: 'user', + attributes: { + name: "Stanley's friend", }, - }); + }, }); - run(function () { - stanley.deleteRecord(); + stanley.deleteRecord(); + stanley.rollbackAttributes(); + await stanleysFriend.bestFriend.then(function (fetchedUser) { + assert.strictEqual(fetchedUser, stanley, 'Stanley got rollbacked correctly'); }); - run(function () { - stanley.rollbackAttributes(); - stanleysFriend.bestFriend.then(function (fetchedUser) { - assert.strictEqual(fetchedUser, stanley, 'Stanley got rollbacked correctly'); - }); - stanley.bestFriend.then(function (fetchedUser) { - assert.strictEqual(fetchedUser, stanleysFriend, 'Stanleys friend did not get removed'); - }); + await stanley.bestFriend.then(function (fetchedUser) { + assert.strictEqual(fetchedUser, stanleysFriend, 'Stanleys friend did not get removed'); }); }); @@ -750,38 +710,34 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun let store = this.owner.lookup('service:store'); var job, user; - run(function () { - job = store.push({ - data: { - id: '2', - type: 'job', - attributes: { - isGood: true, - }, + job = store.push({ + data: { + id: '2', + type: 'job', + attributes: { + isGood: true, }, - }); - user = store.push({ - data: { - id: '1', - type: 'user', - attributes: { - name: 'Stanley', - }, - relationships: { - job: { - data: { - id: '2', - type: 'job', - }, + }, + }); + user = store.push({ + data: { + id: '1', + type: 'user', + attributes: { + name: 'Stanley', + }, + relationships: { + job: { + data: { + id: '2', + type: 'job', }, }, }, - }); - }); - run(function () { - job.deleteRecord(); - job.rollbackAttributes(); + }, }); + job.deleteRecord(); + job.rollbackAttributes(); assert.strictEqual(user.job, job, 'Job got rollbacked correctly'); assert.strictEqual(job.user, user, 'Job still has the user'); }); diff --git a/tests/main/tests/integration/store-test.js b/tests/main/tests/integration/store-test.js index 9185e92db8b..3b0ccee6331 100644 --- a/tests/main/tests/integration/store-test.js +++ b/tests/main/tests/integration/store-test.js @@ -1,9 +1,6 @@ -// eslint-disable-next-line no-restricted-imports -import { run } from '@ember/runloop'; import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { Promise, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -37,7 +34,7 @@ class Car extends Model { function ajaxResponse(value) { return function (url, verb, hash) { - return resolve(deepCopy(value)); + return Promise.resolve(deepCopy(value)); }; } @@ -162,7 +159,10 @@ module('integration/store - destroy', function (hooks) { // ensure we make it into the adapter await arrivedPromise; - run(() => store.destroy()); + store.destroy(); + // can't use await settled() since pending promise + // is in the waiter system + await new Promise((r) => setTimeout(r, 0)); // release the adapter promise next(); @@ -409,7 +409,7 @@ module('integration/store - findRecord', function (hooks) { adapter.findRecord = async () => { await timeout(1); if (calls++ < 2) { - return resolve({ + return Promise.resolve({ data: { type: 'car', id: '1', @@ -505,7 +505,7 @@ module('integration/store - findRecord', function (hooks) { async findRecord() { calls++; - await resolve(); + await Promise.resolve(); return { data: { @@ -733,7 +733,7 @@ module('integration/store - findRecord', function (hooks) { }); adapter.ajax = async function () { - await resolve(); + await Promise.resolve(); return deepCopy({ cars: [ @@ -785,7 +785,7 @@ module('integration/store - findAll', function (hooks) { let adapter = store.adapterFor('application'); adapter.ajax = () => { - return resolve({ + return Promise.resolve({ cars: [ { id: '1', @@ -1019,7 +1019,7 @@ module('integration/store - findAll', function (hooks) { }); adapter.ajax = () => { - return resolve({ + return Promise.resolve({ cars: [ { id: '1', @@ -1131,7 +1131,7 @@ module('integration/store - findAll', function (hooks) { let adapter = store.adapterFor('application'); adapter.ajax = () => { - return resolve({ + return Promise.resolve({ cars: [ { id: '20', diff --git a/tests/main/tests/unit/store/push-test.js b/tests/main/tests/unit/store/push-test.js index 2c2ec4a2979..6c32cd87c63 100644 --- a/tests/main/tests/unit/store/push-test.js +++ b/tests/main/tests/unit/store/push-test.js @@ -1,6 +1,3 @@ -// eslint-disable-next-line no-restricted-imports -import { run } from '@ember/runloop'; - import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; @@ -78,7 +75,7 @@ module('unit/store/push - Store#push', function (hooks) { assert.notOk(person.changedAttributes().firstName); }); - test('Calling push with a normalized hash returns a record', function (assert) { + test('Calling push with a normalized hash returns a record', async function (assert) { assert.expect(2); const store = this.owner.lookup('service:store'); @@ -86,34 +83,32 @@ module('unit/store/push - Store#push', function (hooks) { adapter.shouldBackgroundReloadRecord = () => false; - return run(() => { - let person = store.push({ - data: { - type: 'person', - id: 'wat', - attributes: { - firstName: 'Yehuda', - lastName: 'Katz', - }, - }, - }); - - return store.findRecord('person', 'wat').then((foundPerson) => { - assert.strictEqual( - foundPerson, - person, - 'record returned via load() is the same as the record returned from findRecord()' - ); - assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { - id: 'wat', + let person = store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { firstName: 'Yehuda', lastName: 'Katz', - }); + }, + }, + }); + + await store.findRecord('person', 'wat').then((foundPerson) => { + assert.strictEqual( + foundPerson, + person, + 'record returned via push() is the same as the record returned from findRecord()' + ); + assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { + id: 'wat', + firstName: 'Yehuda', + lastName: 'Katz', }); }); }); - test('Calling push with partial records updates just those attributes', function (assert) { + test('Calling push with partial records updates just those attributes', async function (assert) { assert.expect(2); const store = this.owner.lookup('service:store'); @@ -121,41 +116,39 @@ module('unit/store/push - Store#push', function (hooks) { adapter.shouldBackgroundReloadRecord = () => false; - return run(() => { - store.push({ - data: { - type: 'person', - id: 'wat', - attributes: { - firstName: 'Yehuda', - lastName: 'Katz', - }, + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + firstName: 'Yehuda', + lastName: 'Katz', }, - }); + }, + }); - let person = store.peekRecord('person', 'wat'); + let person = store.peekRecord('person', 'wat'); - store.push({ - data: { - type: 'person', - id: 'wat', - attributes: { - lastName: 'Katz!', - }, + store.push({ + data: { + type: 'person', + id: 'wat', + attributes: { + lastName: 'Katz!', }, - }); + }, + }); - return store.findRecord('person', 'wat').then((foundPerson) => { - assert.strictEqual( - foundPerson, - person, - 'record returned via load() is the same as the record returned from findRecord()' - ); - assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { - id: 'wat', - firstName: 'Yehuda', - lastName: 'Katz!', - }); + await store.findRecord('person', 'wat').then((foundPerson) => { + assert.strictEqual( + foundPerson, + person, + 'record returned via load() is the same as the record returned from findRecord()' + ); + assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { + id: 'wat', + firstName: 'Yehuda', + lastName: 'Katz!', }); }); }); @@ -165,26 +158,24 @@ module('unit/store/push - Store#push', function (hooks) { let person; const store = this.owner.lookup('service:store'); - run(() => { - person = store.push({ - data: { - type: 'person', - id: '1', - attributes: { - firstName: 'Robert', - lastName: 'Jackson', - }, + person = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Robert', + lastName: 'Jackson', }, - }); - - store.push( - store.normalize('person', { - id: '1', - firstName: 'Jacquie', - }) - ); + }, }); + store.push( + store.normalize('person', { + id: '1', + firstName: 'Jacquie', + }) + ); + assert.strictEqual(person.firstName, 'Jacquie', 'you can push raw JSON into the store'); assert.strictEqual(person.lastName, 'Jackson', 'existing fields are untouched'); }); @@ -292,20 +283,18 @@ module('unit/store/push - Store#push', function (hooks) { testInDebug('Calling push with a link for a non async relationship should warn if no data', function (assert) { const store = this.owner.lookup('service:store'); assert.expectWarning(() => { - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - relationships: { - phoneNumbers: { - links: { - related: '/api/people/1/phone-numbers', - }, + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + links: { + related: '/api/people/1/phone-numbers', }, }, }, - }); + }, }); }, /You pushed a record of type 'person' with a relationship 'phoneNumbers' configured as 'async: false'. You've included a link but no primary data, this may be an error in your payload. EmberData will treat this relationship as known-to-be-empty./); }); @@ -315,24 +304,22 @@ module('unit/store/push - Store#push', function (hooks) { function (assert) { const store = this.owner.lookup('service:store'); assert.expectNoWarning(() => { - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - relationships: { - phoneNumbers: { - data: [ - { type: 'phone-number', id: '2' }, - { type: 'phone-number', id: '3' }, - ], - links: { - related: '/api/people/1/phone-numbers', - }, + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + data: [ + { type: 'phone-number', id: '2' }, + { type: 'phone-number', id: '3' }, + ], + links: { + related: '/api/people/1/phone-numbers', }, }, }, - }); + }, }); }); } @@ -397,13 +384,11 @@ module('unit/store/push - Store#push', function (hooks) { testInDebug('Calling push with an unknown model name throws an assertion error', function (assert) { const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { - run(() => { - store.push({ - data: { - id: '1', - type: 'unknown', - }, - }); + store.push({ + data: { + id: '1', + type: 'unknown', + }, }); }, "Missing Resource Type: received resource data with a type 'unknown' but no schema could be found with that name."); }); @@ -418,22 +403,20 @@ module('unit/store/push - Store#push', function (hooks) { this.owner.register('model:person', Person); const store = this.owner.lookup('service:store'); - run(() => { - store.push( - store.normalize('person', { - id: '1', - type: 'person', - attributes: { - 'first-name': 'Tan', - }, - relationships: { - 'phone-numbers': { - links: { related: '/api/people/1/phone-numbers' }, - }, + store.push( + store.normalize('person', { + id: '1', + type: 'person', + attributes: { + 'first-name': 'Tan', + }, + relationships: { + 'phone-numbers': { + links: { related: '/api/people/1/phone-numbers' }, }, - }) - ); - }); + }, + }) + ); let person = store.peekRecord('person', 1); @@ -442,24 +425,22 @@ module('unit/store/push - Store#push', function (hooks) { test('Calling push with a link containing the value null', function (assert) { const store = this.owner.lookup('service:store'); - run(() => { - store.push( - store.normalize('person', { - id: '1', - type: 'person', - attributes: { - 'first-name': 'Tan', - }, - relationships: { - 'phone-numbers': { - links: { - related: null, - }, + store.push( + store.normalize('person', { + id: '1', + type: 'person', + attributes: { + 'first-name': 'Tan', + }, + relationships: { + 'phone-numbers': { + links: { + related: null, }, }, - }) - ); - }); + }, + }) + ); let person = store.peekRecord('person', 1); @@ -469,18 +450,16 @@ module('unit/store/push - Store#push', function (hooks) { testInDebug('calling push with hasMany relationship the value must be an array', function (assert) { const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - relationships: { - phoneNumbers: { - data: 1, - }, + store.push({ + data: { + type: 'person', + id: '1', + relationships: { + phoneNumbers: { + data: 1, }, }, - }); + }, }); }); }); @@ -505,18 +484,16 @@ module('unit/store/push - Store#push', function (hooks) { testInDebug('calling push with belongsTo relationship the value must not be an array', function (assert) { const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { - run(() => { - store.push({ - data: { - type: 'phone-number', - id: '1', - relationships: { - person: { - data: [1], - }, + store.push({ + data: { + type: 'phone-number', + id: '1', + relationships: { + person: { + data: [1], }, }, - }); + }, }); }, /must not be an array/); }); @@ -524,18 +501,16 @@ module('unit/store/push - Store#push', function (hooks) { testInDebug('Calling push with unknown keys should not warn by default', function (assert) { const store = this.owner.lookup('service:store'); assert.expectNoWarning(() => { - run(() => { - store.push({ - data: { - type: 'person', - id: '1', - attributes: { - firstName: 'Tomster', - emailAddress: 'tomster@emberjs.com', - isMascot: true, - }, + store.push({ + data: { + type: 'person', + id: '1', + attributes: { + firstName: 'Tomster', + emailAddress: 'tomster@emberjs.com', + isMascot: true, }, - }); + }, }); }, /The payload for 'person' contains these unknown .*: .* Make sure they've been defined in your model./); }); @@ -560,13 +535,11 @@ module('unit/store/push - Store#push', function (hooks) { assert.notOk('modelFor was triggered as a result of a call to store._push'); }; - run(() => { - store._push({ - data: { - id: '1', - type: 'person', - }, - }); + store._push({ + data: { + id: '1', + type: 'person', + }, }); store.modelFor = originalCall; @@ -575,17 +548,13 @@ module('unit/store/push - Store#push', function (hooks) { test('_push returns an array of identifiers if an array is pushed', function (assert) { const store = this.owner.lookup('service:store'); - let pushResult; - - run(() => { - pushResult = store._push({ - data: [ - { - id: '1', - type: 'person', - }, - ], - }); + let pushResult = store._push({ + data: [ + { + id: '1', + type: 'person', + }, + ], }); assert.ok(pushResult instanceof Array); @@ -595,12 +564,8 @@ module('unit/store/push - Store#push', function (hooks) { test('_push returns null if no data is pushed', function (assert) { const store = this.owner.lookup('service:store'); - let pushResult; - - run(() => { - pushResult = store._push({ - data: null, - }); + let pushResult = store._push({ + data: null, }); assert.strictEqual(pushResult, null); @@ -619,30 +584,26 @@ module('unit/store/push - Store#pushPayload', function (hooks) { test('Calling pushPayload allows pushing raw JSON', function (assert) { const store = this.owner.lookup('service:store'); - run(() => { - store.pushPayload('post', { - posts: [ - { - id: '1', - postTitle: 'Ember rocks', - }, - ], - }); + store.pushPayload('post', { + posts: [ + { + id: '1', + postTitle: 'Ember rocks', + }, + ], }); let post = store.peekRecord('post', 1); assert.strictEqual(post.postTitle, 'Ember rocks', 'you can push raw JSON into the store'); - run(() => { - store.pushPayload('post', { - posts: [ - { - id: '1', - postTitle: 'Ember rocks (updated)', - }, - ], - }); + store.pushPayload('post', { + posts: [ + { + id: '1', + postTitle: 'Ember rocks (updated)', + }, + ], }); assert.strictEqual(post.postTitle, 'Ember rocks (updated)', 'You can update data in the store'); @@ -651,26 +612,22 @@ module('unit/store/push - Store#pushPayload', function (hooks) { test('Calling pushPayload allows pushing singular payload properties', function (assert) { const store = this.owner.lookup('service:store'); - run(() => { - store.pushPayload('post', { - post: { - id: '1', - postTitle: 'Ember rocks', - }, - }); + store.pushPayload('post', { + post: { + id: '1', + postTitle: 'Ember rocks', + }, }); let post = store.peekRecord('post', 1); assert.strictEqual(post.postTitle, 'Ember rocks', 'you can push raw JSON into the store'); - run(() => { - store.pushPayload('post', { - post: { - id: '1', - postTitle: 'Ember rocks (updated)', - }, - }); + store.pushPayload('post', { + post: { + id: '1', + postTitle: 'Ember rocks (updated)', + }, }); assert.strictEqual(post.postTitle, 'Ember rocks (updated)', 'You can update data in the store'); @@ -706,21 +663,19 @@ module('unit/store/push - Store#pushPayload', function (hooks) { const store = this.owner.lookup('service:store'); - run(() => { - store.pushPayload('post', { - posts: [ - { - id: '1', - postTitle: 'Ember rocks', - }, - ], - people: [ - { - id: '2', - firstName: 'Yehuda', - }, - ], - }); + store.pushPayload('post', { + posts: [ + { + id: '1', + postTitle: 'Ember rocks', + }, + ], + people: [ + { + id: '2', + firstName: 'Yehuda', + }, + ], }); let post = store.peekRecord('post', '1'); @@ -746,10 +701,8 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ); const store = this.owner.lookup('service:store'); - run(() => { - store.pushPayload({ - posts: [{ id: '1', postTitle: 'Ember rocks' }], - }); + store.pushPayload({ + posts: [{ id: '1', postTitle: 'Ember rocks' }], }); }); @@ -783,21 +736,19 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ); const store = this.owner.lookup('service:store'); - run(() => { - store.pushPayload({ - posts: [ - { - id: '1', - postTitle: 'Ember rocks', - }, - ], - people: [ - { - id: '2', - firstName: 'Yehuda', - }, - ], - }); + store.pushPayload({ + posts: [ + { + id: '1', + postTitle: 'Ember rocks', + }, + ], + people: [ + { + id: '2', + firstName: 'Yehuda', + }, + ], }); var post = store.peekRecord('post', 1); @@ -820,16 +771,14 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ); const store = this.owner.lookup('service:store'); - run(() => { - store.pushPayload('person', { - people: [ - { - id: '1', - firstName: 'Robert', - lastName: 'Jackson', - }, - ], - }); + store.pushPayload('person', { + people: [ + { + id: '1', + firstName: 'Robert', + lastName: 'Jackson', + }, + ], }); let person = store.peekRecord('person', 1); @@ -837,15 +786,13 @@ module('unit/store/push - Store#pushPayload', function (hooks) { assert.strictEqual(person.firstName, 'Robert', 'you can push raw JSON into the store'); assert.strictEqual(person.lastName, 'Jackson', 'you can push raw JSON into the store'); - run(() => { - store.pushPayload('person', { - people: [ - { - id: '1', - firstName: 'Jacquie', - }, - ], - }); + store.pushPayload('person', { + people: [ + { + id: '1', + firstName: 'Jacquie', + }, + ], }); assert.strictEqual(person.firstName, 'Jacquie', 'you can push raw JSON into the store'); @@ -956,25 +903,23 @@ module('unit/store/push - Store#push with JSON-API', function (hooks) { assert.expect(2); const store = this.owner.lookup('service:store'); - run(() => { - store.push({ - data: [ - { - type: 'person', - id: '1', - attributes: { - name: 'Tom Dale', - }, + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tom Dale', }, - { - type: 'person', - id: '2', - attributes: { - name: 'Tomster', - }, + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Tomster', }, - ], - }); + }, + ], }); let tom = store.peekRecord('person', 1); @@ -988,46 +933,44 @@ module('unit/store/push - Store#push with JSON-API', function (hooks) { assert.expect(2); const store = this.owner.lookup('service:store'); - run(() => { - store.push({ - data: [ - { - type: 'person', - id: '1', - attributes: { - name: 'Tomster', - }, - relationships: { - cars: [ - { - data: { - type: 'person', - id: '1', - }, - }, - ], - }, + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Tomster', }, - ], - included: [ - { - type: 'car', - id: '1', - attributes: { - make: 'Dodge', - model: 'Neon', - }, - relationships: { - person: { + relationships: { + cars: [ + { data: { - id: '1', type: 'person', + id: '1', }, }, + ], + }, + }, + ], + included: [ + { + type: 'car', + id: '1', + attributes: { + make: 'Dodge', + model: 'Neon', + }, + relationships: { + person: { + data: { + id: '1', + type: 'person', + }, }, }, - ], - }); + }, + ], }); let tomster = store.peekRecord('person', 1);