Skip to content

Add fine-grained control for deprecation warnings #1672

Closed
@xanf

Description

@xanf

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 silenceDeprecationWarnings with reverse behavior. The benefit of silenceDeprecationWarnings is that if new deprecation will be added - it will compain about it while showDeprecationWarnings will silently swallow it
  • allowing to pass custom warnDeprecated function, 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions