diff --git a/package.json b/package.json index b6485b71412..4c5aff65820 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "@glimmer/component": "^1.1.2", "@types/jquery": "^3.5.18", "@types/qunit": "^2.19.6", - "@types/rsvp": "^4.0.4", "@typescript-eslint/eslint-plugin": "^6.6.0", "@typescript-eslint/parser": "^6.6.0", "chalk": "^4.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e82734f4bda..a644b9f8ad0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,9 +65,6 @@ importers: '@types/qunit': specifier: ^2.19.6 version: 2.19.6 - '@types/rsvp': - specifier: ^4.0.4 - version: 4.0.4 '@typescript-eslint/eslint-plugin': specifier: ^6.6.0 version: 6.6.0(@typescript-eslint/parser@6.6.0)(eslint@8.48.0)(typescript@5.2.2) @@ -1890,9 +1887,6 @@ importers: '@types/ember__owner': specifier: ^4.0.5 version: 4.0.5 - '@types/rsvp': - specifier: ^4.0.4 - version: 4.0.4 broccoli-asset-rev: specifier: ^3.0.0 version: 3.0.0 @@ -1998,9 +1992,6 @@ importers: '@types/ember__owner': specifier: ^4.0.5 version: 4.0.5 - '@types/rsvp': - specifier: ^4.0.4 - version: 4.0.4 broccoli-asset-rev: specifier: ^3.0.0 version: 3.0.0 @@ -2624,9 +2615,6 @@ importers: '@types/qunit': specifier: ^2.19.6 version: 2.19.6 - '@types/rsvp': - specifier: ^4.0.4 - version: 4.0.4 broccoli-concat: specifier: ^4.2.5 version: 4.2.5 @@ -14361,9 +14349,6 @@ packages: peerDependencies: route-recognizer: ^0.3.4 rsvp: ^4.8.5 - peerDependenciesMeta: - rsvp: - optional: true dependencies: '@glimmer/env': 0.1.7 route-recognizer: 0.3.4 diff --git a/tests/embroider-basic-compat/package.json b/tests/embroider-basic-compat/package.json index bef297aea84..07ca53ad13d 100644 --- a/tests/embroider-basic-compat/package.json +++ b/tests/embroider-basic-compat/package.json @@ -49,7 +49,6 @@ "@glimmer/tracking": "^1.1.2", "@types/ember": "^4.0.4", "@types/ember__owner": "^4.0.5", - "@types/rsvp": "^4.0.4", "broccoli-asset-rev": "^3.0.0", "ember-cli": "~5.2.1", "ember-cli-babel": "^8.0.0", diff --git a/tests/fastboot/package.json b/tests/fastboot/package.json index 426237adf44..097cfa188ae 100644 --- a/tests/fastboot/package.json +++ b/tests/fastboot/package.json @@ -46,7 +46,6 @@ "@glimmer/tracking": "^1.1.2", "@types/ember": "^4.0.4", "@types/ember__owner": "^4.0.5", - "@types/rsvp": "^4.0.4", "broccoli-asset-rev": "^3.0.0", "ember-cli": "~5.2.1", "ember-cli-babel": "^8.0.0", diff --git a/tests/main/package.json b/tests/main/package.json index f8ff31c122c..faa41baff64 100644 --- a/tests/main/package.json +++ b/tests/main/package.json @@ -76,7 +76,6 @@ "@types/ember__owner": "^4.0.5", "@types/ember__utils": "^4.0.3", "@types/qunit": "^2.19.6", - "@types/rsvp": "^4.0.4", "broccoli-concat": "^4.2.5", "broccoli-merge-trees": "^4.2.0", "broccoli-stew": "^3.0.0", diff --git a/tests/main/tests/integration/adapter/find-all-test.js b/tests/main/tests/integration/adapter/find-all-test.js index a298da7c6ca..e7168942695 100644 --- a/tests/main/tests/integration/adapter/find-all-test.js +++ b/tests/main/tests/integration/adapter/find-all-test.js @@ -1,11 +1,11 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import Model, { attr } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import JSONAPISerializer from '@ember-data/serializer/json-api'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; @@ -157,7 +157,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); test('isUpdating is true while records are fetched', async function (assert) { - let findAllDeferred = defer(); + let findAllDeferred = createDeferred(); let adapter = store.adapterFor('person'); adapter.findAll = () => findAllDeferred.promise; adapter.shouldReloadAll = () => true; @@ -186,7 +186,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); test('isUpdating is true while records are fetched in the background', async function (assert) { - let findAllDeferred = defer(); + let findAllDeferred = createDeferred(); let adapter = store.adapterFor('person'); adapter.findAll = () => { return findAllDeferred.promise; @@ -223,7 +223,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); test('isUpdating is false if records are not fetched in the background', async function (assert) { - let findAllDeferred = defer(); + let findAllDeferred = createDeferred(); let adapter = store.adapterFor('person'); adapter.findAll = () => { return findAllDeferred.promise; diff --git a/tests/main/tests/integration/adapter/record-persistence-test.js b/tests/main/tests/integration/adapter/record-persistence-test.js index 9d57073e3c6..31f1b7d762d 100644 --- a/tests/main/tests/integration/adapter/record-persistence-test.js +++ b/tests/main/tests/integration/adapter/record-persistence-test.js @@ -1,5 +1,4 @@ import { module, test } from 'qunit'; -import { hash } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -233,10 +232,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( ], }); - let { tom, yehuda } = await hash({ - tom: store.findRecord('person', '1'), - yehuda: store.findRecord('person', '2'), - }); + let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); tom.set('name', 'Draaaaaahm Dale'); yehuda.set('name', 'Goy Katz'); @@ -309,10 +305,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( ], }); - let { tom, yehuda } = await hash({ - tom: store.findRecord('person', '1'), - yehuda: store.findRecord('person', '2'), - }); + let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); assert.false(tom.isDeleted, 'Tom is not deleted'); assert.false(yehuda.isDeleted, 'Yehuda is not deleted'); diff --git a/tests/main/tests/integration/adapter/store-adapter-test.js b/tests/main/tests/integration/adapter/store-adapter-test.js index d5d1a947cbd..3d6c4ef66a4 100644 --- a/tests/main/tests/integration/adapter/store-adapter-test.js +++ b/tests/main/tests/integration/adapter/store-adapter-test.js @@ -1,7 +1,6 @@ import { get, set } from '@ember/object'; import { module, test } from 'qunit'; -import { hash } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -117,14 +116,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration let tom = store.createRecord('person', { name: 'Tom Dale' }); let yehuda = store.createRecord('person', { name: 'Yehuda Katz' }); - let promise = hash({ - tom: tom.save(), - yehuda: yehuda.save(), - }); - - let records = await promise; - tom = records.tom; - yehuda = records.yehuda; + [tom, yehuda] = await Promise.all([tom.save(), yehuda.save()]); assert.strictEqual( tom, @@ -184,25 +176,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ], }); - let promise = hash({ - tom: store.findRecord('person', '1'), - yehuda: store.findRecord('person', '2'), - }); - - let records1 = await promise; - let tom = records1.tom; - let yehuda = records1.yehuda; + let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); set(tom, 'name', 'Tom Dale'); set(yehuda, 'name', 'Yehuda Katz'); - let records2 = await hash({ - tom: tom.save(), - yehuda: yehuda.save(), - }); - - let tom2 = records2.tom; - let yehuda2 = records2.yehuda; + let [tom2, yehuda2] = await Promise.all([tom.save(), yehuda.save()]); assert.false(tom2.isSaving, 'record is no longer saving'); assert.true(tom2.isLoaded, 'record is loaded'); @@ -319,19 +298,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ], }); - let promise = hash({ - tom: store.findRecord('person', '1'), - yehuda: store.findRecord('person', '2'), - }); - - let records = await promise; - let tom = records.tom; - let yehuda = records.yehuda; + let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); tom.deleteRecord(); yehuda.deleteRecord(); - return Promise.all([tom.save(), yehuda.save()]); + await Promise.all([tom.save(), yehuda.save()]); }); test('by default, destroyRecord calls deleteRecord once per record without requiring .save', async function (assert) { @@ -379,16 +351,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ], }); - let promise = hash({ - tom: store.findRecord('person', '1'), - yehuda: store.findRecord('person', '2'), - }); - - let records = await promise; - let tom = records.tom; - let yehuda = records.yehuda; + let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); - return Promise.all([tom.destroyRecord(), yehuda.destroyRecord()]); + await Promise.all([tom.destroyRecord(), yehuda.destroyRecord()]); }); test('if an existing model is edited then deleted, deleteRecord is called on the adapter', async function (assert) { diff --git a/tests/main/tests/integration/identifiers/lid-reflection-test.ts b/tests/main/tests/integration/identifiers/lid-reflection-test.ts index 130c023f820..c859fe42da0 100644 --- a/tests/main/tests/integration/identifiers/lid-reflection-test.ts +++ b/tests/main/tests/integration/identifiers/lid-reflection-test.ts @@ -1,13 +1,13 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import Adapter from '@ember-data/adapter'; import type { Snapshot } from '@ember-data/legacy-compat/-private'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import type Store from '@ember-data/store'; import { recordIdentifierFor } from '@ember-data/store'; @@ -79,8 +79,8 @@ module('Integration | Identifiers - lid reflection', function (hooks: NestedHook }); test(`A newly created record can receive a payload by lid (after save, before Adapter.createRecord resolves)`, async function (assert: Assert) { - const adapterPromise = defer(); - const beganSavePromise = defer(); + const adapterPromise = createDeferred(); + const beganSavePromise = createDeferred(); class TestSerializer extends EmberObject { normalizeResponse(_, __, payload: Record) { return payload; @@ -88,7 +88,7 @@ module('Integration | Identifiers - lid reflection', function (hooks: NestedHook } class TestAdapter extends Adapter { createRecord(store, ModelClass, snapshot: Snapshot) { - beganSavePromise.resolve(); + beganSavePromise.resolve(void 0); return adapterPromise.promise.then(() => { return { data: { @@ -138,7 +138,7 @@ module('Integration | Identifiers - lid reflection', function (hooks: NestedHook assert.strictEqual(record.name, 'Chris', 'We use the in-flight name, rollback has no effect'); - adapterPromise.resolve(); + adapterPromise.resolve(void 0); await savePromise; assert.strictEqual(record.name, '@runspired', 'After we finish we use the most recent clean name'); diff --git a/tests/main/tests/integration/records/save-test.js b/tests/main/tests/integration/records/save-test.js index 8a42c989f84..660efe9d945 100644 --- a/tests/main/tests/integration/records/save-test.js +++ b/tests/main/tests/integration/records/save-test.js @@ -1,13 +1,13 @@ import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import Adapter from '@ember-data/adapter'; import { InvalidError } from '@ember-data/adapter/error'; import Model, { attr } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import JSONAPISerializer from '@ember-data/serializer/json-api'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; @@ -29,7 +29,7 @@ module('integration/records/save - Save Record', function (hooks) { let adapter = store.adapterFor('application'); let post = store.createRecord('post', { title: 'toto' }); - const deferred = defer(); + const deferred = createDeferred(); adapter.createRecord = function (store, type, snapshot) { return deferred.promise; }; diff --git a/tests/main/tests/integration/records/unload-test.js b/tests/main/tests/integration/records/unload-test.js index ddb27be7e78..3df2f5d90e9 100644 --- a/tests/main/tests/integration/records/unload-test.js +++ b/tests/main/tests/integration/records/unload-test.js @@ -1,12 +1,6 @@ -/*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'; import { module, test } from 'qunit'; -import { all, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -207,8 +201,6 @@ module('integration/unload - Unloading Records', function (hooks) { }, ], }); - let adam = store.peekRecord('person', 1); - let bob = store.peekRecord('person', 2); car = store.push({ data: { @@ -225,7 +217,6 @@ module('integration/unload - Unloading Records', function (hooks) { }, }, }); - 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'); @@ -274,8 +265,6 @@ module('integration/unload - Unloading Records', function (hooks) { }, ], }); - let adam = store.peekRecord('person', '1'); - let bob = store.peekRecord('person', '2'); store.push({ data: { @@ -292,7 +281,6 @@ module('integration/unload - Unloading Records', function (hooks) { }, }, }); - 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'); @@ -736,7 +724,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(relationshipState.remoteState.length, 1, 'remoteMembers size should be 1'); assert.strictEqual(relationshipState.additions, null, 'additions should be empty'); assert.strictEqual(relationshipState.removals, null, 'removals should be empty'); - assert.strictEqual(get(peopleBoats, 'length'), 1, 'Our person has a boat'); + assert.strictEqual(peopleBoats.length, 1, 'Our person has a boat'); assert.strictEqual(peopleBoats.at(0), boat, 'Our person has the right boat'); assert.strictEqual(boatPerson, person, 'Our boat has the right person'); @@ -746,7 +734,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(relationshipState.remoteState.length, 1, 'remoteMembers size should still be 1'); assert.strictEqual(relationshipState.additions, null, 'additions should be empty'); assert.strictEqual(relationshipState.removals, null, 'removals should be empty'); - assert.strictEqual(get(peopleBoats, 'length'), 0, 'Our person thinks they have no boats'); + assert.strictEqual(peopleBoats.length, 0, 'Our person thinks they have no boats'); store.push({ data: makeBoatOneForPersonOne(), @@ -758,7 +746,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(relationshipState.remoteState.length, 1, 'remoteMembers size should still be 1'); assert.strictEqual(relationshipState.additions, null, 'additions should be empty'); assert.strictEqual(relationshipState.removals, null, 'removals should be empty'); - assert.strictEqual(get(peopleBoats, 'length'), 1, 'Our person has their boats'); + assert.strictEqual(peopleBoats.length, 1, 'Our person has their boats'); }); test('unloadAll(type) does not leave stranded internalModels in relationships (rediscover via relationship reload)', async function (assert) { @@ -767,7 +755,7 @@ module('integration/unload - Unloading Records', function (hooks) { adapter.findRecord = (store, type, id) => { assert.strictEqual(type.modelName, 'boat', 'We refetch the boat'); assert.strictEqual(id, '1', 'We refetch the right boat'); - return resolve({ + return Promise.resolve({ data: makeBoatOneForPersonOne(), }); }; @@ -854,7 +842,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should be 1'); - assert.strictEqual(get(peopleBoats, 'length'), 1, 'Our person has a boat'); + assert.strictEqual(peopleBoats.length, 1, 'Our person has a boat'); assert.strictEqual(peopleBoats.at(0), boat, 'Our person has the right boat'); assert.strictEqual(boatPerson, person, 'Our boat has the right person'); @@ -863,7 +851,7 @@ module('integration/unload - Unloading Records', function (hooks) { // 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'); + assert.strictEqual(peopleBoats.length, 0, 'Our person thinks they have no boats'); store.push({ data: makeBoatOneForPersonOne(), @@ -873,25 +861,25 @@ module('integration/unload - Unloading Records', function (hooks) { assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should be 1'); - assert.strictEqual(get(peopleBoats, 'length'), 1, 'Our person thas their boat'); + assert.strictEqual(peopleBoats.length, 1, 'Our person thas their boat'); // and now the kicker, run-loop fun! // here, we will dematerialize the record, but push it back into the store // all in the same run-loop! // effectively this tests that our destroySync is not stupid - run(() => { - reloadedBoat.unloadRecord(); - store.push({ - data: makeBoatOneForPersonOne(), - }); + await settled(); + reloadedBoat.unloadRecord(); + store.push({ + data: makeBoatOneForPersonOne(), }); + await settled(); boat = store.peekRecord('boat', '1'); assert.notStrictEqual(boat, null, 'we have a boat'); assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should be 1'); - assert.strictEqual(get(peopleBoats, 'length'), 1, 'Our person thas their boat'); + assert.strictEqual(peopleBoats.length, 1, 'Our person thas their boat'); // and the other way too! // and now the kicker, run-loop fun! @@ -899,23 +887,23 @@ module('integration/unload - Unloading Records', function (hooks) { // all in the same run-loop! // effectively this tests that our destroySync is not stupid let newPerson; - run(() => { - person.unloadRecord(); - newPerson = store.push({ - data: { - type: 'person', - id: '1', - attributes: { - name: 'Could be Anybody', - }, - relationships: { - boats: { - data: [{ type: 'boat', id: '1' }], - }, + await settled(); + person.unloadRecord(); + newPerson = store.push({ + data: { + type: 'person', + id: '1', + attributes: { + name: 'Could be Anybody', + }, + relationships: { + boats: { + data: [{ type: 'boat', id: '1' }], }, }, - }); + }, }); + await settled(); const relatedPerson = await boat.person; assert.notStrictEqual(relatedPerson, person, 'the original record is gone'); @@ -1128,7 +1116,7 @@ module('integration/unload - Unloading Records', function (hooks) { // stub findRecord adapter.findRecord = () => { - return resolve({ + return Promise.resolve({ data: { type: 'person', id: '1', @@ -1169,7 +1157,7 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('after unloading a record, the record can be saved again immediately', async function (assert) { - assert.expect(0); + assert.expect(1); const data = { data: { @@ -1181,7 +1169,7 @@ module('integration/unload - Unloading Records', function (hooks) { }, }; - adapter.createRecord = () => resolve(data); + adapter.createRecord = () => Promise.resolve(data); // add an initial record with id '1' to the store store.push(data); @@ -1191,6 +1179,7 @@ module('integration/unload - Unloading Records', function (hooks) { // create a new record that will again get id '1' from the backend await store.createRecord('person').save(); + assert.ok(true, 'it worked'); }); test('after unloading a record, pushing a new copy will setup relationships', function (assert) { @@ -1222,46 +1211,42 @@ module('integration/unload - Unloading Records', function (hooks) { }); } - run(() => { - store.push(personData); - }); + store.push(personData); let adam = store.peekRecord('person', 1); assert.strictEqual(adam.cars.length, 0, 'cars hasMany starts off empty'); - run(() => pushCar()); + pushCar(); assert.strictEqual(adam.cars.length, 1, 'pushing car setups inverse relationship'); - run(() => adam.cars.at(0).unloadRecord()); + adam.cars.at(0).unloadRecord(); assert.strictEqual(adam.cars.length, 0, 'unloading car cleaned up hasMany'); - run(() => pushCar()); + pushCar(); assert.strictEqual(adam.cars.length, 1, 'pushing car again setups inverse relationship'); }); test('1:1 sync unload', function (assert) { - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - house: { - data: { - id: '2', - type: 'house', - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + house: { + data: { + id: '2', + type: 'house', }, }, }, - included: [ - { - id: '2', - type: 'house', - }, - ], - }) - ); + }, + included: [ + { + id: '2', + type: 'house', + }, + ], + }); let person = store.peekRecord('person', 1); let house = store.peekRecord('house', 2); @@ -1269,78 +1254,72 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(person.house.id, '2', 'initially relationship established lhs'); assert.strictEqual(house.person.id, '1', 'initially relationship established rhs'); - run(() => house.unloadRecord()); + house.unloadRecord(); assert.strictEqual(person.house, null, 'unloading acts as a delete for sync relationships'); assert.strictEqual(store.peekRecord('house', '2'), null, 'unloaded record gone from store'); - house = run(() => - store.push({ - data: { - id: '2', - type: 'house', - }, - }) - ); + house = store.push({ + data: { + id: '2', + type: 'house', + }, + }); assert.notStrictEqual(store.peekRecord('house', '2'), null, 'unloaded record can be restored'); assert.strictEqual(person.house, null, 'restoring unloaded record does not restore relationship'); assert.strictEqual(house.person, null, 'restoring unloaded record does not restore relationship'); - run(() => - store.push({ - data: { - id: '2', - type: 'house', - relationships: { - person: { - data: { - id: '1', - type: 'person', - }, + store.push({ + data: { + id: '2', + type: 'house', + relationships: { + person: { + data: { + id: '1', + type: 'person', }, }, }, - }) - ); + }, + }); assert.strictEqual(person.house.id, '2', 'after unloading, relationship can be restored'); assert.strictEqual(house.person.id, '1', 'after unloading, relationship can be restored'); }); test('1:many sync unload 1 side', function (assert) { - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - cars: { - data: [ - { - id: '2', - type: 'car', - }, - { - id: '3', - type: 'car', - }, - ], - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + cars: { + data: [ + { + id: '2', + type: 'car', + }, + { + id: '3', + type: 'car', + }, + ], }, }, - included: [ - { - id: '2', - type: 'car', - }, - { - id: '3', - type: 'car', - }, - ], - }) - ); + }, + included: [ + { + id: '2', + type: 'car', + }, + { + id: '3', + type: 'car', + }, + ], + }); let person = store.peekRecord('person', 1); let car2 = store.peekRecord('car', 2); @@ -1356,7 +1335,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(car2.person.id, '1', 'initially relationship established rhs'); assert.strictEqual(car3.person.id, '1', 'initially relationship established rhs'); - run(() => person.unloadRecord()); + person.unloadRecord(); assert.strictEqual(store.peekRecord('person', '1'), null, 'unloaded record gone from store'); @@ -1364,14 +1343,12 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(car3.person, null, 'unloading acts as delete for sync relationships'); assert.true(cars.isDestroyed, 'ManyArray destroyed'); - person = run(() => - store.push({ - data: { - id: '1', - type: 'person', - }, - }) - ); + person = store.push({ + data: { + id: '1', + type: 'person', + }, + }); assert.notStrictEqual(store.peekRecord('person', '1'), null, 'unloaded record can be restored'); assert.deepEqual( @@ -1382,28 +1359,26 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(car2.person, null, 'restoring unloaded record does not restore relationship'); assert.strictEqual(car3.person, null, 'restoring unloaded record does not restore relationship'); - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - cars: { - data: [ - { - id: '2', - type: 'car', - }, - { - id: '3', - type: 'car', - }, - ], - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + cars: { + data: [ + { + id: '2', + type: 'car', + }, + { + id: '3', + type: 'car', + }, + ], }, }, - }) - ); + }, + }); assert.strictEqual(car2.person.id, '1', 'after unloading, relationship can be restored'); assert.strictEqual(car3.person.id, '1', 'after unloading, relationship can be restored'); @@ -1415,38 +1390,36 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('1:many sync unload many side', function (assert) { - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - cars: { - data: [ - { - id: '2', - type: 'car', - }, - { - id: '3', - type: 'car', - }, - ], - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + cars: { + data: [ + { + id: '2', + type: 'car', + }, + { + id: '3', + type: 'car', + }, + ], }, }, - included: [ - { - id: '2', - type: 'car', - }, - { - id: '3', - type: 'car', - }, - ], - }) - ); + }, + included: [ + { + id: '2', + type: 'car', + }, + { + id: '3', + type: 'car', + }, + ], + }); let person = store.peekRecord('person', 1); let car2 = store.peekRecord('car', 2); @@ -1462,7 +1435,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(car2.person.id, '1', 'initially relationship established rhs'); assert.strictEqual(car3.person.id, '1', 'initially relationship established rhs'); - run(() => car2.unloadRecord()); + car2.unloadRecord(); assert.strictEqual(store.peekRecord('car', '2'), null, 'unloaded record gone from store'); @@ -1474,46 +1447,41 @@ module('integration/unload - Unloading Records', function (hooks) { ); assert.strictEqual(car3.person.id, '1', 'unloading one of a sync hasMany does not affect the rest'); - car2 = run(() => - store.push({ - data: { - id: '2', - type: 'car', - }, - }) - ); - - assert.notStrictEqual(store.peekRecord('car', '2'), null, 'unloaded record can be restored'); - assert.deepEqual( - person.cars.map((r) => r.id), + car2 = store.push({ + data: { + id: '2', + type: 'car', + }, + }); + + assert.notStrictEqual(store.peekRecord('car', '2'), null, 'unloaded record can be restored'); + assert.deepEqual( + person.cars.map((r) => r.id), ['3'], 'restoring unloaded record does not restore relationship' ); assert.strictEqual(car2.person, null, 'restoring unloaded record does not restore relationship'); - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - cars: { - data: [ - { - id: '2', - type: 'car', - }, - { - id: '3', - type: 'car', - }, - ], - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + cars: { + data: [ + { + id: '2', + type: 'car', + }, + { + id: '3', + type: 'car', + }, + ], }, }, - }) - ); - + }, + }); assert.strictEqual(car2.person.id, '1', 'after unloading, relationship can be restored'); assert.deepEqual( person.cars.map((r) => r.id), @@ -1523,58 +1491,56 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('many:many sync unload', function (assert) { - run(() => - store.push({ - data: [ - { - id: '1', - type: 'person', - relationships: { - groups: { - data: [ - { - id: '3', - type: 'group', - }, - { - id: '4', - type: 'group', - }, - ], - }, + store.push({ + data: [ + { + id: '1', + type: 'person', + relationships: { + groups: { + data: [ + { + id: '3', + type: 'group', + }, + { + id: '4', + type: 'group', + }, + ], }, }, - { - id: '2', - type: 'person', - relationships: { - groups: { - data: [ - { - id: '3', - type: 'group', - }, - { - id: '4', - type: 'group', - }, - ], - }, + }, + { + id: '2', + type: 'person', + relationships: { + groups: { + data: [ + { + id: '3', + type: 'group', + }, + { + id: '4', + type: 'group', + }, + ], }, }, - ], - included: [ - { - id: '3', - type: 'group', - }, - { - id: '4', - type: 'group', - }, - ], - }) - ); + }, + ], + included: [ + { + id: '3', + type: 'group', + }, + { + id: '4', + type: 'group', + }, + ], + }); let person1 = store.peekRecord('person', 1); let person2 = store.peekRecord('person', 2); @@ -1607,7 +1573,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.false(p2groups.isDestroyed, 'groups is not destroyed'); assert.false(g3people.isDestroyed, 'people is not destroyed'); - run(() => person2.unloadRecord()); + person2.unloadRecord(); assert.true(p2groups.isDestroyed, 'groups (unloaded side) is destroyed'); assert.false(g3people.isDestroyed, 'people (inverse) is not destroyed'); @@ -1630,14 +1596,12 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(store.peekRecord('person', '2'), null, 'unloading removes record from store'); - person2 = run(() => - store.push({ - data: { - id: '2', - type: 'person', - }, - }) - ); + person2 = store.push({ + data: { + id: '2', + type: 'person', + }, + }); assert.notStrictEqual(store.peekRecord('person', '2'), null, 'unloaded record can be restored'); assert.deepEqual( @@ -1656,28 +1620,26 @@ module('integration/unload - Unloading Records', function (hooks) { 'restoring unloaded record does not restore relationship' ); - run(() => - store.push({ - data: { - id: '2', - type: 'person', - relationships: { - groups: { - data: [ - { - id: '3', - type: 'group', - }, - { - id: '4', - type: 'group', - }, - ], - }, + store.push({ + data: { + id: '2', + type: 'person', + relationships: { + groups: { + data: [ + { + id: '3', + type: 'group', + }, + { + id: '4', + type: 'group', + }, + ], }, }, - }) - ); + }, + }); assert.deepEqual( person2.groups.map((r) => r.id), @@ -1696,7 +1658,7 @@ module('integration/unload - Unloading Records', function (hooks) { ); }); - test('1:1 async unload', function (assert) { + test('1:1 async unload', async function (assert) { let findRecordCalls = 0; adapter.findRecord = (store, type, id) => { @@ -1712,48 +1674,44 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - mortgage: { - data: { - id: '2', - type: 'mortgage', - }, + let person = store.push({ + data: { + id: '1', + type: 'person', + relationships: { + mortgage: { + data: { + id: '2', + type: 'mortgage', }, }, }, - }) - ); + }, + }); let mortgage; - return run(() => - person.mortgage - .then((asyncRecord) => { - mortgage = asyncRecord; - return mortgage.person; - }) - .then(() => { - assert.strictEqual(mortgage.belongsTo('person').id(), '1', 'initially relationship established lhs'); - assert.strictEqual(person.belongsTo('mortgage').id(), '2', 'initially relationship established rhs'); - - run(() => mortgage.unloadRecord()); - - assert.strictEqual(person.belongsTo('mortgage').id(), '2', 'unload async is not treated as delete'); - - return person.mortgage; - }) - .then((refetchedMortgage) => { - assert.notEqual(mortgage, refetchedMortgage, 'the previously loaded record is not reused'); - - assert.strictEqual(person.belongsTo('mortgage').id(), '2', 'unload async is not treated as delete'); - assert.strictEqual(refetchedMortgage.belongsTo('person').id(), '1', 'unload async is not treated as delete'); - assert.strictEqual(findRecordCalls, 2); - }) - ); + await person.mortgage + .then((asyncRecord) => { + mortgage = asyncRecord; + return mortgage.person; + }) + .then(() => { + assert.strictEqual(mortgage.belongsTo('person').id(), '1', 'initially relationship established lhs'); + assert.strictEqual(person.belongsTo('mortgage').id(), '2', 'initially relationship established rhs'); + + mortgage.unloadRecord(); + + assert.strictEqual(person.belongsTo('mortgage').id(), '2', 'unload async is not treated as delete'); + + return person.mortgage; + }) + .then((refetchedMortgage) => { + assert.notEqual(mortgage, refetchedMortgage, 'the previously loaded record is not reused'); + + assert.strictEqual(person.belongsTo('mortgage').id(), '2', 'unload async is not treated as delete'); + assert.strictEqual(refetchedMortgage.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + assert.strictEqual(findRecordCalls, 2); + }); }); test('1:many async unload 1 side', async function (assert) { @@ -1827,7 +1785,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.false(boats.isDestroyed, 'ManyArray is not destroyed'); - run(() => person.unloadRecord()); + person.unloadRecord(); assert.true(boats.isDestroyed, 'ManyArray is destroyed when 1 side is unloaded'); assert.strictEqual(boat2.belongsTo('person').id(), '1', 'unload async is not treated as delete'); @@ -2015,7 +1973,7 @@ module('integration/unload - Unloading Records', function (hooks) { const person1Friends = await person1.friends; const [person3, person4] = person1Friends.slice(); - await all([person2.friends, person3.friends, person4.friends]); + await Promise.all([person2.friends, person3.friends, person4.friends]); assert.deepEqual(person1.hasMany('friends').ids(), ['3', '4'], 'initially relationship established lhs'); assert.deepEqual(person2.hasMany('friends').ids(), ['3', '4'], 'initially relationship established lhs'); @@ -2127,7 +2085,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(bookPerson?.id, '1', 'after unloading, relationship can be restored'); }); - test('1 sync : 1 async unload async side', function (assert) { + test('1 sync : 1 async unload async side', async function (assert) { let findRecordCalls = 0; adapter.findRecord = (store, type, id) => { @@ -2143,87 +2101,81 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - favoriteBook: { - data: { - id: '2', - type: 'book', - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + favoriteBook: { + data: { + id: '2', + type: 'book', }, }, }, - included: [ - { - id: '2', - type: 'book', - }, - ], - }) - ); + }, + included: [ + { + id: '2', + type: 'book', + }, + ], + }); let person = store.peekRecord('person', 1); let book = store.peekRecord('book', 2); - return run(() => - book.person - .then(() => { - assert.strictEqual(person.favoriteBook.id, '2', 'initially relationship established lhs'); - assert.strictEqual(book.belongsTo('person').id(), '1', 'initially relationship established rhs'); + await book.person + .then(() => { + assert.strictEqual(person.favoriteBook.id, '2', 'initially relationship established lhs'); + assert.strictEqual(book.belongsTo('person').id(), '1', 'initially relationship established rhs'); - run(() => person.unloadRecord()); + person.unloadRecord(); - assert.strictEqual(book.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + assert.strictEqual(book.belongsTo('person').id(), '1', 'unload async is not treated as delete'); - return book.person; - }) - .then((refetchedPerson) => { - assert.notEqual(person, refetchedPerson, 'the previously loaded record is not reused'); + return book.person; + }) + .then((refetchedPerson) => { + assert.notEqual(person, refetchedPerson, 'the previously loaded record is not reused'); - assert.strictEqual(book.belongsTo('person').id(), '1', 'unload async is not treated as delete'); - assert.strictEqual(refetchedPerson.favoriteBook.id, '2', 'unload async is not treated as delete'); - assert.strictEqual(findRecordCalls, 1); - }) - ); + assert.strictEqual(book.belongsTo('person').id(), '1', 'unload async is not treated as delete'); + assert.strictEqual(refetchedPerson.favoriteBook.id, '2', 'unload async is not treated as delete'); + assert.strictEqual(findRecordCalls, 1); + }); }); test('1 async : many sync unload sync side', function (assert) { - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - favoriteSpoons: { - data: [ - { - id: '2', - type: 'spoon', - }, - { - id: '3', - type: 'spoon', - }, - ], - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + favoriteSpoons: { + data: [ + { + id: '2', + type: 'spoon', + }, + { + id: '3', + type: 'spoon', + }, + ], }, }, - included: [ - { - id: '2', - type: 'spoon', - }, - { - id: '3', - type: 'spoon', - }, - ], - }) - ); + }, + included: [ + { + id: '2', + type: 'spoon', + }, + { + id: '3', + type: 'spoon', + }, + ], + }); let person = store.peekRecord('person', 1); let spoon2 = store.peekRecord('spoon', 2); @@ -2239,7 +2191,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(spoon2.belongsTo('person').id(), '1', 'initially relationship established rhs'); assert.strictEqual(spoon3.belongsTo('person').id(), '1', 'initially relationship established rhs'); - run(() => spoon2.unloadRecord()); + spoon2.unloadRecord(); assert.strictEqual(store.peekRecord('spoon', '2'), null, 'unloaded record gone from store'); @@ -2255,14 +2207,12 @@ module('integration/unload - Unloading Records', function (hooks) { 'unloading one of a sync hasMany does not affect the rest' ); - spoon2 = run(() => - store.push({ - data: { - id: '2', - type: 'spoon', - }, - }) - ); + spoon2 = store.push({ + data: { + id: '2', + type: 'spoon', + }, + }); assert.notStrictEqual(store.peekRecord('spoon', '2'), null, 'unloaded record can be restored'); assert.deepEqual( @@ -2276,28 +2226,26 @@ module('integration/unload - Unloading Records', function (hooks) { 'restoring unloaded record does not restore relationship' ); - run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - favoriteSpoons: { - data: [ - { - id: '2', - type: 'spoon', - }, - { - id: '3', - type: 'spoon', - }, - ], - }, + store.push({ + data: { + id: '1', + type: 'person', + relationships: { + favoriteSpoons: { + data: [ + { + id: '2', + type: 'spoon', + }, + { + id: '3', + type: 'spoon', + }, + ], }, }, - }) - ); + }, + }); assert.strictEqual(spoon2.belongsTo('person').id(), '1', 'after unloading, relationship can be restored'); assert.deepEqual( @@ -2597,7 +2545,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(findManyCalls, 1, 'findMany calls as expected'); }); - test('unload invalidates link promises', function (assert) { + test('unload invalidates link promises', async function (assert) { let isUnloaded = false; adapter.coalesceFindRequests = false; @@ -2639,57 +2587,48 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = run(() => - store.push({ - data: { - id: '1', - type: 'person', - relationships: { - boats: { - links: { related: 'boats' }, - }, + let person = store.push({ + data: { + id: '1', + type: 'person', + relationships: { + boats: { + links: { related: 'boats' }, }, }, - }) - ); + }, + }); let boats, boat2, boat3; - return run(() => - person.boats - .then((asyncRecords) => { - boats = asyncRecords; - [boat2, boat3] = boats.slice(); - }) - .then(() => { - assert.deepEqual(person.hasMany('boats').ids(), ['2', '3'], 'initially relationship established rhs'); - assert.strictEqual(boat2.belongsTo('person').id(), '1', 'initially relationship established rhs'); - assert.strictEqual(boat3.belongsTo('person').id(), '1', 'initially relationship established rhs'); - - isUnloaded = true; - run(() => { - boat2.unloadRecord(); - person.boats; - }); - - assert.deepEqual( - boats.map((r) => r.id), - ['3'], - 'unloaded boat is removed from ManyArray' - ); - }) - .then(() => { - return run(() => person.boats); - }) - .then((newBoats) => { - assert.strictEqual(newBoats.length, 1, 'new ManyArray has only 1 boat after unload'); - }) - ); + await person.boats + .then((asyncRecords) => { + boats = asyncRecords; + [boat2, boat3] = boats.slice(); + }) + .then(() => { + assert.deepEqual(person.hasMany('boats').ids(), ['2', '3'], 'initially relationship established rhs'); + assert.strictEqual(boat2.belongsTo('person').id(), '1', 'initially relationship established rhs'); + assert.strictEqual(boat3.belongsTo('person').id(), '1', 'initially relationship established rhs'); + + isUnloaded = true; + boat2.unloadRecord(); + return person.boats; + }) + .then((newBoats) => { + assert.deepEqual( + boats.map((r) => r.id), + ['3'], + 'unloaded boat is removed from ManyArray' + ); + assert.strictEqual(newBoats.length, 1, 'new ManyArray has only 1 boat after unload'); + }); }); - test('fetching records cancels unloading', function (assert) { + test('fetching records cancels unloading', async function (assert) { adapter.findRecord = (store, type, id) => { assert.strictEqual(type, Person, 'findRecord(_, type) is correct'); assert.deepEqual(id, '1', 'findRecord(_, _, id) is correct'); + assert.step('findRecord'); return { data: { @@ -2699,15 +2638,19 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - run(() => - store.push({ - data: { - id: '1', - type: 'person', - }, - }) - ); + store.push({ + data: { + id: '1', + type: 'person', + }, + }); - return run(() => store.findRecord('person', 1, { backgroundReload: true }).then((person) => person.unloadRecord())); + const person = await store.findRecord('person', '1', { backgroundReload: true }); + person.unloadRecord(); + assert.step('unloadRecord'); + await settled(); + assert.verifySteps(['unloadRecord', 'findRecord'], 'steps are correct'); + assert.notStrictEqual(store.peekRecord('person', '1'), null, 'record is still in the store'); + assert.true(person.isDestroyed, 'original record is destroyed'); }); }); diff --git a/tests/main/tests/integration/references/record-test.js b/tests/main/tests/integration/references/record-test.js index edcd6e79edc..ef5774a41f9 100644 --- a/tests/main/tests/integration/references/record-test.js +++ b/tests/main/tests/integration/references/record-test.js @@ -1,12 +1,12 @@ import { get } from '@ember/object'; import { module, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import JSONAPIAdapter from '@ember-data/adapter/json-api'; import Model, { attr } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import JSONAPISerializer from '@ember-data/serializer/json-api'; import { recordIdentifierFor } from '@ember-data/store'; @@ -110,7 +110,7 @@ module('integration/references/record', function (hooks) { let store = this.owner.lookup('service:store'); let Person = store.modelFor('person'); - let deferred = defer(); + let deferred = createDeferred(); let recordReference = store.getReference('person', 1); let pushed = recordReference.push(deferred.promise); diff --git a/tests/main/tests/integration/relationships/belongs-to-test.js b/tests/main/tests/integration/relationships/belongs-to-test.js index d22497227cd..f91246eca39 100644 --- a/tests/main/tests/integration/relationships/belongs-to-test.js +++ b/tests/main/tests/integration/relationships/belongs-to-test.js @@ -1,7 +1,6 @@ import EmberObject from '@ember/object'; import { module, test } from 'qunit'; -import { hash } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -615,12 +614,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }, }); - await hash({ - message: store.findRecord('post', '1'), - comment: store.findRecord('comment', '2'), - }).then((records) => { - assert.strictEqual(records.comment.message, records.message); - }); + const [message, comment] = await Promise.all([store.findRecord('post', '1'), store.findRecord('comment', '2')]); + + assert.strictEqual(comment.message, message); }); test('The store can serialize a polymorphic belongsTo association', async 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 89dbafad28a..d4785a1e2ec 100644 --- a/tests/main/tests/integration/relationships/has-many-test.js +++ b/tests/main/tests/integration/relationships/has-many-test.js @@ -1,9 +1,6 @@ -import { get } 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, Promise as EmberPromise, reject, resolve } from 'rsvp'; import { setupTest } from 'ember-qunit'; @@ -108,7 +105,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( 'adapter:company', JSONAPIAdapter.extend({ findHasMany(store, type, snapshot) { - return resolve({ + return Promise.resolve({ links: { related: 'company/1/employees', }, @@ -156,21 +153,19 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( // test null id assert.expectAssertion(() => { - run(() => { - let post = store.push({ - data: { - id: '1', - type: 'post', - relationships: { - comments: { - data: [{ id: null, type: 'comment' }], - }, + let post = store.push({ + data: { + id: '1', + type: 'post', + relationships: { + comments: { + data: [{ id: null, type: 'comment' }], }, }, - }); - - post.comments; + }, }); + + post.comments; }, /Assertion Failed: Encountered a relationship identifier without an id for the hasMany relationship 'comments' on , expected an identifier but found/); }); @@ -181,20 +176,18 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( // test missing type assert.expectAssertion(() => { - run(() => { - let post = store.push({ - data: { - id: '2', - type: 'post', - relationships: { - comments: { - data: [{ id: '1', type: null }], - }, + let post = store.push({ + data: { + id: '2', + type: 'post', + relationships: { + comments: { + data: [{ id: '1', type: null }], }, }, - }); - post.comments; + }, }); + post.comments; }, /Assertion Failed: Encountered a relationship identifier without a type for the hasMany relationship 'comments' on , expected an identifier with type 'comment' but found/); }); @@ -325,9 +318,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.ok(!user.contacts.initialState || !user.contacts.initialState.find((model) => model.id === '2')); - run(() => { - contacts.push(store.createRecord('user', { id: '8' })); - }); + contacts.push(store.createRecord('user', { id: '8' })); assert.deepEqual( contacts.map((c) => c.id), @@ -397,11 +388,9 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( 'user should have expected contacts' ); - run(() => { - contacts.push(store.createRecord('user', { id: '5' })); - contacts.push(store.createRecord('user', { id: '6' })); - contacts.push(store.createRecord('user', { id: '7' })); - }); + contacts.push(store.createRecord('user', { id: '5' })); + contacts.push(store.createRecord('user', { id: '6' })); + contacts.push(store.createRecord('user', { id: '7' })); assert.deepEqual( contacts.map((c) => c.id), @@ -460,7 +449,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, Chapter, 'type passed to adapter.findMany is correct'); assert.deepEqual(ids, ['2', '3'], 'ids passed to adapter.findMany are unique'); - return resolve({ + return Promise.resolve({ data: [ { id: '2', type: 'chapter', attributes: { title: 'Chapter One' } }, { id: '3', type: 'chapter', attributes: { title: 'Chapter Two' } }, @@ -492,7 +481,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( // relationship as an identifier that it can fetch lazily. The most // common use case of this is to provide a URL to a collection that // is loaded later. - test("A serializer can materialize a hasMany as an opaque token that can be lazily fetched via the adapter's findHasMany hook", function (assert) { + test("A serializer can materialize a hasMany as an opaque token that can be lazily fetched via the adapter's findHasMany hook", async function (assert) { class Post extends Model { @attr title; @hasMany('comment', { async: true, inverse: 'message' }) comments; @@ -514,7 +503,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, Post, 'find type was Post'); assert.strictEqual(id, '1', 'find id was 1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -538,7 +527,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); assert.strictEqual(relationship.type, 'comment', 'relationship was passed correctly'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -546,18 +535,16 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - return run(() => { - return store - .findRecord('post', 1) - .then((post) => { - return post.comments; - }) - .then((comments) => { - assert.true(comments.isLoaded, 'comments are loaded'); - assert.strictEqual(comments.length, 2, 'comments have 2 length'); - assert.strictEqual(comments.at(0).body, 'First', 'comment loaded successfully'); - }); - }); + await store + .findRecord('post', 1) + .then((post) => { + return post.comments; + }) + .then((comments) => { + assert.true(comments.isLoaded, 'comments are loaded'); + assert.strictEqual(comments.length, 2, 'comments have 2 length'); + assert.strictEqual(comments.at(0).body, 'First', 'comment loaded successfully'); + }); }); test('Accessing a hasMany backed by a link multiple times triggers only one request', async function (assert) { @@ -595,7 +582,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( adapter.findHasMany = function (store, snapshot, link, relationship) { count++; assert.strictEqual(count, 1, 'findHasMany has only been called once'); - return new EmberPromise((resolve, reject) => { + return new Promise((resolve, reject) => { setTimeout(() => { let value = { data: [ @@ -625,11 +612,11 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); promise2 = post.comments; - await all([promise1, promise2]); + await Promise.all([promise1, promise2]); assert.strictEqual(promise1.promise, promise2.promise, 'Same promise is returned both times'); }); - test('A hasMany backed by a link remains a promise after a record has been added to it', function (assert) { + test('A hasMany backed by a link remains a promise after a record has been added to it', async function (assert) { assert.expect(1); class Post extends Model { @attr title; @@ -648,7 +635,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -656,46 +643,40 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - let post; - run(() => { + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: '/posts/1/comments', + }, + }, + }, + }, + }); + + await post.comments.then(() => { store.push({ data: { - type: 'post', - id: '1', + type: 'comment', + id: '3', relationships: { - comments: { - links: { - related: '/posts/1/comments', - }, + message: { + data: { type: 'post', id: '1' }, }, }, }, }); - post = store.peekRecord('post', 1); - }); - return run(() => { return post.comments.then(() => { - store.push({ - data: { - type: 'comment', - id: '3', - relationships: { - message: { - data: { type: 'post', id: '1' }, - }, - }, - }, - }); - - return post.comments.then(() => { - assert.ok(true, 'Promise was called'); - }); + assert.ok(true, 'Promise was called'); }); }); }); - test('A hasMany updated link should not remove new children', function (assert) { + test('A hasMany updated link should not remove new children', async function (assert) { class Post extends Model { @attr title; @hasMany('comment', { async: true, inverse: 'message' }) comments; @@ -711,11 +692,11 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { - return resolve({ data: [] }); + return Promise.resolve({ data: [] }); }; adapter.createRecord = function (store, snapshot, link, relationship) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -728,24 +709,22 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - return run(() => { - let post = store.createRecord('post', {}); - store.createRecord('comment', { message: post }); + let post = store.createRecord('post', {}); + store.createRecord('comment', { message: post }); - return post.comments - .then((comments) => { - assert.strictEqual(comments.length, 1, 'initially we have one comment'); + await post.comments + .then((comments) => { + assert.strictEqual(comments.length, 1, 'initially we have one comment'); - return post.save(); - }) - .then(() => post.comments) - .then((comments) => { - assert.strictEqual(comments.length, 1, 'after saving, we still have one comment'); - }); - }); + return post.save(); + }) + .then(() => post.comments) + .then((comments) => { + assert.strictEqual(comments.length, 1, 'after saving, we still have one comment'); + }); }); - test('A hasMany updated link should not remove new children when the parent record has children already', function (assert) { + test('A hasMany updated link should not remove new children when the parent record has children already', async function (assert) { class Post extends Model { @attr title; @hasMany('comment', { async: true, inverse: 'message' }) comments; @@ -762,13 +741,13 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { - return resolve({ + return Promise.resolve({ data: [{ id: '5', type: 'comment', attributes: { body: 'hello' } }], }); }; adapter.createRecord = function (store, snapshot, link, relationship) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -781,23 +760,21 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - return run(() => { - let post = store.createRecord('post', {}); - store.createRecord('comment', { message: post }); + let post = store.createRecord('post', {}); + store.createRecord('comment', { message: post }); - return post.comments - .then((comments) => { - assert.strictEqual(comments.length, 1); - return post.save(); - }) - .then(() => post.comments) - .then((comments) => { - assert.strictEqual(comments.length, 2); - }); - }); + await post.comments + .then((comments) => { + assert.strictEqual(comments.length, 1); + return post.save(); + }) + .then(() => post.comments) + .then((comments) => { + assert.strictEqual(comments.length, 2); + }); }); - test("A hasMany relationship doesn't contain duplicate children, after the canonical state of the relationship is updated via store#push", function (assert) { + test("A hasMany relationship doesn't contain duplicate children, after the canonical state of the relationship is updated via store#push", async function (assert) { class Post extends Model { @attr title; @hasMany('comment', { async: true, inverse: 'message' }) comments; @@ -814,54 +791,52 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.createRecord = function (store, snapshot, link, relationship) { - return resolve({ data: { id: '1', type: 'post' } }); + return Promise.resolve({ data: { id: '1', type: 'post' } }); }; - return run(() => { - let post = store.createRecord('post', {}); + let post = store.createRecord('post', {}); - // create a new comment with id 'local', which is in the 'comments' - // relationship of post - let localComment = store.createRecord('comment', { id: 'local', message: post }); + // create a new comment with id 'local', which is in the 'comments' + // relationship of post + let localComment = store.createRecord('comment', { id: 'local', message: post }); - return post.comments - .then((comments) => { - assert.strictEqual(comments.length, 1); - assert.true(localComment.isNew); + await post.comments + .then((comments) => { + assert.strictEqual(comments.length, 1); + assert.true(localComment.isNew); - return post.save(); - }) - .then(() => { - // Now the post is saved but the locally created comment with the id - // 'local' is still in the created state since it hasn't been saved - // yet. - // - // As next we are pushing the post into the store again, having the - // locally created comment in the 'comments' relationship. By this the - // canonical state of the relationship is defined to consist of one - // comment: the one with id 'local'. - // - // This setup is needed to demonstrate the bug which has been fixed - // in #4154, where the locally created comment was duplicated in the - // comment relationship. - store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - data: [{ id: 'local', type: 'comment' }], - }, + return post.save(); + }) + .then(() => { + // Now the post is saved but the locally created comment with the id + // 'local' is still in the created state since it hasn't been saved + // yet. + // + // As next we are pushing the post into the store again, having the + // locally created comment in the 'comments' relationship. By this the + // canonical state of the relationship is defined to consist of one + // comment: the one with id 'local'. + // + // This setup is needed to demonstrate the bug which has been fixed + // in #4154, where the locally created comment was duplicated in the + // comment relationship. + store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ id: 'local', type: 'comment' }], }, }, - }); - }) - .then(() => post.comments) - .then((comments) => { - assert.strictEqual(comments.length, 1); - assert.true(localComment.isNew); + }, }); - }); + }) + .then(() => post.comments) + .then((comments) => { + assert.strictEqual(comments.length, 1); + assert.true(localComment.isNew); + }); }); test('A hasMany relationship can be reloaded if it was fetched via a link', async function (assert) { @@ -884,7 +859,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, Post, 'find type was Post'); assert.strictEqual(id, '1', 'find id was 1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -902,7 +877,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(relationship.key, 'comments', 'findHasMany relationship key was comments'); assert.strictEqual(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -920,7 +895,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(relationship.key, 'comments', 'findHasMany relationship key was comments'); assert.strictEqual(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -942,7 +917,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, store.modelFor('post'), 'find type was Post'); assert.strictEqual(id, '1', 'find id was 1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -985,7 +960,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(comments.length, 2, 'comments have a length of 2'); adapter.findMany = function (store, type, ids, snapshots) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'FirstUpdated' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1021,7 +996,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, Post, 'find type was Post'); assert.strictEqual(id, '1', 'find id was 1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -1038,7 +1013,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }; adapter.findMany = function (store, type, ids, snapshots) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1056,7 +1031,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(comments.length, 2, 'comments have 2 length'); adapter.findMany = function (store, type, ids, snapshots) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'FirstUpdated' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1089,7 +1064,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.findRecord = function () { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -1106,9 +1081,9 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( adapter.findHasMany = function () { loadingCount++; if (loadingCount % 2 === 1) { - return reject({ data: null }); + return Promise.reject({ data: null }); } else { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'FirstUpdated' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1168,7 +1143,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, Post, 'find type was Post'); assert.strictEqual(id, '1', 'find id was 1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -1184,7 +1159,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( adapter.findHasMany = function (store, record, link, relationship) { assert.strictEqual(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'FirstUpdated' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1220,7 +1195,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -1236,7 +1211,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let count = 0; adapter.findHasMany = function (store, record, link, relationship) { count++; - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1245,7 +1220,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }; await store.findRecord('post', '1').then(function (post) { post.comments.then(function (comments) { - all([comments.reload(), comments.reload(), comments.reload()]).then(function (comments) { + Promise.all([comments.reload(), comments.reload(), comments.reload()]).then(function (comments) { assert.strictEqual( count, 2, @@ -1277,7 +1252,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(type, Post, 'find type was Post'); assert.strictEqual(id, '1', 'find id was 1'); - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -1294,7 +1269,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }; adapter.findMany = function (store, type, ids, snapshots) { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'FirstUpdated' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1331,7 +1306,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'post', @@ -1350,7 +1325,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( let count = 0; adapter.findMany = function (store, type, ids, snapshots) { count++; - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'FirstUpdated' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -1360,7 +1335,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( await store.findRecord('post', '1').then(function (post) { post.comments.then(function (comments) { - all([comments.reload(), comments.reload(), comments.reload()]).then(function (comments) { + Promise.all([comments.reload(), comments.reload(), comments.reload()]).then(function (comments) { assert.strictEqual( count, 2, @@ -1393,14 +1368,14 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(relationship.type, 'comment', 'relationship was passed correctly'); if (link === '/first') { - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, ], }); } else if (link === '/second') { - return resolve({ + return Promise.resolve({ data: [ { id: '3', type: 'comment', attributes: { body: 'Third' } }, { id: '4', type: 'comment', attributes: { body: 'Fourth' } }, @@ -1508,9 +1483,9 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = function (store, type, id, snapshot) { if (type === store.modelFor('post')) { - return resolve({ data: { id: '1', type: 'post' } }); + return Promise.resolve({ data: { id: '1', type: 'post' } }); } else if (type === store.modelFor('comment')) { - return resolve({ data: { id: '3', type: 'comment' } }); + return Promise.resolve({ data: { id: '3', type: 'comment' } }); } }; @@ -2141,32 +2116,30 @@ If using this relationship in a polymorphic manner is desired, the relationships let store = this.owner.lookup('service:store'); let post = store.createRecord('post'); - run(function () { - store.push({ - data: [ - { - type: 'comment', - id: '1', - attributes: { - body: 'First', - }, + store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'First', }, - { - type: 'comment', - id: '2', - attributes: { - body: 'Second', - }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'Second', }, - ], - }); - post.set('comments', store.peekAll('comment').slice()); + }, + ], }); + post.set('comments', store.peekAll('comment').slice()); - assert.strictEqual(get(post, 'comments.length'), 2, 'we can set HM relationship'); + assert.strictEqual(post.comments.length, 2, 'we can set HM relationship'); }); - test('We can set records ASYNC HM relationship', function (assert) { + test('We can set records ASYNC HM relationship', async function (assert) { assert.expect(1); class Post extends Model { @attr title; @@ -2183,52 +2156,47 @@ If using this relationship in a polymorphic manner is desired, the relationships let store = this.owner.lookup('service:store'); let post = store.createRecord('post'); - run(function () { - store.push({ - data: [ - { - type: 'comment', - id: '1', - attributes: { - body: 'First', - }, + store.push({ + data: [ + { + type: 'comment', + id: '1', + attributes: { + body: 'First', }, - { - type: 'comment', - id: '2', - attributes: { - body: 'Second', - }, + }, + { + type: 'comment', + id: '2', + attributes: { + body: 'Second', }, - ], - }); - post.set('comments', store.peekAll('comment').slice()); + }, + ], }); + post.set('comments', store.peekAll('comment').slice()); - return post.comments.then((comments) => { + await post.comments.then((comments) => { assert.strictEqual(comments.length, 2, 'we can set async HM relationship'); }); }); - test('When a record is saved, its unsaved hasMany records should be kept', function (assert) { + test('When a record is saved, its unsaved hasMany records should be kept', async function (assert) { assert.expect(1); let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); adapter.createRecord = function (store, type, snapshot) { - return resolve({ data: { id: '1', type: snapshot.modelName } }); + return Promise.resolve({ data: { id: '1', type: snapshot.modelName } }); }; let post, comment; - return run(() => { - post = store.createRecord('post'); - comment = store.createRecord('comment'); - post.comments.push(comment); - return post.save(); - }).then(() => { - assert.strictEqual(get(post, 'comments.length'), 1, "The unsaved comment should be in the post's comments array"); - }); + post = store.createRecord('post'); + comment = store.createRecord('comment'); + post.comments.push(comment); + await post.save(); + assert.strictEqual(post.comments.length, 1, "The unsaved comment should be in the post's comments array"); }); test('dual non-async HM <-> BT', async function (assert) { @@ -2250,7 +2218,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.createRecord = function (store, type, snapshot) { let serialized = snapshot.record.serialize(); serialized.data.id = 2; - return resolve(serialized); + return Promise.resolve(serialized); }; let post = store.push({ @@ -2312,7 +2280,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.findMany = function (store, type, ids, snapshots) { assert.ok(true, `findMany called ${++findManyCalls}x`); - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'first' } }, { id: '2', type: 'comment', attributes: { body: 'second' } }, @@ -2323,7 +2291,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.findRecord = function (store, type, id, snapshot) { assert.ok(true, `findRecord called ${++findRecordCalls}x`); - return resolve({ data: { id: '3', type: 'comment', attributes: { body: 'third' } } }); + return Promise.resolve({ data: { id: '3', type: 'comment', attributes: { body: 'third' } } }); }; let post = store.push({ @@ -2433,33 +2401,29 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.ok(post.comments.length, 1, 'expected length for comments'); }); - test('After removing and unloading a record, a hasMany relationship should still be valid', function (assert) { + test('After removing and unloading a record, a hasMany relationship should still be valid', async function (assert) { let store = this.owner.lookup('service:store'); - const post = run(() => { - store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - data: [{ type: 'comment', id: '1' }], - }, + const post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + data: [{ type: 'comment', id: '1' }], }, }, - included: [{ type: 'comment', id: '1' }], - }); - const post = store.peekRecord('post', 1); - const comments = post.comments; - const comment = comments.at(0); - comments.splice(0, 1); - store.unloadRecord(comment); - assert.strictEqual(comments.length, 0); - return post; + }, + included: [{ type: 'comment', id: '1' }], }); + const comments = post.comments; + const comment = comments.at(0); + comments.splice(0, 1); + store.unloadRecord(comment); + assert.strictEqual(comments.length, 0); - // Explicitly re-get comments - assert.strictEqual(run(post, 'get', 'comments.length'), 0); + const comments2 = await post.comments; + assert.strictEqual(comments2.length, 0); }); test('If reordered hasMany data has been pushed to the store, the many array reflects the ordering change - sync', async function (assert) { @@ -2657,7 +2621,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.strictEqual(chapter.pages.at(0), page, 'Chapter has a page after rollback attributes'); }); - test('Rollbacking attributes for deleted record restores implicit relationship correctly when the belongsTo side has been deleted - async', function (assert) { + test('Rollbacking attributes for deleted record restores implicit relationship correctly when the belongsTo side has been deleted - async', async function (assert) { class Page extends Model { @attr number; @belongsTo('chapter', { async: true, inverse: 'pages' }) chapter; @@ -2668,43 +2632,36 @@ If using this relationship in a polymorphic manner is desired, the relationships let chapter, page; - run(() => { - store.push({ - data: { - type: 'chapter', - id: '2', + store.push({ + data: { + type: 'chapter', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + }, + included: [ + { + type: 'page', + id: '3', attributes: { - title: 'Sailing the Seven Seas', + number: 1, }, - }, - included: [ - { - type: 'page', - id: '3', - attributes: { - number: 1, - }, - relationships: { - chapter: { - data: { type: 'chapter', id: '2' }, - }, + relationships: { + chapter: { + data: { type: 'chapter', id: '2' }, }, }, - ], - }); - chapter = store.peekRecord('chapter', 2); - page = store.peekRecord('page', 3); - }); - - run(() => { - chapter.deleteRecord(); - chapter.rollbackAttributes(); + }, + ], }); + chapter = store.peekRecord('chapter', '2'); + page = store.peekRecord('page', '3'); - return run(() => { - return page.chapter.then((fetchedChapter) => { - assert.strictEqual(fetchedChapter, chapter, 'Page has a chapter after rollback attributes'); - }); + chapter.deleteRecord(); + chapter.rollbackAttributes(); + await page.chapter.then((fetchedChapter) => { + assert.strictEqual(fetchedChapter, chapter, 'Page has a chapter after rollback attributes'); }); }); @@ -2712,42 +2669,36 @@ If using this relationship in a polymorphic manner is desired, the relationships let store = this.owner.lookup('service:store'); let chapter, page; - run(() => { - store.push({ - data: { - type: 'chapter', - id: '2', + store.push({ + data: { + type: 'chapter', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + }, + included: [ + { + type: 'page', + id: '3', attributes: { - title: 'Sailing the Seven Seas', + number: 1, }, - }, - included: [ - { - type: 'page', - id: '3', - attributes: { - number: 1, - }, - relationships: { - chapter: { - data: { type: 'chapter', id: '2' }, - }, + relationships: { + chapter: { + data: { type: 'chapter', id: '2' }, }, }, - ], - }); - chapter = store.peekRecord('chapter', 2); - page = store.peekRecord('page', 3); + }, + ], }); + chapter = store.peekRecord('chapter', '2'); + page = store.peekRecord('page', '3'); - run(() => { - chapter.deleteRecord(); - chapter.rollbackAttributes(); - }); + chapter.deleteRecord(); + chapter.rollbackAttributes(); - run(() => { - assert.strictEqual(page.chapter, chapter, 'Page has a chapter after rollback attributes'); - }); + assert.strictEqual(page.chapter, chapter, 'Page has a chapter after rollback attributes'); }); test('Relationship.clear removes all records correctly', async function (assert) { @@ -2827,7 +2778,7 @@ If using this relationship in a polymorphic manner is desired, the relationships ); }); - test('unloading a record with associated records does not prevent the store from tearing down', function (assert) { + test('unloading a record with associated records does not prevent the store from tearing down', async function (assert) { class Post extends Model { @attr title; @hasMany('comment', { async: false, inverse: 'post' }) comments; @@ -2843,59 +2794,56 @@ If using this relationship in a polymorphic manner is desired, the relationships let store = this.owner.lookup('service:store'); let post; - run(() => { - store.push({ - data: [ - { - type: 'post', - id: '2', - attributes: { - title: 'Sailing the Seven Seas', - }, - relationships: { - comments: { - data: [ - { type: 'comment', id: '1' }, - { type: 'comment', id: '2' }, - ], - }, + store.push({ + data: [ + { + type: 'post', + id: '2', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + comments: { + data: [ + { type: 'comment', id: '1' }, + { type: 'comment', id: '2' }, + ], }, }, - { - type: 'comment', - id: '1', - relationships: { - post: { - data: { type: 'post', id: '2' }, - }, + }, + { + type: 'comment', + id: '1', + relationships: { + post: { + data: { type: 'post', id: '2' }, }, }, - { - type: 'comment', - id: '2', - relationships: { - post: { - data: { type: 'post', id: '2' }, - }, + }, + { + type: 'comment', + id: '2', + relationships: { + post: { + data: { type: 'post', id: '2' }, }, }, - ], - }); - post = store.peekRecord('post', 2); - - // This line triggers the original bug that gets manifested - // in teardown for apps, e.g. store.destroy that is caused by - // App.destroy(). - // Relationship#clear uses Ember.Set#forEach, which does incorrect - // iteration when the set is being mutated (in our case, the index gets off - // because records are being removed) - store.unloadRecord(post); + }, + ], }); + post = store.peekRecord('post', '2'); + + // This line triggers the original bug that gets manifested + // in teardown for apps, e.g. store.destroy that is caused by + // App.destroy(). + // Relationship#clear uses Ember.Set#forEach, which does incorrect + // iteration when the set is being mutated (in our case, the index gets off + // because records are being removed) + store.unloadRecord(post); try { - run(() => { - store.destroy(); - }); + store.destroy(); + await settled(); assert.ok(true, 'store destroyed correctly'); } catch (error) { assert.ok(false, 'store prevented from being destroyed'); @@ -2924,13 +2872,13 @@ If using this relationship in a polymorphic manner is desired, the relationships 'adapter:comment', RESTAdapter.extend({ deleteRecord(record) { - return resolve(); + return Promise.resolve(); }, updateRecord(record) { - return resolve(); + return Promise.resolve(); }, createRecord() { - return resolve({ comments: { id: commentId++ } }); + return Promise.resolve({ comments: { id: commentId++ } }); }, }) ); @@ -3001,7 +2949,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.strictEqual(commentsPromiseArray.length, 4, 'Comments count after second add'); }); - test('hasMany hasAnyRelationshipData async loaded', function (assert) { + test('hasMany hasAnyRelationshipData async loaded', async function (assert) { assert.expect(1); class Chapter extends Model { @attr title; @@ -3013,7 +2961,7 @@ If using this relationship in a polymorphic manner is desired, the relationships let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'chapter', @@ -3030,22 +2978,20 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - return store.findRecord('chapter', 1).then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); - assert.true(relationship.state.hasReceivedData, 'relationship has data'); - }); + await store.findRecord('chapter', '1').then((chapter) => { + let relationship = getRelationshipStateForRecord(chapter, 'pages'); + assert.true(relationship.state.hasReceivedData, 'relationship has data'); }); }); - test('hasMany hasAnyRelationshipData sync loaded', function (assert) { + test('hasMany hasAnyRelationshipData sync loaded', async function (assert) { assert.expect(1); let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'chapter', @@ -3062,15 +3008,13 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - return store.findRecord('chapter', 1).then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); - assert.true(relationship.state.hasReceivedData, 'relationship has data'); - }); + await store.findRecord('chapter', '1').then((chapter) => { + let relationship = getRelationshipStateForRecord(chapter, 'pages'); + assert.true(relationship.state.hasReceivedData, 'relationship has data'); }); }); - test('hasMany hasAnyRelationshipData async not loaded', function (assert) { + test('hasMany hasAnyRelationshipData async not loaded', async function (assert) { assert.expect(1); class Chapter extends Model { @attr title; @@ -3082,7 +3026,7 @@ If using this relationship in a polymorphic manner is desired, the relationships let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'chapter', @@ -3096,22 +3040,20 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - return store.findRecord('chapter', 1).then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); - assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); - }); + await store.findRecord('chapter', '1').then((chapter) => { + let relationship = getRelationshipStateForRecord(chapter, 'pages'); + assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); }); }); - test('hasMany hasAnyRelationshipData sync not loaded', function (assert) { + test('hasMany hasAnyRelationshipData sync not loaded', async function (assert) { assert.expect(1); let store = this.owner.lookup('service:store'); let adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { - return resolve({ + return Promise.resolve({ data: { id: '1', type: 'chapter', @@ -3120,11 +3062,9 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - return store.findRecord('chapter', 1).then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); - assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); - }); + await store.findRecord('chapter', '1').then((chapter) => { + let relationship = getRelationshipStateForRecord(chapter, 'pages'); + assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); }); }); @@ -3173,31 +3113,24 @@ If using this relationship in a polymorphic manner is desired, the relationships test("Model's hasMany relationship should not be created during model creation", function (assert) { let store = this.owner.lookup('service:store'); - let user; - run(() => { - store.push({ - data: { - type: 'user', - id: '1', - }, - }); - user = store.peekRecord('user', 1); - assert.notOk(hasRelationshipForRecord(user, 'messages'), 'Newly created record should not have relationships'); + let user = store.push({ + data: { + type: 'user', + id: '1', + }, }); + assert.notOk(hasRelationshipForRecord(user, 'messages'), 'Newly created record should not have relationships'); }); - test("Model's belongsTo relationship should be created during 'get' method", function (assert) { + test("Model's belongsTo relationship should be created during 'get' method", async function (assert) { let store = this.owner.lookup('service:store'); - let user; - run(() => { - user = store.createRecord('user'); - user.messages; - assert.ok( - hasRelationshipForRecord(user, 'messages'), - 'Newly created record with relationships in params passed in its constructor should have relationships' - ); - }); + let user = store.createRecord('user'); + user.messages; + assert.ok( + hasRelationshipForRecord(user, 'messages'), + 'Newly created record with relationships in params passed in its constructor should have relationships' + ); }); test('metadata is accessible when pushed as a meta property for a relationship', function (assert) { @@ -3207,40 +3140,30 @@ If using this relationship in a polymorphic manner is desired, the relationships let adapter = store.adapterFor('application'); adapter.findHasMany = function () { - return resolve({}); + return Promise.resolve({}); }; - let book; - run(() => { - store.push({ - data: { - type: 'book', - id: '1', - attributes: { - title: 'Sailing the Seven Seas', - }, - relationships: { - chapters: { - meta: { - where: 'the lefkada sea', - }, - links: { - related: '/chapters', - }, + let book = store.push({ + data: { + type: 'book', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + chapters: { + meta: { + where: 'the lefkada sea', + }, + links: { + related: '/chapters', }, }, }, - }); - book = store.peekRecord('book', 1); + }, }); - run(() => { - assert.strictEqual( - getRelationshipStateForRecord(book, 'chapters').meta.where, - 'the lefkada sea', - 'meta is there' - ); - }); + assert.strictEqual(getRelationshipStateForRecord(book, 'chapters').meta.where, 'the lefkada sea', 'meta is there'); }); test('metadata is accessible when return from a fetchLink', async function (assert) { @@ -3252,7 +3175,7 @@ If using this relationship in a polymorphic manner is desired, the relationships let adapter = store.adapterFor('application'); adapter.findHasMany = function () { - return resolve({ + return Promise.resolve({ meta: { foo: 'bar', }, @@ -3282,7 +3205,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.strictEqual(meta?.foo, 'bar', 'metadata is available'); }); - test('metadata should be reset between requests', function (assert) { + test('metadata should be reset between requests', async function (assert) { this.owner.register('serializer:application', RESTSerializer); let store = this.owner.lookup('service:store'); @@ -3306,62 +3229,58 @@ If using this relationship in a polymorphic manner is desired, the relationships counter++; - return resolve(data); + return Promise.resolve(data); }; let book1, book2; - run(() => { - store.push({ - data: [ - { - type: 'book', - id: '1', - attributes: { - title: 'Sailing the Seven Seas', - }, - relationships: { - chapters: { - links: { - related: 'chapters', - }, + store.push({ + data: [ + { + type: 'book', + id: '1', + attributes: { + title: 'Sailing the Seven Seas', + }, + relationships: { + chapters: { + links: { + related: 'chapters', }, }, }, - { - type: 'book', - id: '2', - attributes: { - title: 'Another book title', - }, - relationships: { - chapters: { - links: { - related: 'chapters', - }, + }, + { + type: 'book', + id: '2', + attributes: { + title: 'Another book title', + }, + relationships: { + chapters: { + links: { + related: 'chapters', }, }, }, - ], - }); - book1 = store.peekRecord('book', 1); - book2 = store.peekRecord('book', 2); + }, + ], }); + book1 = store.peekRecord('book', '1'); + book2 = store.peekRecord('book', '2'); - return run(() => { - return book1.chapters.then((chapters) => { - let meta = chapters.meta; - assert.strictEqual(get(meta, 'foo'), 'bar', 'metadata should available'); + await book1.chapters.then((chapters) => { + let meta = chapters.meta; + assert.strictEqual(meta.foo, 'bar', 'metadata should available'); - return book2.chapters.then((chapters) => { - let meta = chapters.meta; - assert.strictEqual(meta, null, 'metadata should not be available'); - }); + return book2.chapters.then((chapters) => { + let meta = chapters.meta; + assert.strictEqual(meta, null, 'metadata should not be available'); }); }); }); - test('Related link should be fetched when no relationship data is present', function (assert) { + test('Related link should be fetched when no relationship data is present', async function (assert) { assert.expect(3); class Post extends Model { @attr title; @@ -3391,7 +3310,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.findHasMany = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'get-comments', 'url is correct'); assert.ok(true, "The adapter's findHasMany method should be called"); - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -3404,28 +3323,26 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - let post = store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'get-comments', - }, + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', }, }, }, - }); + }, + }); - return post.comments.then((comments) => { - assert.strictEqual(comments.at(0).body, 'This is comment', 'comment body is correct'); - }); + await post.comments.then((comments) => { + assert.strictEqual(comments.at(0).body, 'This is comment', 'comment body is correct'); }); }); - test('Related link should take precedence over relationship data when local record data is missing', function (assert) { + test('Related link should take precedence over relationship data when local record data is missing', async function (assert) { assert.expect(3); class Post extends Model { @attr title; @@ -3455,7 +3372,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.findHasMany = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'get-comments', 'url is correct'); assert.ok(true, "The adapter's findHasMany method should be called"); - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -3468,29 +3385,27 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - let post = store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'get-comments', - }, - data: [{ type: 'comment', id: '1' }], + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', }, + data: [{ type: 'comment', id: '1' }], }, }, - }); + }, + }); - return post.comments.then((comments) => { - assert.strictEqual(comments.at(0).body, 'This is comment', 'comment body is correct'); - }); + await post.comments.then((comments) => { + assert.strictEqual(comments.at(0).body, 'This is comment', 'comment body is correct'); }); }); - test('Local relationship data should take precedence over related link when local record data is available', function (assert) { + test('Local relationship data should take precedence over related link when local record data is available', async function (assert) { assert.expect(1); class Post extends Model { @attr title; @@ -3521,38 +3436,36 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.ok(false, "The adapter's findHasMany method should not be called"); }; - return run(() => { - let post = store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'get-comments', - }, - data: [{ type: 'comment', id: '1' }], + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', }, + data: [{ type: 'comment', id: '1' }], }, }, - included: [ - { - id: '1', - type: 'comment', - attributes: { - body: 'This is comment', - }, + }, + included: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment', }, - ], - }); + }, + ], + }); - return post.comments.then((comments) => { - assert.strictEqual(comments.at(0).body, 'This is comment', 'comment body is correct'); - }); + await post.comments.then((comments) => { + assert.strictEqual(comments.at(0).body, 'This is comment', 'comment body is correct'); }); }); - test('Related link should take precedence over local record data when relationship data is not initially available', function (assert) { + test('Related link should take precedence over local record data when relationship data is not initially available', async function (assert) { assert.expect(3); class Post extends Model { @attr title; @@ -3582,7 +3495,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.findHasMany = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'get-comments', 'url is correct'); assert.ok(true, "The adapter's findHasMany method should be called"); - return resolve({ + return Promise.resolve({ data: [ { id: '1', @@ -3595,45 +3508,43 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - return run(() => { - let post = store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'get-comments', - }, + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'get-comments', }, }, }, - included: [ - { - id: '1', - type: 'comment', - attributes: { - body: 'This is comment', - }, - relationships: { - post: { - data: { - type: 'post', - id: '1', - }, + }, + included: [ + { + id: '1', + type: 'comment', + attributes: { + body: 'This is comment', + }, + relationships: { + post: { + data: { + type: 'post', + id: '1', }, }, }, - ], - }); + }, + ], + }); - return post.comments.then((comments) => { - assert.strictEqual(comments.at(0).body, 'This is comment fetched by link', 'comment body is correct'); - }); + await post.comments.then((comments) => { + assert.strictEqual(comments.at(0).body, 'This is comment fetched by link', 'comment body is correct'); }); }); - test('Updated related link should take precedence over relationship data and local record data', function (assert) { + test('Updated related link should take precedence over relationship data and local record data', async function (assert) { assert.expect(3); class Post extends Model { @attr title; @@ -3653,7 +3564,7 @@ If using this relationship in a polymorphic manner is desired, the relationships adapter.findHasMany = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'comments-updated-link', 'url is correct'); assert.ok(true, "The adapter's findHasMany method should be called"); - return resolve({ + return Promise.resolve({ data: [{ id: '1', type: 'comment', attributes: { body: 'This is updated comment' } }], }); }; @@ -3662,39 +3573,37 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.ok(false, "The adapter's findRecord method should not be called"); }; - return run(() => { - let post = store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'comments', - }, - data: [{ type: 'comment', id: '1' }], + let post = store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'comments', }, + data: [{ type: 'comment', id: '1' }], }, }, - }); + }, + }); - store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'comments-updated-link', - }, + store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'comments-updated-link', }, }, }, - }); + }, + }); - return post.comments.then((comments) => { - assert.strictEqual(comments.at(0).body, 'This is updated comment', 'comment body is correct'); - }); + await post.comments.then((comments) => { + assert.strictEqual(comments.at(0).body, 'This is updated comment', 'comment body is correct'); }); }); @@ -3813,9 +3722,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.strictEqual(user.messages.at(0).id, 'message-1'); assert.strictEqual(message.user.id, 'user-1'); - run(() => { - store.unloadRecord(user); - }); + store.unloadRecord(user); // The record is resurrected for some reason. store.push({ @@ -3882,7 +3789,7 @@ If using this relationship in a polymorphic manner is desired, the relationships user = store.peekRecord('user', 'user-1'); message = store.peekRecord('message', 'message-1'); - assert.strictEqual(get(user, 'messages.length'), 2); + assert.strictEqual(user.messages.length, 2); await message.destroyRecord(); @@ -3903,29 +3810,27 @@ If using this relationship in a polymorphic manner is desired, the relationships }); assert.deepEqual( - get(user, 'messages').map((r) => r.id), + user.messages.map((r) => r.id), ['message-2', 'message-3'], 'user should have 2 message since 1 was deleted' ); }); - test("hasMany relationship with links doesn't trigger extra change notifications - #4942", function (assert) { + test("hasMany relationship with links doesn't trigger extra change notifications - #4942", async function (assert) { let store = this.owner.lookup('service:store'); - run(() => { - store.push({ - data: { - type: 'book', - id: '1', - relationships: { - chapters: { - data: [{ type: 'chapter', id: '1' }], - links: { related: '/book/1/chapters' }, - }, + store.push({ + data: { + type: 'book', + id: '1', + relationships: { + chapters: { + data: [{ type: 'chapter', id: '1' }], + links: { related: '/book/1/chapters' }, }, }, - included: [{ type: 'chapter', id: '1' }], - }); + }, + included: [{ type: 'chapter', id: '1' }], }); let book = store.peekRecord('book', '1'); @@ -3935,9 +3840,7 @@ If using this relationship in a polymorphic manner is desired, the relationships count++; }); - run(() => { - book.chapters; - }); + await book.chapters; assert.strictEqual(count, 0); }); @@ -4003,7 +3906,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.strictEqual(link, '/posts/1/comments', 'findHasMany link was /posts/1/comments'); hasManyCounter++; - return resolve({ + return Promise.resolve({ data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, 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 0343bc393b5..1c7d4f08727 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,9 +1,9 @@ import { module, skip, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import Model, { attr } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import { AdapterPopulatedRecordArray, RecordArrayManager, SOURCE } from '@ember-data/store/-private'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; @@ -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 = defer(); + let deferred = createDeferred(); 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 565545b2401..b11d4722627 100644 --- a/tests/main/tests/unit/record-arrays/record-array-test.js +++ b/tests/main/tests/unit/record-arrays/record-array-test.js @@ -1,10 +1,10 @@ import { module, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import { FetchManager, SnapshotRecordArray } from '@ember-data/legacy-compat/-private'; import Model, { attr } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import { recordIdentifierFor } from '@ember-data/store'; import { RecordArray, SOURCE } from '@ember-data/store/-private'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; @@ -87,7 +87,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#update', async function (assert) { let findAllCalled = 0; - let deferred = defer(); + let deferred = createDeferred(); 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 = defer(); + let deferred = createDeferred(); const store = { findAll(modelName, options) { findAllCalled++; diff --git a/tests/main/tests/unit/store/finders-test.js b/tests/main/tests/unit/store/finders-test.js index 6a299fd51c6..272246cf43e 100644 --- a/tests/main/tests/unit/store/finders-test.js +++ b/tests/main/tests/unit/store/finders-test.js @@ -1,10 +1,10 @@ import { module, test } from 'qunit'; -import { defer } from 'rsvp'; import { setupTest } from 'ember-qunit'; import Adapter from '@ember-data/adapter'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; +import { createDeferred } from '@ember-data/request'; import JSONAPISerializer from '@ember-data/serializer/json-api'; class Person extends Model { @@ -35,7 +35,7 @@ module('unit/store/finders', function (hooks) { test('findRecord does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -68,7 +68,7 @@ module('unit/store/finders', function (hooks) { test('findMany does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -106,7 +106,7 @@ module('unit/store/finders', function (hooks) { test('findHasMany does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -159,7 +159,7 @@ module('unit/store/finders', function (hooks) { test('findBelongsTo does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -208,7 +208,7 @@ module('unit/store/finders', function (hooks) { test('findAll does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -241,7 +241,7 @@ module('unit/store/finders', function (hooks) { test('query does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -274,7 +274,7 @@ module('unit/store/finders', function (hooks) { test('queryRecord does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = defer(); + let deferedFind = createDeferred(); this.owner.register( 'adapter:person',