Skip to content

Commit

Permalink
Support for the "silent" mode for logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Oct 25, 2024
1 parent d14666d commit 013bf89
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function publishPackageOnNpmCallback( packagePath, taskOpti
await tools.shExec( `npm publish --access=public --tag ${ taskOptions.npmTag }`, {
cwd: packagePath,
async: true,
verbosity: 'error'
verbosity: 'silent'
} );

// Do nothing if `npm publish` says "OK". We cannot trust anything npm says.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe( 'publishPackageOnNpmCallback()', () => {
} );
} );

it( 'should set the verbosity level to "error" during publishing packages', () => {
it( 'should set the verbosity level to "silent" during publishing packages', () => {
const packagePath = '/workspace/ckeditor5/packages/ckeditor5-foo';

return publishPackageOnNpmCallback( packagePath, { npmTag: 'nightly' } )
Expand All @@ -56,7 +56,7 @@ describe( 'publishPackageOnNpmCallback()', () => {
expect( tools.shExec ).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining( {
verbosity: 'error'
verbosity: 'silent'
} )
);
} );
Expand Down
8 changes: 2 additions & 6 deletions packages/ckeditor5-dev-utils/lib/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import chalk from 'chalk';

const levels = new Map();

// Displays everything.
levels.set( 'silent', new Set( [] ) );
levels.set( 'info', new Set( [ 'info' ] ) );

// Displays warning and error logs.
levels.set( 'warning', new Set( [ 'info', 'warning' ] ) );

// Displays error logs only.
levels.set( 'error', new Set( [ 'info', 'warning', 'error' ] ) );

/**
Expand Down Expand Up @@ -45,7 +41,7 @@ levels.set( 'error', new Set( [ 'info', 'warning', 'error' ] ) );
*
* Additionally, the `logger#error()` method prints the error instance if provided as the second argument.
*
* @param {string} moduleVerbosity='info' Level of the verbosity for all log methods.
* @param {'info'|'warning'|'error'|'silent'} [moduleVerbosity='info'] Level of the verbosity for all log methods.
* @returns {object} logger
* @returns {Function} logger.info
* @returns {Function} logger.warning
Expand Down
30 changes: 30 additions & 0 deletions packages/ckeditor5-dev-utils/tests/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ describe( 'logger()', () => {
} );
} );

describe( 'verbosity = silent', () => {
beforeEach( () => {
log = logger( 'silent' );
} );

describe( 'logger.info()', () => {
it( 'should not log any message', () => {
log.info( logMessage );

expect( vi.mocked( console ).log ).not.toHaveBeenCalled();
} );
} );

describe( 'logger.warning()', () => {
it( 'should not log any message', () => {
log.warning( logMessage );

expect( vi.mocked( console ).log ).not.toHaveBeenCalled();
} );
} );

describe( 'logger.error()', () => {
it( 'should not log any message', () => {
log.error( logMessage );

expect( vi.mocked( console ).log ).not.toHaveBeenCalled();
} );
} );
} );

describe( 'uses default verbosity', () => {
beforeEach( () => {
log = logger();
Expand Down

0 comments on commit 013bf89

Please sign in to comment.