Skip to content

Commit 863ed94

Browse files
[bugfix] Add stack traces to conditional deprecation warnings (#6450)
[bugfix] Add stack traces to conditional deprecations
1 parent 2c7abe1 commit 863ed94

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/lib/utils/deprecate.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function deprecateSimple(name, msg) {
6060
hooks.deprecationHandler(name, msg);
6161
}
6262
if (!deprecations[name]) {
63-
warn(msg);
63+
warn(msg + '\n' + new Error().stack);
6464
deprecations[name] = true;
6565
}
6666
}

‎src/test/moment/deprecate.js‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { module, test } from '../qunit';
2-
import { deprecate } from '../../lib/utils/deprecate';
2+
import { deprecate, deprecateSimple } from '../../lib/utils/deprecate';
33
import { hooks } from '../../lib/utils/hooks';
44

55
module('deprecate');
@@ -16,3 +16,34 @@ test('deprecate', function (assert) {
1616

1717
assert.expect(0);
1818
});
19+
20+
test('deprecateSimple includes a stack trace and warns once', function (assert) {
21+
var oldSuppressDeprecationWarnings = hooks.suppressDeprecationWarnings,
22+
oldWarn = console.warn,
23+
warnings = [];
24+
25+
hooks.suppressDeprecationWarnings = false;
26+
console.warn = function (msg) {
27+
warnings.push(msg);
28+
};
29+
30+
try {
31+
deprecateSimple(
32+
'testing deprecateSimple',
33+
'testing simple deprecation'
34+
);
35+
deprecateSimple(
36+
'testing deprecateSimple',
37+
'testing simple deprecation'
38+
);
39+
} finally {
40+
console.warn = oldWarn;
41+
hooks.suppressDeprecationWarnings = oldSuppressDeprecationWarnings;
42+
}
43+
44+
assert.equal(warnings.length, 1, 'warns once for each named deprecation');
45+
assert.ok(
46+
warnings[0].indexOf('testing simple deprecation\n') !== -1,
47+
'includes a stack trace after the message'
48+
);
49+
});

0 commit comments

Comments
 (0)