-
Notifications
You must be signed in to change notification settings - Fork 663
Description
Feature Description
Provide a way for fine-grained control of deprecation warnings, allowing each deprecation to be "silenced" one-by-one
Make config.showDeprecationWarnings to accept not only boolean, but also a fine-grained config, for example:
config.showDeprecationWarnings = [
'find',
'findAll',
'isVisible',
'options.attachToDocument',
'options.methods'
];Alternate approaches:
- new config
silenceDeprecationWarningswith reverse behavior. The benefit ofsilenceDeprecationWarningsis that if new deprecation will be added - it will compain about it whileshowDeprecationWarningswill silently swallow it - allowing to pass custom
warnDeprecatedfunction, so warnings could be handled in other way
Problem
When you have huge codebase it is a real pain to deal with all deprecations immediately. On the other side showDeprecationWarnings silences all warnings and will not complain if people are using deprecated function, which was already "cleaned" from the codebase
Expected behavior
VTU should show deprecation warnings for elements, specified in showDeprecationWarnings but keep silence for other deprecations
Alternatives
Right now I have such ugly code in setting my tests in Jest:
const originalConsoleError = global.console.error;
const ALLOWED_DEPRECATION_MESSAGES = [
...[
// subject for automated codemod
'`find`',
'`findAll`',
// requires custom matcher
'isVisible',
'setMethods',
// 'is',
].map(method => `${method} is deprecated and will be removed in the next major version.`),
'options.attachToDocument is deprecated in favor of options.attachTo', // +
'overwriting methods via the `methods` property is deprecated',
'name is deprecated and will be removed in the next major version', // easy
];
global.console.error = function consoleErrorWithSuppression(message, ...args) {
if (
message.startsWith('[vue-test-utils]') &&
ALLOWED_DEPRECATION_MESSAGES.find(warning => message.includes(warning))
) {
console.warn(message, ...args);
}
originalConsoleError.call(console, message, ...args);
};I'm quite uncomfortable with this hack and will be happy to submit PR as soon as the desired direction will be selected