diff --git a/tests/acceptance/workflow-config-test.js b/tests/acceptance/workflow-config-test.js index 1167da4..e1e89c9 100644 --- a/tests/acceptance/workflow-config-test.js +++ b/tests/acceptance/workflow-config-test.js @@ -16,8 +16,8 @@ module('workflow config', function (hooks) { window.Testem.handleConsoleMessage = originalWarn; }); - test('deprecation silenced with string matcher', (assert) => { - deprecate('silence-me', false, { + test('deprecation silenced with message matcher', (assert) => { + deprecate('silence-strict', false, { since: 'now', until: 'forever', id: 'test', @@ -26,10 +26,10 @@ module('workflow config', function (hooks) { assert.ok(true, 'Deprecation did not raise'); }); - test('deprecation logs with string matcher', (assert) => { + test('deprecation logs with message matcher', (assert) => { assert.expect(1); - let message = 'log-me'; + let message = 'log-strict'; window.Testem.handleConsoleMessage = function (passedMessage) { assert.ok( passedMessage.indexOf('DEPRECATION: ' + message) === 0, @@ -44,10 +44,45 @@ module('workflow config', function (hooks) { }); }); + test('deprecation logs with message matcher by regex', (assert) => { + assert.expect(1); + + let message = ' foo log-match foo'; + window.Testem.handleConsoleMessage = function (passedMessage) { + assert.ok( + passedMessage.indexOf('DEPRECATION: ' + message) === 0, + 'deprecation logs' + ); + }; + deprecate(message, false, { + since: 'now', + until: 'forever', + id: 'test', + for: 'testing', + }); + }); + + test('deprecation logs with id matcher', (assert) => { + assert.expect(1); + + let message = ' foo foo'; + window.Testem.handleConsoleMessage = function (passedMessage) { + assert.ok( + passedMessage.indexOf('DEPRECATION: ' + message) === 0, + 'deprecation logs' + ); + }; + deprecate(message, false, { + since: 'now', + until: 'forever', + id: 'log-strict', + for: 'testing', + }); + }); + test('deprecation thrown with string matcher', (assert) => { - Ember.ENV.RAISE_ON_DEPRECATION = true; assert.throws(function () { - deprecate('throw-me', false, { + deprecate('throw-strict', false, { since: 'now', until: 'forever', id: 'test', @@ -59,8 +94,8 @@ module('workflow config', function (hooks) { test('deprecation logs with id matcher', (assert) => { assert.expect(1); - let message = 'log-id'; - let id = 'ember.workflow'; + let message = 'id matched (log-match)'; + let id = 'id-matched'; let options = { id, since: '2.0.0', until: '3.0.0', for: 'testing' }; let expected = `DEPRECATION: ${message}`; window.Testem.handleConsoleMessage = function (passedMessage) { @@ -74,15 +109,10 @@ module('workflow config', function (hooks) { }); test('deprecation limits each id to 100 console.logs', (assert) => { - self.deprecationWorkflow.config = { - ...self.deprecationWorkflow.config, - throwOnUnhandled: false, - }; - let limit = 100; - let message = 'log-id'; - let id = 'ember.workflow'; + let message = 'first (log-match)'; + let id = 'first-and-unique-to-100-limit-test'; let options = { id, since: '2.0.0', until: '3.0.0', for: 'testing' }; let expected = `DEPRECATION: ${message}`; @@ -112,8 +142,8 @@ module('workflow config', function (hooks) { assert.equal(count, limit + 1, 'logged 101 times, including final notice'); - let secondMessage = 'log-id2'; - let secondId = 'ember.workflow2'; + let secondMessage = 'second (log-match)'; + let secondId = 'second-and-unique-to-100-limit-test'; let secondOptions = { id: secondId, since: '2.0.0', diff --git a/tests/dummy/config/deprecation-workflow.js b/tests/dummy/config/deprecation-workflow.js index 8ffd739..b330547 100644 --- a/tests/dummy/config/deprecation-workflow.js +++ b/tests/dummy/config/deprecation-workflow.js @@ -9,11 +9,14 @@ self.deprecationWorkflow.config = { { matchId: 'ember-global', handler: 'log' }, /* - * Deprecation setup for testsActual controlled deprecations + * Deprecation setup for tests */ - { matchMessage: 'silence-me', handler: 'silence' }, - { matchMessage: 'log-me', handler: 'log' }, - { matchMessage: 'throw-me', handler: 'throw' }, - { matchId: 'ember.workflow', handler: 'log' }, + { matchId: 'silence-strict', handler: 'silence' }, + { matchMessage: 'silence-strict', handler: 'silence' }, + { matchMessage: /silence-match/, handler: 'silence' }, + { matchId: 'log-strict', handler: 'log' }, + { matchMessage: 'log-strict', handler: 'log' }, + { matchMessage: /log-match/, handler: 'log' }, + { matchMessage: 'throw-strict', handler: 'throw' }, ], }; diff --git a/tests/index.html b/tests/index.html index 3eb848d..5209b85 100644 --- a/tests/index.html +++ b/tests/index.html @@ -21,13 +21,6 @@ {{content-for "body"}} {{content-for "test-body"}} -
-
-
-
-
-
- diff --git a/tests/unit/deprecation-collector-test.js b/tests/unit/deprecation-collector-test.js index 595318d..949017d 100644 --- a/tests/unit/deprecation-collector-test.js +++ b/tests/unit/deprecation-collector-test.js @@ -10,11 +10,12 @@ let originalWarn, originalConfig; module('deprecation collector', function (hooks) { hooks.beforeEach(function () { originalWarn = console.warn; - originalConfig = { ...self.deprecationWorkflow.config }; - self.deprecationWorkflow.config = { - ...originalConfig, - throwOnUnhandled: false, - }; + + /* + * Clear config for these tests + */ + originalConfig = self.deprecationWorkflow.config; + self.deprecationWorkflow.config = null; }); hooks.afterEach(function () { @@ -50,16 +51,6 @@ self.deprecationWorkflow.config = { ); }); - test('deprecation does not choke when called without soon-to-be-required options', (assert) => { - deprecate('silence-me', undefined, { - id: 'silence-me', - since: 'now', - until: 'forever', - for: 'testing', - }); - assert.ok(true, 'Deprecation did not raise'); - }); - test('deprecations are not duplicated', function (assert) { deprecate('First deprecation', false, { id: 'first', diff --git a/vendor/ember-cli-deprecation-workflow/main.js b/vendor/ember-cli-deprecation-workflow/main.js index 4a81133..f3c3936 100644 --- a/vendor/ember-cli-deprecation-workflow/main.js +++ b/vendor/ember-cli-deprecation-workflow/main.js @@ -50,7 +50,7 @@ const LOG_LIMIT = 100; case 'log': { let key = options && options.id || message; let count = self.deprecationWorkflow.logCounts[key] || 0; - self.deprecationWorkflow.logCounts[key] = count + 1; + self.deprecationWorkflow.logCounts[key] = ++count; if (count <= LOG_LIMIT) { console.warn('DEPRECATION: ' + message);