Skip to content

Commit 2dfaf4d

Browse files
authored
Merge pull request #124 from mixonic/mixonic/test-cleanup
Clean up test config for clarity
2 parents 92196df + b8e6d4d commit 2dfaf4d

3 files changed

Lines changed: 70 additions & 37 deletions

File tree

tests/acceptance/workflow-config-test.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { deprecate } from '@ember/debug';
2-
import Ember from 'ember';
32
import { module } from 'qunit';
43
import test from '../helpers/debug-test';
54

@@ -11,13 +10,12 @@ module('workflow config', function (hooks) {
1110
});
1211

1312
hooks.afterEach(function () {
14-
Ember.ENV.RAISE_ON_DEPRECATION = false;
1513
window.deprecationWorkflow.deprecationLog = { messages: {} };
1614
window.Testem.handleConsoleMessage = originalWarn;
1715
});
1816

1917
test('deprecation silenced with string matcher', (assert) => {
20-
deprecate('silence-me', false, {
18+
deprecate('silence-strict', false, {
2119
since: '2.0.0',
2220
until: 'forever',
2321
id: 'test',
@@ -26,10 +24,10 @@ module('workflow config', function (hooks) {
2624
assert.ok(true, 'Deprecation did not raise');
2725
});
2826

29-
test('deprecation logs with string matcher', (assert) => {
27+
test('deprecation logs with message matcher', (assert) => {
3028
assert.expect(1);
3129

32-
let message = 'log-me';
30+
let message = 'log-strict';
3331
window.Testem.handleConsoleMessage = function (passedMessage) {
3432
assert.ok(
3533
passedMessage.indexOf('DEPRECATION: ' + message) === 0,
@@ -44,10 +42,45 @@ module('workflow config', function (hooks) {
4442
});
4543
});
4644

45+
test('deprecation logs with message matcher by regex', (assert) => {
46+
assert.expect(1);
47+
48+
let message = ' foo log-match foo';
49+
window.Testem.handleConsoleMessage = function (passedMessage) {
50+
assert.ok(
51+
passedMessage.indexOf('DEPRECATION: ' + message) === 0,
52+
'deprecation logs'
53+
);
54+
};
55+
deprecate(message, false, {
56+
since: 'now',
57+
until: 'forever',
58+
id: 'test',
59+
for: 'testing',
60+
});
61+
});
62+
63+
test('deprecation logs with id matcher', (assert) => {
64+
assert.expect(1);
65+
66+
let message = ' foo foo';
67+
window.Testem.handleConsoleMessage = function (passedMessage) {
68+
assert.ok(
69+
passedMessage.indexOf('DEPRECATION: ' + message) === 0,
70+
'deprecation logs'
71+
);
72+
};
73+
deprecate(message, false, {
74+
since: 'now',
75+
until: 'forever',
76+
id: 'log-strict',
77+
for: 'testing',
78+
});
79+
});
80+
4781
test('deprecation thrown with string matcher', (assert) => {
48-
Ember.ENV.RAISE_ON_DEPRECATION = true;
4982
assert.throws(function () {
50-
deprecate('throw-me', false, {
83+
deprecate('throw-strict', false, {
5184
since: '2.0.0',
5285
until: 'forever',
5386
id: 'test',
@@ -60,7 +93,7 @@ module('workflow config', function (hooks) {
6093
assert.expect(1);
6194

6295
let message = 'arbitrary-unmatched-message';
63-
let id = 'log-me';
96+
let id = 'log-strict';
6497
let options = {
6598
id,
6699
since: '2.0.0',
@@ -82,7 +115,7 @@ module('workflow config', function (hooks) {
82115
assert.expect(104);
83116
let limit = 100;
84117

85-
let message = 'log-me';
118+
let message = 'log-match';
86119
let id = 'first-and-unique-to-limit-test';
87120
let options = {
88121
id,
@@ -119,7 +152,7 @@ module('workflow config', function (hooks) {
119152

120153
assert.equal(count, limit, 'logged 100 times, including final notice');
121154

122-
let secondMessage = 'log-me';
155+
let secondMessage = 'log-strict';
123156
let secondId = 'second-and-unique-to-limit-test';
124157
let secondOptions = {
125158
id: secondId,
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
/* globals self */
22
self.deprecationWorkflow = self.deprecationWorkflow || {};
33
self.deprecationWorkflow.config = {
4+
throwOnUnhandled: true,
45
workflow: [
5-
{ matchMessage: 'silence-me', handler: 'silence' },
6-
{ matchMessage: 'log-me', handler: 'log' },
7-
{ matchMessage: 'throw-me', handler: 'throw' },
8-
{ matchId: 'log-me', handler: 'log' },
6+
/*
7+
* Actual controlled deprecations
8+
*/
9+
{ matchId: 'ember-global', handler: 'log' },
10+
{ matchId: 'ember.component.reopen', handler: 'log' },
11+
12+
/*
13+
* Deprecation setup for tests
14+
*/
15+
{ matchId: 'silence-strict', handler: 'silence' },
16+
{ matchMessage: 'silence-strict', handler: 'silence' },
17+
{ matchMessage: /silence-match/, handler: 'silence' },
18+
19+
{ matchId: 'log-strict', handler: 'log' },
20+
{ matchMessage: 'log-strict', handler: 'log' },
21+
{ matchMessage: /log-match/, handler: 'log' },
22+
23+
{ matchMessage: 'throw-strict', handler: 'throw' },
924
],
1025
};

tests/unit/deprecation-collector-test.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
/* eslint no-console: 0 */
22

33
import { deprecate } from '@ember/debug';
4-
import Ember from 'ember';
54
import { module } from 'qunit';
65
import test from '../helpers/debug-test';
76

8-
let originalWarn;
7+
let originalWarn, originalConfig;
98

109
module('deprecation collector', function (hooks) {
1110
hooks.beforeEach(function () {
1211
originalWarn = console.warn;
12+
13+
/*
14+
* Clear config for these tests
15+
*/
16+
originalConfig = self.deprecationWorkflow.config;
17+
self.deprecationWorkflow.config = null;
1318
});
1419

1520
hooks.afterEach(function () {
16-
Ember.ENV.RAISE_ON_DEPRECATION = false;
17-
self.deprecationWorkflow.config = null;
21+
self.deprecationWorkflow.config = originalConfig;
1822
self.deprecationWorkflow.deprecationLog = { messages: {} };
1923
console.warn = originalWarn;
2024
});
@@ -45,16 +49,6 @@ self.deprecationWorkflow.config = {
4549
);
4650
});
4751

48-
test('deprecation does not choke when called without soon-to-be-required options', (assert) => {
49-
deprecate('silence-me', undefined, {
50-
id: 'silence-me',
51-
since: 'the beginning',
52-
until: 'forever',
53-
for: 'testing',
54-
});
55-
assert.ok(true, 'Deprecation did not raise');
56-
});
57-
5852
test('deprecations are not duplicated', function (assert) {
5953
deprecate('First deprecation', false, {
6054
id: 'first',
@@ -99,8 +93,6 @@ self.deprecationWorkflow.config = {
9993
test('specifying `throwOnUnhandled` as true raises', function (assert) {
10094
assert.expect(2);
10195

102-
Ember.ENV.RAISE_ON_DEPRECATION = false;
103-
10496
self.deprecationWorkflow.config = {
10597
throwOnUnhandled: true,
10698
workflow: [{ handler: 'silence', matchMessage: 'Sshhhhh!!' }],
@@ -131,8 +123,6 @@ self.deprecationWorkflow.config = {
131123
test('specifying `throwOnUnhandled` as false does nothing', function (assert) {
132124
assert.expect(1);
133125

134-
Ember.ENV.RAISE_ON_DEPRECATION = false;
135-
136126
self.deprecationWorkflow.config = {
137127
throwOnUnhandled: false,
138128
};
@@ -147,7 +137,6 @@ self.deprecationWorkflow.config = {
147137
});
148138

149139
test('deprecation silenced with string matcher', (assert) => {
150-
Ember.ENV.RAISE_ON_DEPRECATION = true;
151140
self.deprecationWorkflow.config = {
152141
workflow: [{ matchMessage: 'Interesting', handler: 'silence' }],
153142
};
@@ -196,7 +185,6 @@ self.deprecationWorkflow.config = {
196185
});
197186

198187
test('deprecation silenced with regex matcher', (assert) => {
199-
Ember.ENV.RAISE_ON_DEPRECATION = true;
200188
self.deprecationWorkflow.config = {
201189
workflow: [{ matchMessage: /Inter/, handler: 'silence' }],
202190
};
@@ -264,7 +252,6 @@ self.deprecationWorkflow.config = {
264252
});
265253

266254
test('deprecation silenced with id matcher', (assert) => {
267-
Ember.ENV.RAISE_ON_DEPRECATION = true;
268255
self.deprecationWorkflow.config = {
269256
workflow: [{ matchId: 'ember.deprecation-workflow', handler: 'silence' }],
270257
};
@@ -316,8 +303,6 @@ self.deprecationWorkflow.config = {
316303
test('deprecation logging happens even if `throwOnUnhandled` is true', function (assert) {
317304
assert.expect(2);
318305

319-
Ember.ENV.RAISE_ON_DEPRECATION = false;
320-
321306
self.deprecationWorkflow.config = {
322307
throwOnUnhandled: true,
323308
};

0 commit comments

Comments
 (0)