Skip to content

Commit 89cd5f3

Browse files
justinhelmereddyerburgh
authored andcommitted
refactor: add deprecation message lib (#113)
1 parent b40094f commit 89cd5f3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/deprecate.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const chalk = require('chalk')
2+
const logger = require('./logger')
3+
4+
const replace = (oldThing, newThing) => {
5+
logger.warn(chalk.bold.yellow('Deprecation Warning:'), '\n')
6+
logger.warn(chalk.yellow(`Option ${chalk.bold(`"${oldThing}"`)} has been removed, and replaced by ${chalk.bold(`"${newThing}"`)}`), '\n')
7+
logger.warn(chalk.yellow('This option will be removed in the next major version of `vue-jest`. Please update your configuration.'), '\n')
8+
logger.warn(chalk.bold.yellow('Configuration Documentation:'))
9+
logger.warn(chalk.yellow('https://github.com/vuejs/vue-jest'))
10+
}
11+
12+
module.exports = { replace }

test/deprecate.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import chalk from 'chalk'
2+
import { replace } from '../lib/deprecate'
3+
import logger from '../lib/logger'
4+
5+
describe('display deprecation messaging', () => {
6+
it('should format the warning with the correct information', () => {
7+
logger.warn = jest.fn()
8+
replace('foo', 'bar')
9+
expect(logger.warn).toHaveBeenCalledWith(chalk.bold.yellow('Deprecation Warning:'), '\n')
10+
expect(logger.warn).toHaveBeenCalledWith(chalk.yellow(`Option ${chalk.bold('"foo"')} has been removed, and replaced by ${chalk.bold('"bar"')}`), '\n')
11+
logger.warn.mockRestore()
12+
})
13+
})

0 commit comments

Comments
 (0)