Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence warnings and deprecations in the console during tests #4663

Merged
merged 2 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/setup-ember-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Copy link
Member

@pangratz pangratz Nov 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like ignoreDeprecation is no more used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, nevermind. I think it doesn't hurt if this assertion is available too.


// Maintain backwards compatiblity with older versions of ember.
var emberDebugModule;
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 26 additions & 18 deletions tests/integration/records/error-test.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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({
Expand All @@ -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' },
Expand All @@ -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', {
Expand All @@ -82,20 +90,20 @@ 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' },
{ attribute: 'lastName', 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(7);

var person = run(() => {
return store.createRecord('person', {
Expand All @@ -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', {
Expand All @@ -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');
});
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/references/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/serializers/json-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/serializers/rest-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');
});
Expand Down
61 changes: 33 additions & 28 deletions tests/unit/model/errors-test.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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');
Expand All @@ -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' },
Expand All @@ -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());
});
Loading