Skip to content

Commit 422c25f

Browse files
committed
Avoid several Ember API deprecations
* Avoid the Ember global in workflow runtime code. * Ensure the test suite isn't using deprecated API by throwing unhandled deprecations. Address several uses of deprecated Ember API. * Bump ember-jquery to get emberjs/ember-jquery#321
1 parent 92196df commit 422c25f

File tree

5 files changed

+105
-9
lines changed

5 files changed

+105
-9
lines changed

config/ember-try.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ module.exports = async function () {
8181
npm: {
8282
devDependencies: {
8383
'ember-source': emberReleaseVersion,
84-
'@ember/jquery': '^1.1.0',
84+
'@ember/jquery':
85+
'emberjs/ember-jquery#84e8353b3650133ec784a8a19e01c15074338d83',
8586
},
8687
},
8788
},

tests/acceptance/workflow-config-test.js

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,26 @@ module('workflow config', function (hooks) {
1616
window.Testem.handleConsoleMessage = originalWarn;
1717
});
1818

19+
<<<<<<< HEAD
1920
test('deprecation silenced with string matcher', (assert) => {
2021
deprecate('silence-me', false, {
2122
since: '2.0.0',
23+
=======
24+
test('deprecation silenced with message matcher', (assert) => {
25+
deprecate('silence-strict', false, {
26+
since: 'now',
27+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
2228
until: 'forever',
2329
id: 'test',
2430
for: 'testing',
2531
});
2632
assert.ok(true, 'Deprecation did not raise');
2733
});
2834

29-
test('deprecation logs with string matcher', (assert) => {
35+
test('deprecation logs with message matcher', (assert) => {
3036
assert.expect(1);
3137

32-
let message = 'log-me';
38+
let message = 'log-strict';
3339
window.Testem.handleConsoleMessage = function (passedMessage) {
3440
assert.ok(
3541
passedMessage.indexOf('DEPRECATION: ' + message) === 0,
@@ -44,11 +50,51 @@ module('workflow config', function (hooks) {
4450
});
4551
});
4652

53+
test('deprecation logs with message matcher by regex', (assert) => {
54+
assert.expect(1);
55+
56+
let message = ' foo log-match foo';
57+
window.Testem.handleConsoleMessage = function (passedMessage) {
58+
assert.ok(
59+
passedMessage.indexOf('DEPRECATION: ' + message) === 0,
60+
'deprecation logs'
61+
);
62+
};
63+
deprecate(message, false, {
64+
since: 'now',
65+
until: 'forever',
66+
id: 'test',
67+
for: 'testing',
68+
});
69+
});
70+
71+
test('deprecation logs with id matcher', (assert) => {
72+
assert.expect(1);
73+
74+
let message = ' foo foo';
75+
window.Testem.handleConsoleMessage = function (passedMessage) {
76+
assert.ok(
77+
passedMessage.indexOf('DEPRECATION: ' + message) === 0,
78+
'deprecation logs'
79+
);
80+
};
81+
deprecate(message, false, {
82+
since: 'now',
83+
until: 'forever',
84+
id: 'log-strict',
85+
for: 'testing',
86+
});
87+
});
88+
4789
test('deprecation thrown with string matcher', (assert) => {
48-
Ember.ENV.RAISE_ON_DEPRECATION = true;
4990
assert.throws(function () {
91+
<<<<<<< HEAD
5092
deprecate('throw-me', false, {
5193
since: '2.0.0',
94+
=======
95+
deprecate('throw-strict', false, {
96+
since: 'now',
97+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
5298
until: 'forever',
5399
id: 'test',
54100
for: 'testing',
@@ -59,6 +105,7 @@ module('workflow config', function (hooks) {
59105
test('deprecation logs with id matcher', (assert) => {
60106
assert.expect(1);
61107

108+
<<<<<<< HEAD
62109
let message = 'arbitrary-unmatched-message';
63110
let id = 'log-me';
64111
let options = {
@@ -67,6 +114,11 @@ module('workflow config', function (hooks) {
67114
until: '3.0.0',
68115
for: 'testing',
69116
};
117+
=======
118+
let message = 'id matched (log-match)';
119+
let id = 'id-matched';
120+
let options = { id, since: '2.0.0', until: '3.0.0', for: 'testing' };
121+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
70122
let expected = `DEPRECATION: ${message}`;
71123
window.Testem.handleConsoleMessage = function (passedMessage) {
72124
assert.equal(
@@ -79,6 +131,7 @@ module('workflow config', function (hooks) {
79131
});
80132

81133
test('deprecation limits each id to 100 console.logs', (assert) => {
134+
<<<<<<< HEAD
82135
assert.expect(104);
83136
let limit = 100;
84137

@@ -90,6 +143,13 @@ module('workflow config', function (hooks) {
90143
until: '3.0.0',
91144
for: 'testing',
92145
};
146+
=======
147+
let limit = 100;
148+
149+
let message = 'first (log-match)';
150+
let id = 'first-and-unique-to-100-limit-test';
151+
let options = { id, since: '2.0.0', until: '3.0.0', for: 'testing' };
152+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
93153
let expected = `DEPRECATION: ${message}`;
94154

95155
let count = 0;
@@ -119,8 +179,13 @@ module('workflow config', function (hooks) {
119179

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

182+
<<<<<<< HEAD
122183
let secondMessage = 'log-me';
123184
let secondId = 'second-and-unique-to-limit-test';
185+
=======
186+
let secondMessage = 'second (log-match)';
187+
let secondId = 'second-and-unique-to-100-limit-test';
188+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
124189
let secondOptions = {
125190
id: secondId,
126191
since: '2.0.0',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
/* globals self */
22
self.deprecationWorkflow = self.deprecationWorkflow || {};
33
self.deprecationWorkflow.config = {
4+
throwOnUnhandled: true,
45
workflow: [
6+
/*
7+
* Actual controlled deprecations
8+
*/
9+
{ matchId: 'ember-global', handler: 'log' },
10+
11+
/*
12+
* Deprecation setup for tests
13+
*/
14+
<<<<<<< HEAD
515
{ matchMessage: 'silence-me', handler: 'silence' },
616
{ matchMessage: 'log-me', handler: 'log' },
717
{ matchMessage: 'throw-me', handler: 'throw' },
818
{ matchId: 'log-me', handler: 'log' },
19+
=======
20+
{ matchId: 'silence-strict', handler: 'silence' },
21+
{ matchMessage: 'silence-strict', handler: 'silence' },
22+
{ matchMessage: /silence-match/, handler: 'silence' },
23+
{ matchId: 'log-strict', handler: 'log' },
24+
{ matchMessage: 'log-strict', handler: 'log' },
25+
{ matchMessage: /log-match/, handler: 'log' },
26+
{ matchMessage: 'throw-strict', handler: 'throw' },
27+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
928
],
1029
};

tests/unit/deprecation-collector-test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ import Ember from 'ember';
55
import { module } from 'qunit';
66
import test from '../helpers/debug-test';
77

8-
let originalWarn;
8+
let originalWarn, originalConfig;
99

1010
module('deprecation collector', function (hooks) {
1111
hooks.beforeEach(function () {
1212
originalWarn = console.warn;
13+
14+
/*
15+
* Clear config for these tests
16+
*/
17+
originalConfig = self.deprecationWorkflow.config;
18+
self.deprecationWorkflow.config = null;
1319
});
1420

1521
hooks.afterEach(function () {
1622
Ember.ENV.RAISE_ON_DEPRECATION = false;
17-
self.deprecationWorkflow.config = null;
23+
self.deprecationWorkflow.config = originalConfig;
1824
self.deprecationWorkflow.deprecationLog = { messages: {} };
1925
console.warn = originalWarn;
2026
});
@@ -45,6 +51,7 @@ self.deprecationWorkflow.config = {
4551
);
4652
});
4753

54+
<<<<<<< HEAD
4855
test('deprecation does not choke when called without soon-to-be-required options', (assert) => {
4956
deprecate('silence-me', undefined, {
5057
id: 'silence-me',
@@ -55,6 +62,8 @@ self.deprecationWorkflow.config = {
5562
assert.ok(true, 'Deprecation did not raise');
5663
});
5764

65+
=======
66+
>>>>>>> c9e2029 (Many fixes, limit system and tests)
5867
test('deprecations are not duplicated', function (assert) {
5968
deprecate('First deprecation', false, {
6069
id: 'first',

vendor/ember-cli-deprecation-workflow/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals self */
1+
;* globals self */
22

33
const LOG_LIMIT = 100;
44

@@ -30,7 +30,9 @@ const LOG_LIMIT = 100;
3030
}
3131
}
3232

33-
Ember.Debug.registerDeprecationHandler(function handleDeprecationWorkflow(message, options, next){
33+
let registerDeprecationHandler = require.has('@ember/debug') ? require('@ember/debug').registerDeprecationHandler : Ember.Debug.registerDeprecationHandler;
34+
35+
registerDeprecationHandler(function handleDeprecationWorkflow(message, options, next){
3436
let config = self.deprecationWorkflow.config || {};
3537

3638
let matchingWorkflow = detectWorkflow(config, message, options);
@@ -68,7 +70,7 @@ const LOG_LIMIT = 100;
6870
}
6971
});
7072

71-
Ember.Debug.registerDeprecationHandler(function deprecationCollector(message, options, next){
73+
registerDeprecationHandler(function deprecationCollector(message, options, next){
7274
let key = options && options.id || message;
7375
let matchKey = options && key === options.id ? 'matchId' : 'matchMessage';
7476

0 commit comments

Comments
 (0)