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

[bugfix] Adds options checking ability to debug/deprecation test helpers #16520

Merged
merged 1 commit into from
Apr 14, 2018
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
6 changes: 3 additions & 3 deletions packages/ember-metal/tests/properties_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ moduleFor(
assert.expect(3);
let obj = { foo: 'bar' };

deprecateProperty(obj, 'baz', 'foo');
deprecateProperty(obj, 'baz', 'foo', { id: 'baz-deprecation', until: 'some.version' });

expectDeprecation();
assert.equal(obj.baz, obj.foo, 'baz and foo are equal');
Expand All @@ -94,7 +94,7 @@ moduleFor(
assert.expect(2);
let obj = { foo: 'bar', blammo: 'whammy' };

deprecateProperty(obj, 'baz', 'foo');
deprecateProperty(obj, 'baz', 'foo', { id: 'baz-deprecation', until: 'some.version' });

for (let prop in obj) {
if (obj.hasOwnProperty(prop)) {
Expand All @@ -109,7 +109,7 @@ moduleFor(
assert.expect(3);
let obj = { foo: 'bar' };

deprecateProperty(obj, 'baz', 'foo');
deprecateProperty(obj, 'baz', 'foo', { id: 'baz-deprecation', until: 'some.version' });

expectDeprecation();
obj.baz = 'bloop';
Expand Down
24 changes: 20 additions & 4 deletions packages/ember-runtime/tests/computed/computed_macros_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,26 @@ moduleFor(
})
);

defineProperty(obj, 'barAlias', deprecatingAlias('bar'));
defineProperty(obj, 'bazAlias', deprecatingAlias('baz'));
defineProperty(obj, 'quzAlias', deprecatingAlias('quz'));
defineProperty(obj, 'bayAlias', deprecatingAlias('bay'));
defineProperty(
obj,
'barAlias',
deprecatingAlias('bar', { id: 'bar-deprecation', until: 'some.version' })
);
defineProperty(
obj,
'bazAlias',
deprecatingAlias('baz', { id: 'baz-deprecation', until: 'some.version' })
);
defineProperty(
obj,
'quzAlias',
deprecatingAlias('quz', { id: 'quz-deprecation', until: 'some.version' })
);
defineProperty(
obj,
'bayAlias',
deprecatingAlias('bay', { id: 'bay-deprecation', until: 'some.version' })
);

expectDeprecation(function() {
assert.equal(get(obj, 'barAlias'), 'asdf');
Expand Down
7 changes: 6 additions & 1 deletion packages/ember/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ Object.defineProperty(Ember, 'EXTEND_PROTOTYPES', {
enumerable: false,
get() {
deprecate(
'Accessing Ember.EXTEND_PROTOTYPES is deprecated, please migrate to Ember.ENV.EXTEND_PROTOTYPES'
'Accessing Ember.EXTEND_PROTOTYPES is deprecated, please migrate to Ember.ENV.EXTEND_PROTOTYPES',
false,
{
id: 'ember-env.old-extend-prototypes',
until: '4.0.0',
}
);

return ENV.EXTEND_PROTOTYPES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DeprecationAssert extends DebugAssert {
throw new Error('expectDeprecation was called after expectNoDeprecation was called!');
}

tracker.expectCall(message);
tracker.expectCall(message, ['id', 'until']);
});
};

Expand Down
93 changes: 65 additions & 28 deletions packages/internal-test-helpers/lib/ember-dev/method-call-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var MethodCallTracker = function(env, methodName) {
this._env = env;
this._methodName = methodName;
this._isExpectingNoCalls = false;
this._expecteds = [];
this._expectedMessages = [];
this._expectedOptionLists = [];
this._actuals = [];
};

Expand All @@ -20,10 +21,10 @@ MethodCallTracker.prototype = {

this._originalMethod = env.getDebugFunction(methodName);

env.setDebugFunction(methodName, (message, test) => {
env.setDebugFunction(methodName, (message, test, options) => {
let resultOfTest = checkTest(test);

this._actuals.push([message, resultOfTest]);
this._actuals.push([message, resultOfTest, options]);
});
},

Expand All @@ -33,9 +34,10 @@ MethodCallTracker.prototype = {
}
},

expectCall(message) {
expectCall(message, options) {
this.stubMethod();
this._expecteds.push(message || /.*/);
this._expectedMessages.push(message || /.*/);
this._expectedOptionLists.push(options);
},

expectNoCalls() {
Expand All @@ -48,19 +50,20 @@ MethodCallTracker.prototype = {
},

isExpectingCalls() {
return !this._isExpectingNoCalls && this._expecteds.length;
return !this._isExpectingNoCalls && this._expectedMessages.length;
},

assert() {
let { assert } = QUnit.config.current;
let env = this._env;
let methodName = this._methodName;
let isExpectingNoCalls = this._isExpectingNoCalls;
let expecteds = this._expecteds;
let expectedMessages = this._expectedMessages;
let expectedOptionLists = this._expectedOptionLists;
let actuals = this._actuals;
let o, i;
let o, i, j;

if (!isExpectingNoCalls && expecteds.length === 0 && actuals.length === 0) {
if (!isExpectingNoCalls && expectedMessages.length === 0 && actuals.length === 0) {
return;
}

Expand All @@ -83,29 +86,63 @@ MethodCallTracker.prototype = {
return;
}

let expected, actual, match;
let expectedMessage,
expectedOptionList,
actual,
match,
matchesMessage,
matchesOptionList,
expectedOptionsMessage,
actualOptionsMessage;

for (o = 0; o < expectedMessages.length; o++) {
expectedMessage = expectedMessages[o];
expectedOptionList = expectedOptionLists[o];

for (o = 0; o < expecteds.length; o++) {
expected = expecteds[o];
for (i = 0; i < actuals.length; i++) {
matchesMessage = false;
matchesOptionList = false;
actual = actuals[i];
if (!actual[1]) {
if (expected instanceof RegExp) {
if (expected.test(actual[0])) {
match = actual;
break;
}
} else {
if (expected === actual[0]) {
match = actual;
break;
}

if (actual[1] === true) {
continue;
}

if (expectedMessage instanceof RegExp && expectedMessage.test(actual[0])) {
matchesMessage = true;
} else if (expectedMessage === actual[0]) {
matchesMessage = true;
}

if (expectedOptionList === undefined) {
matchesOptionList = true;
} else if (actual[2]) {
matchesOptionList = true;

for (j = 0; j < expectedOptionList.length; j++) {
matchesOptionList =
matchesOptionList && actual[2].hasOwnProperty(expectedOptionList[j]);
}
}

if (matchesMessage && matchesOptionList) {
match = actual;
break;
}
}

expectedOptionsMessage = expectedOptionList
? `and options: { ${expectedOptionList.join(', ')} }`
: 'and no options';
actualOptionsMessage = actual[2]
? `and options: { ${Object.keys(actual[2]).join(', ')} }`
: 'and no options';

if (!actual) {
assert.ok(false, `Received no Ember.${methodName} calls at all, expecting: ${expected}`);
assert.ok(
false,
`Received no Ember.${methodName} calls at all, expecting: ${expectedMessage}`
);
} else if (match && !match[1]) {
assert.ok(true, `Received failing Ember.${methodName} call with message: ${match[0]}`);
} else if (match && match[1]) {
Expand All @@ -116,16 +153,16 @@ MethodCallTracker.prototype = {
} else if (actual[1]) {
assert.ok(
false,
`Did not receive failing Ember.${methodName} call matching '${expected}', last was success with '${
`Did not receive failing Ember.${methodName} call matching '${expectedMessage}' ${expectedOptionsMessage}, last was success with '${
actual[0]
}'`
}' ${actualOptionsMessage}`
);
} else if (!actual[1]) {
assert.ok(
false,
`Did not receive failing Ember.${methodName} call matching '${expected}', last was failure with '${
`Did not receive failing Ember.${methodName} call matching '${expectedMessage}' ${expectedOptionsMessage}, last was failure with '${
actual[0]
}'`
}' ${actualOptionsMessage}`
);
}
}
Expand Down