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

[CLEANUP] Change warn deprecations to asserts #15900

Merged
merged 1 commit into from
Nov 30, 2017
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
12 changes: 10 additions & 2 deletions packages/ember-debug/lib/warn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';

import Logger from 'ember-console';
import deprecate from './deprecate';
import { assert } from './index';
import { registerHandler as genericRegisterHandler, invoke } from './handlers';

let registerHandler = () => {};
Expand Down Expand Up @@ -84,7 +86,13 @@ if (DEBUG) {
options = test;
test = false;
}
if (!options) {

if (ENV._ENABLE_WARN_OPTIONS_SUPPORT !== true) {
assert(missingOptionsDeprecation, options);
assert(missingOptionsIdDeprecation, options && options.id);
}

if (!options && ENV._ENABLE_WARN_OPTIONS_SUPPORT === true) {
deprecate(
missingOptionsDeprecation,
false,
Expand All @@ -96,7 +104,7 @@ if (DEBUG) {
);
}

if (options && !options.id) {
if (options && !options.id && ENV._ENABLE_WARN_OPTIONS_SUPPORT === true) {
deprecate(
missingOptionsIdDeprecation,
false,
Expand Down
51 changes: 51 additions & 0 deletions packages/ember-debug/tests/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import {

let originalEnvValue;
let originalDeprecateHandler;
let originalWarnOptions;

QUnit.module('ember-debug', {
setup() {
originalEnvValue = ENV.RAISE_ON_DEPRECATION;
originalDeprecateHandler = HANDLERS.deprecate;
originalWarnOptions = ENV._ENABLE_WARN_OPTIONS_SUPPORT;

ENV.RAISE_ON_DEPRECATION = true;
},
Expand All @@ -35,6 +37,7 @@ QUnit.module('ember-debug', {
HANDLERS.deprecate = originalDeprecateHandler;

ENV.RAISE_ON_DEPRECATION = originalEnvValue;
ENV._ENABLE_WARN_OPTIONS_SUPPORT = originalWarnOptions;
}
});

Expand Down Expand Up @@ -245,6 +248,8 @@ QUnit.test('Ember.deprecate without options.until triggers a deprecation', funct
QUnit.test('warn without options triggers a deprecation', function(assert) {
assert.expect(2);

ENV._ENABLE_WARN_OPTIONS_SUPPORT = true;

registerHandler(function(message) {
assert.equal(message, missingWarnOptionsDeprecation, 'deprecation is triggered when options is missing');
});
Expand All @@ -256,9 +261,21 @@ QUnit.test('warn without options triggers a deprecation', function(assert) {
warn('foo');
});

QUnit.test('warn without options triggers an assert', function(assert) {
assert.expect(1);

assert.throws(
() => warn('foo'),
new RegExp(missingWarnOptionsDeprecation),
'deprecation is triggered when options is missing'
);
});

QUnit.test('warn without options.id triggers a deprecation', function(assert) {
assert.expect(2);

ENV._ENABLE_WARN_OPTIONS_SUPPORT = true;

registerHandler(function(message) {
assert.equal(message, missingWarnOptionsIdDeprecation, 'deprecation is triggered when options is missing');
});
Expand All @@ -270,9 +287,21 @@ QUnit.test('warn without options.id triggers a deprecation', function(assert) {
warn('foo', false, { });
});

QUnit.test('warn without options.id triggers an assertion', function(assert) {
assert.expect(1);

assert.throws(
() => warn('foo', false, { }),
new RegExp(missingWarnOptionsIdDeprecation),
'deprecation is triggered when options is missing'
);
});

QUnit.test('warn without options.id nor test triggers a deprecation', function(assert) {
assert.expect(2);

ENV._ENABLE_WARN_OPTIONS_SUPPORT = true;

registerHandler(function(message) {
assert.equal(message, missingWarnOptionsIdDeprecation, 'deprecation is triggered when options is missing');
});
Expand All @@ -284,9 +313,21 @@ QUnit.test('warn without options.id nor test triggers a deprecation', function(a
warn('foo', { });
});

QUnit.test('warn without options.id nor test triggers an assertion', function(assert) {
assert.expect(1);

assert.throws(
() => warn('foo', { }),
new RegExp(missingWarnOptionsIdDeprecation),
'deprecation is triggered when options is missing'
);
});

QUnit.test('warn without test but with options does not trigger a deprecation', function(assert) {
assert.expect(1);

ENV._ENABLE_WARN_OPTIONS_SUPPORT = true;

registerHandler(function(message) {
assert.ok(false, `there should be no deprecation ${message}`);
});
Expand All @@ -297,3 +338,13 @@ QUnit.test('warn without test but with options does not trigger a deprecation',

warn('foo', { id: 'ember-debug.do-not-raise' });
});

QUnit.test('warn without test but with options does not trigger an assertion', function(assert) {
assert.expect(1);

registerWarnHandler(function(message) {
assert.equal(message, 'foo', 'warning was triggered');
});

warn('foo', { id: 'ember-debug.do-not-raise' });
});