Skip to content

Commit

Permalink
Merge pull request #15900 from thoov/warn-assert
Browse files Browse the repository at this point in the history
[CLEANUP] Change warn deprecations to asserts
  • Loading branch information
rwjblue authored Nov 30, 2017
2 parents c27cd04 + 64d4708 commit e751389
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
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' });
});

0 comments on commit e751389

Please sign in to comment.