Skip to content

Commit

Permalink
Many fixes, limit system and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed May 28, 2021
1 parent 22dbfb0 commit c9e2029
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 45 deletions.
64 changes: 47 additions & 17 deletions tests/acceptance/workflow-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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) {
Expand All @@ -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}`;

Expand Down Expand Up @@ -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',
Expand Down
13 changes: 8 additions & 5 deletions tests/dummy/config/deprecation-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
};
7 changes: 0 additions & 7 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
{{content-for "body"}}
{{content-for "test-body"}}

<div id="qunit"></div>
<div id="qunit-fixture">
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
</div>

<script src="/testem.js" integrity=""></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
Expand Down
21 changes: 6 additions & 15 deletions tests/unit/deprecation-collector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion vendor/ember-cli-deprecation-workflow/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c9e2029

Please sign in to comment.