Skip to content

Commit

Permalink
Deprecated: Output an informational message for deprecation when no v…
Browse files Browse the repository at this point in the history
…ersion provided (#16774)

* Deprecated: Output an informational message for deprecation when no version provided
When there is no `options.version` param provided `deprecated` method outputs an informational message to the Web Console rather than warns as previously.

* Use warn for all deprecations

* Update unit tests for deprecated method to make them less confusing around version param
  • Loading branch information
gziolo committed Aug 29, 2019
1 parent 9ff7b52 commit feb2d0e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions packages/deprecated/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Master

### Bug Fix

- When there is no `options.version` param provided `deprecated` method warns with more relaxed tone.

## 2.0.4 (2019-01-03)

## 2.0.0 (2018-09-05)
Expand Down
4 changes: 2 additions & 2 deletions packages/deprecated/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export default function deprecated( feature, options = {} ) {
} = options;

const pluginMessage = plugin ? ` from ${ plugin }` : '';
const versionMessage = version ? `${ pluginMessage } in ${ version }` : '';
const versionMessage = version ? ` and will be removed${ pluginMessage } in version ${ version }` : '';
const useInsteadMessage = alternative ? ` Please use ${ alternative } instead.` : '';
const linkMessage = link ? ` See: ${ link }` : '';
const hintMessage = hint ? ` Note: ${ hint }` : '';
const message = `${ feature } is deprecated and will be removed${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;
const message = `${ feature } is deprecated${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;

// Skip if already logged.
if ( message in logged ) {
Expand Down
22 changes: 11 additions & 11 deletions packages/deprecated/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,61 @@ describe( 'deprecated', () => {
deprecated( 'Eating meat' );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed.'
'Eating meat is deprecated.'
);
} );

it( 'should show a deprecation warning with a version', () => {
deprecated( 'Eating meat', { version: 'the future' } );
deprecated( 'Eating meat', { version: '2020.01.01' } );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed in the future.'
'Eating meat is deprecated and will be removed in version 2020.01.01.'
);
} );

it( 'should show a deprecation warning with an alternative', () => {
deprecated( 'Eating meat', { version: 'the future', alternative: 'vegetables' } );
deprecated( 'Eating meat', { version: '2020.01.01', alternative: 'vegetables' } );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed in the future. Please use vegetables instead.'
'Eating meat is deprecated and will be removed in version 2020.01.01. Please use vegetables instead.'
);
} );

it( 'should show a deprecation warning with an alternative specific to a plugin', () => {
deprecated( 'Eating meat', {
version: 'the future',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
} );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead.'
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead.'
);
} );

it( 'should show a deprecation warning with a link', () => {
deprecated( 'Eating meat', {
version: 'the future',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
link: 'https://en.wikipedia.org/wiki/Vegetarianism',
} );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism'
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism'
);
} );

it( 'should show a deprecation warning with a hint', () => {
deprecated( 'Eating meat', {
version: 'the future',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
hint: 'You may find it beneficial to transition gradually.',
} );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
);
} );

Expand Down

0 comments on commit feb2d0e

Please sign in to comment.