From 3d49afeb6d01bcbdfe2f7f5dad21ca274938df08 Mon Sep 17 00:00:00 2001 From: bmac Date: Thu, 17 Nov 2016 09:58:20 -0500 Subject: [PATCH 1/2] Silence warnings and deprecations in the console durring tests --- tests/helpers/setup-ember-dev.js | 2 +- .../integration/adapter/rest-adapter-test.js | 16 +++-- tests/integration/records/error-test.js | 44 +++++++------ .../serializers/json-serializer-test.js | 9 +-- tests/unit/model/errors-test.js | 61 ++++++++++--------- tests/unit/store/adapter-interop-test.js | 26 ++++---- 6 files changed, 89 insertions(+), 69 deletions(-) diff --git a/tests/helpers/setup-ember-dev.js b/tests/helpers/setup-ember-dev.js index faf10add6af..703c9c4dac6 100644 --- a/tests/helpers/setup-ember-dev.js +++ b/tests/helpers/setup-ember-dev.js @@ -2,7 +2,7 @@ import Ember from 'ember'; import EmberTestHelpers from "ember-dev/test-helper/index"; -const AVAILABLE_ASSERTIONS = ['expectAssertion', 'expectDeprecation', 'expectNoDeprecation', 'expectWarning', 'expectNoWarning']; +const AVAILABLE_ASSERTIONS = ['expectAssertion', 'expectDeprecation', 'expectNoDeprecation', 'expectWarning', 'expectNoWarning', 'ignoreDeprecation']; // Maintain backwards compatiblity with older versions of ember. var emberDebugModule; diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js index 0f0167ec8f7..a91d402581f 100644 --- a/tests/integration/adapter/rest-adapter-test.js +++ b/tests/integration/adapter/rest-adapter-test.js @@ -1349,17 +1349,21 @@ test("queryRecord - returning sideloaded data loads the data", function(assert) })); }); -test("queryRecord - returning an array picks the first one but saves all records to the store", function(assert) { +testInDebug("queryRecord - returning an array picks the first one but saves all records to the store", function(assert) { ajaxResponse({ post: [{ id: 1, name: "Rails is omakase" }, { id: 2, name: "Ember is js" }] }); - store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(assert.wait(function(post) { - var post2 = store.peekRecord('post', 2); + assert.expectDeprecation('The adapter returned an array for the primary data of a `queryRecord` response. This is deprecated as `queryRecord` should return a single record.'); - assert.deepEqual(post.getProperties('id', 'name'), { id: "1", name: "Rails is omakase" }); - assert.deepEqual(post2.getProperties('id', 'name'), { id: "2", name: "Ember is js" }); - })); + run(function() { + store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(assert.wait(function(post) { + var post2 = store.peekRecord('post', 2); + + assert.deepEqual(post.getProperties('id', 'name'), { id: "1", name: "Rails is omakase" }); + assert.deepEqual(post2.getProperties('id', 'name'), { id: "2", name: "Ember is js" }); + })); + }); }); testInDebug("queryRecord - returning an array is deprecated", function(assert) { diff --git a/tests/integration/records/error-test.js b/tests/integration/records/error-test.js index 0c8e1bfe77d..a0ca3f3a941 100644 --- a/tests/integration/records/error-test.js +++ b/tests/integration/records/error-test.js @@ -1,12 +1,19 @@ import Ember from 'ember'; -import {module, test} from 'qunit'; +import {module} from 'qunit'; import DS from 'ember-data'; import setupStore from 'dummy/tests/helpers/store'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; var env, store, Person; var attr = DS.attr; var run = Ember.run; +function updateErrors(func) { + window.expectWarning(function() { + run(func); + }, 'Interacting with a record errors object will no longer change the record state.'); +} + module('integration/records/error', { beforeEach: function() { Person = DS.Model.extend({ @@ -28,8 +35,8 @@ module('integration/records/error', { } }); -test('adding errors during root.loaded.created.invalid works', function(assert) { - assert.expect(3); +testInDebug('adding errors during root.loaded.created.invalid works', function(assert) { + assert.expect(5); var person = run(() => { store.push({ @@ -51,11 +58,12 @@ test('adding errors during root.loaded.created.invalid works', function(assert) }); assert.equal(person._internalModel.currentState.stateName, 'root.loaded.updated.uncommitted'); - Ember.run(() => person.get('errors').add('firstName', 'is invalid') ); + + updateErrors(() => person.get('errors').add('firstName', 'is invalid') , assert); assert.equal(person._internalModel.currentState.stateName, 'root.loaded.updated.invalid'); - Ember.run(() => person.get('errors').add('lastName', 'is invalid') ); + updateErrors(() => person.get('errors').add('lastName', 'is invalid'), assert); assert.deepEqual(person.get('errors').toArray(), [ { attribute: 'firstName', message: 'is invalid' }, @@ -64,8 +72,8 @@ test('adding errors during root.loaded.created.invalid works', function(assert) }); -test('adding errors root.loaded.created.invalid works', function(assert) { - assert.expect(3); +testInDebug('adding errors root.loaded.created.invalid works', function(assert) { + assert.expect(5); var person = run(() => { return store.createRecord('person', { @@ -82,11 +90,11 @@ test('adding errors root.loaded.created.invalid works', function(assert) { assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted'); - Ember.run(() => person.get('errors').add('firstName', 'is invalid') ); + updateErrors(() => person.get('errors').add('firstName', 'is invalid') ); assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); - Ember.run(() => person.get('errors').add('lastName', 'is invalid') ); + updateErrors(() => person.get('errors').add('lastName', 'is invalid') ); assert.deepEqual(person.get('errors').toArray(), [ { attribute: 'firstName', message: 'is invalid' }, @@ -94,8 +102,8 @@ test('adding errors root.loaded.created.invalid works', function(assert) { ]); }); -test('adding errors root.loaded.created.invalid works add + remove + add', function(assert) { - assert.expect(4); +testInDebug('adding errors root.loaded.created.invalid works add + remove + add', function(assert) { + assert.expect(7); var person = run(() => { return store.createRecord('person', { @@ -110,23 +118,23 @@ test('adding errors root.loaded.created.invalid works add + remove + add', funct assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted'); - Ember.run(() => person.get('errors').add('firstName', 'is invalid') ); + updateErrors(() => person.get('errors').add('firstName', 'is invalid') ); assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); - Ember.run(() => person.get('errors').remove('firstName')); + updateErrors(() => person.get('errors').remove('firstName')); assert.deepEqual(person.get('errors').toArray(), []); - Ember.run(() => person.get('errors').add('firstName', 'is invalid') ); + updateErrors(() => person.get('errors').add('firstName', 'is invalid') ); assert.deepEqual(person.get('errors').toArray(), [ { attribute: 'firstName', message: 'is invalid' } ]); }); -test('adding errors root.loaded.created.invalid works add + (remove, add)', function(assert) { - assert.expect(4); +testInDebug('adding errors root.loaded.created.invalid works add + (remove, add)', function(assert) { + assert.expect(6); var person = run(() => { return store.createRecord('person', { @@ -141,13 +149,13 @@ test('adding errors root.loaded.created.invalid works add + (remove, add)', func assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted'); - Ember.run(() => { + updateErrors(() => { person.get('errors').add('firstName', 'is invalid'); }); assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid'); - Ember.run(() => { + updateErrors(() => { person.get('errors').remove('firstName'); person.get('errors').add('firstName', 'is invalid'); }); diff --git a/tests/integration/serializers/json-serializer-test.js b/tests/integration/serializers/json-serializer-test.js index 00cb4d20105..66e547b7e60 100644 --- a/tests/integration/serializers/json-serializer-test.js +++ b/tests/integration/serializers/json-serializer-test.js @@ -973,7 +973,7 @@ test('normalizeResponse respects `included` items (array response)', function(as ]); }); -test('normalizeResponse ignores unmapped attributes', function(assert) { +testInDebug('normalizeResponse ignores unmapped attributes', function(assert) { env.registry.register("serializer:post", DS.JSONSerializer.extend({ attrs: { title: { serialize: false }, @@ -987,9 +987,10 @@ test('normalizeResponse ignores unmapped attributes', function(assert) { title: "Rails is omakase" }; - var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); - - assert.equal(post.data.attributes.title, "Rails is omakase"); + assert.expectWarning(function() { + var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord'); + assert.equal(post.data.attributes.title, "Rails is omakase"); + }, /There is no attribute or relationship with the name/); }); test('options are passed to transform for serialization', function(assert) { diff --git a/tests/unit/model/errors-test.js b/tests/unit/model/errors-test.js index 9569a80c4de..b1efef07942 100644 --- a/tests/unit/model/errors-test.js +++ b/tests/unit/model/errors-test.js @@ -1,5 +1,6 @@ import DS from 'ember-data'; -import QUnit, {module, test} from 'qunit'; +import QUnit, {module} from 'qunit'; +import testInDebug from 'dummy/tests/helpers/test-in-debug'; const AssertPrototype = QUnit.assert; @@ -14,6 +15,10 @@ module("unit/model/errors", { } }); +function updateErrors(func) { + window.expectWarning(func, 'Interacting with a record errors object will no longer change the record state.'); +} + AssertPrototype.becameInvalid = function becameInvalid(eventName) { if (eventName === 'becameInvalid') { this.ok(true, 'becameInvalid send'); @@ -34,32 +39,32 @@ AssertPrototype.unexpectedSend = function unexpectedSend(eventName) { this.ok(false, 'unexpected send : ' + eventName); }.bind(AssertPrototype); -test("add error", function(assert) { - assert.expect(6); +testInDebug("add error", function(assert) { + assert.expect(10); errors.trigger = assert.becameInvalid; - errors.add('firstName', 'error'); + updateErrors(() => errors.add('firstName', 'error')); errors.trigger = assert.unexpectedSend; assert.ok(errors.has('firstName'), 'it has firstName errors'); assert.equal(errors.get('length'), 1, 'it has 1 error'); - errors.add('firstName', ['error1', 'error2']); + updateErrors(() => errors.add('firstName', ['error1', 'error2'])); assert.equal(errors.get('length'), 3, 'it has 3 errors'); assert.ok(!errors.get('isEmpty'), 'it is not empty'); - errors.add('lastName', 'error'); - errors.add('lastName', 'error'); + updateErrors(() => errors.add('lastName', 'error')); + updateErrors(() => errors.add('lastName', 'error')); assert.equal(errors.get('length'), 4, 'it has 4 errors'); }); -test("get error", function(assert) { - assert.expect(8); +testInDebug("get error", function(assert) { + assert.expect(11); assert.ok(errors.get('firstObject') === undefined, 'returns undefined'); errors.trigger = assert.becameInvalid; - errors.add('firstName', 'error'); + updateErrors(() => errors.add('firstName', 'error')); errors.trigger = assert.unexpectedSend; assert.ok(errors.get('firstName').length === 1, 'returns errors'); assert.deepEqual(errors.get('firstObject'), { attribute: 'firstName', message: 'error' }); - errors.add('firstName', 'error2'); + updateErrors(() => errors.add('firstName', 'error2')); assert.ok(errors.get('firstName').length === 2, 'returns errors'); - errors.add('lastName', 'error3'); + updateErrors(() => errors.add('lastName', 'error3')); assert.deepEqual(errors.toArray(), [ { attribute: 'firstName', message: 'error' }, { attribute: 'firstName', message: 'error2' }, @@ -72,42 +77,42 @@ test("get error", function(assert) { assert.deepEqual(errors.get('messages'), ['error', 'error2', 'error3']); }); -test("remove error", function(assert) { - assert.expect(5); +testInDebug("remove error", function(assert) { + assert.expect(8); errors.trigger = assert.becameInvalid; - errors.add('firstName', 'error'); + updateErrors(() => errors.add('firstName', 'error')); errors.trigger = assert.becameValid; - errors.remove('firstName'); + updateErrors(() => errors.remove('firstName')); errors.trigger = assert.unexpectedSend; assert.ok(!errors.has('firstName'), 'it has no firstName errors'); assert.equal(errors.get('length'), 0, 'it has 0 error'); assert.ok(errors.get('isEmpty'), 'it is empty'); - errors.remove('firstName'); + updateErrors(() => errors.remove('firstName')); }); -test("remove same errors from different attributes", function(assert) { - assert.expect(5); +testInDebug("remove same errors from different attributes", function(assert) { + assert.expect(9); errors.trigger = assert.becameInvalid; - errors.add('firstName', 'error'); - errors.add('lastName', 'error'); + updateErrors(() => errors.add('firstName', 'error')); + updateErrors(() => errors.add('lastName', 'error')); errors.trigger = assert.unexpectedSend; assert.equal(errors.get('length'), 2, 'it has 2 error'); - errors.remove('firstName'); + updateErrors(() => errors.remove('firstName')); assert.equal(errors.get('length'), 1, 'it has 1 error'); errors.trigger = assert.becameValid; - errors.remove('lastName'); + updateErrors(() => errors.remove('lastName')); assert.ok(errors.get('isEmpty'), 'it is empty'); }); -test("clear errors", function(assert) { - assert.expect(5); +testInDebug("clear errors", function(assert) { + assert.expect(8); errors.trigger = assert.becameInvalid; - errors.add('firstName', ['error', 'error1']); + updateErrors(() => errors.add('firstName', ['error', 'error1'])); assert.equal(errors.get('length'), 2, 'it has 2 errors'); errors.trigger = assert.becameValid; - errors.clear(); + updateErrors(() => errors.clear()); errors.trigger = assert.unexpectedSend; assert.ok(!errors.has('firstName'), 'it has no firstName errors'); assert.equal(errors.get('length'), 0, 'it has 0 error'); - errors.clear(); + updateErrors(() => errors.clear()); }); diff --git a/tests/unit/store/adapter-interop-test.js b/tests/unit/store/adapter-interop-test.js index f2e04bbe782..09b8939f85d 100644 --- a/tests/unit/store/adapter-interop-test.js +++ b/tests/unit/store/adapter-interop-test.js @@ -835,8 +835,8 @@ test("the promise returned by `_scheduleFetch`, when it rejects, does not depend }); }); -test("store._fetchRecord reject records that were not found, even when those requests were coalesced with records that were found", function(assert) { - assert.expect(2); +testInDebug("store._fetchRecord reject records that were not found, even when those requests were coalesced with records that were found", function(assert) { + assert.expect(3); var Person = DS.Model.extend(); @@ -859,18 +859,20 @@ test("store._fetchRecord reject records that were not found, even when those req test: Person }); - run(function () { - var davidPromise = store.findRecord('test', 'david'); - var igorPromise = store.findRecord('test', 'igor'); + assert.expectWarning(function() { + run(function () { + var davidPromise = store.findRecord('test', 'david'); + var igorPromise = store.findRecord('test', 'igor'); - davidPromise.then(assert.wait(function () { - assert.ok(true, "David resolved"); - })); + davidPromise.then(function () { + assert.ok(true, "David resolved"); + }); - igorPromise.then(null, assert.wait(function () { - assert.ok(true, "Igor rejected"); - })); - }); + igorPromise.then(null, function () { + assert.ok(true, "Igor rejected"); + }); + }); + }, /expected to find records with the following ids/); }); testInDebug("store._fetchRecord warns when records are missing", function(assert) { From 672a1fcf726138011cd020290f459435ccc3b28f Mon Sep 17 00:00:00 2001 From: bmac Date: Fri, 18 Nov 2016 09:13:01 -0500 Subject: [PATCH 2/2] Enable the RAISE_ON_DEPRECATION flag so tests fail if there is a deprecation --- tests/dummy/config/environment.js | 7 ++----- tests/integration/references/belongs-to-test.js | 8 +++++++- tests/integration/serializers/rest-serializer-test.js | 8 ++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index cf10d93440f..ad6657a6117 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -15,11 +15,8 @@ module.exports = function(environment) { locationType: 'auto', EmberENV: { FEATURES: featureFlags, - ENABLE_DS_FILTER: true - - // don't raise on deprecation yet, since there are too many thrown errors; - // this should be addressed in another PR - // RAISE_ON_DEPRECATION: true + ENABLE_DS_FILTER: true, + RAISE_ON_DEPRECATION: true }, APP: { diff --git a/tests/integration/references/belongs-to-test.js b/tests/integration/references/belongs-to-test.js index cf8614cab09..e69b67540e0 100644 --- a/tests/integration/references/belongs-to-test.js +++ b/tests/integration/references/belongs-to-test.js @@ -292,6 +292,9 @@ test("push(promise)", function(assert) { testInDebug("push(record) asserts for invalid modelClass", function(assert) { var person, anotherPerson; + if (isEnabled('ds-overhaul-references')) { + assert.expectDeprecation('BelongsToReference#push(DS.Model) is deprecated. Update relationship via `model.set(\'relationshipName\', value)` instead.') + } run(function() { person = env.store.push({ data: { @@ -321,11 +324,14 @@ testInDebug("push(record) asserts for invalid modelClass", function(assert) { }, "You cannot add a record of modelClass 'person' to the 'person.family' relationship (only 'family' allowed)"); }); -test("push(record) works with polymorphic modelClass", function(assert) { +testInDebug("push(record) works with polymorphic modelClass", function(assert) { var done = assert.async(); var person, mafiaFamily; + if (isEnabled('ds-overhaul-references')) { + assert.expectDeprecation('BelongsToReference#push(DS.Model) is deprecated. Update relationship via `model.set(\'relationshipName\', value)` instead.') + } env.registry.register('model:mafia-family', Family.extend()); run(function() { diff --git a/tests/integration/serializers/rest-serializer-test.js b/tests/integration/serializers/rest-serializer-test.js index 991e2756299..fd99b33fa8a 100644 --- a/tests/integration/serializers/rest-serializer-test.js +++ b/tests/integration/serializers/rest-serializer-test.js @@ -147,8 +147,8 @@ test("normalizeResponse with custom modelNameFromPayloadKey", function(assert) { }); }); -test("normalizeResponse with type and custom modelNameFromPayloadKey", function(assert) { - assert.expect(2); +testInDebug("normalizeResponse with type and custom modelNameFromPayloadKey", function(assert) { + assert.expect(isEnabled("ds-payload-type-hooks") ? 3 : 2); var homePlanetNormalizeCount = 0; @@ -168,6 +168,10 @@ test("normalizeResponse with type and custom modelNameFromPayloadKey", function( }; var array; + + if (isEnabled("ds-payload-type-hooks")) { + assert.expectDeprecation('You are using modelNameFromPayloadKey to normalize the type for a polymorphic relationship. This is has been deprecated in favor of modelNameFromPayloadType'); + } run(function() { array = env.restSerializer.normalizeResponse(env.store, HomePlanet, jsonHash, '1', 'findAll'); });