From 334e0ccc0295450d0c6640ba919ed032550766c7 Mon Sep 17 00:00:00 2001 From: Justin Helmer Date: Thu, 4 Oct 2018 19:52:09 -0700 Subject: [PATCH] feat: add deprecation message lib --- lib/deprecate.js | 12 ++++++++++++ test/deprecate.spec.js | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/deprecate.js create mode 100644 test/deprecate.spec.js diff --git a/lib/deprecate.js b/lib/deprecate.js new file mode 100644 index 00000000..1df16988 --- /dev/null +++ b/lib/deprecate.js @@ -0,0 +1,12 @@ +const chalk = require('chalk') +const logger = require('./logger') + +const replace = (oldThing, newThing) => { + logger.warn(chalk.bold.yellow('Deprecation Warning:'), '\n') + logger.warn(chalk.yellow(`Option ${chalk.bold(`"${oldThing}"`)} has been removed, and replaced by ${chalk.bold(`"${newThing}"`)}`), '\n') + logger.warn(chalk.yellow('This option will be removed in the next major version of `vue-jest`. Please update your configuration.'), '\n') + logger.warn(chalk.bold.yellow('Configuration Documentation:')) + logger.warn(chalk.yellow('https://github.com/vuejs/vue-jest')) +} + +module.exports = { replace } diff --git a/test/deprecate.spec.js b/test/deprecate.spec.js new file mode 100644 index 00000000..410f8bb3 --- /dev/null +++ b/test/deprecate.spec.js @@ -0,0 +1,13 @@ +import chalk from 'chalk' +import { replace } from '../lib/deprecate' +import logger from '../lib/logger' + +describe('display deprecation messaging', () => { + it('should format the warning with the correct information', () => { + logger.warn = jest.fn() + replace('foo', 'bar') + expect(logger.warn).toHaveBeenCalledWith(chalk.bold.yellow('Deprecation Warning:'), '\n') + expect(logger.warn).toHaveBeenCalledWith(chalk.yellow(`Option ${chalk.bold('"foo"')} has been removed, and replaced by ${chalk.bold('"bar"')}`), '\n') + logger.warn.mockRestore() + }) +})