From 013bf89ddd3694c837173b7e1581e704f9ecc093 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 25 Oct 2024 13:24:02 +0200 Subject: [PATCH] Support for the "silent" mode for logger. --- .../lib/utils/publishpackageonnpmcallback.js | 2 +- .../utils/publishpackageonnpmcallback.js | 4 +-- .../ckeditor5-dev-utils/lib/logger/index.js | 8 ++--- .../ckeditor5-dev-utils/tests/logger/index.js | 30 +++++++++++++++++++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js b/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js index ae48db06d..2d8f33087 100644 --- a/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js +++ b/packages/ckeditor5-dev-release-tools/lib/utils/publishpackageonnpmcallback.js @@ -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. diff --git a/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js b/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js index 1afefa50a..4c9582fd3 100644 --- a/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js +++ b/packages/ckeditor5-dev-release-tools/tests/utils/publishpackageonnpmcallback.js @@ -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' } ) @@ -56,7 +56,7 @@ describe( 'publishPackageOnNpmCallback()', () => { expect( tools.shExec ).toHaveBeenCalledWith( expect.anything(), expect.objectContaining( { - verbosity: 'error' + verbosity: 'silent' } ) ); } ); diff --git a/packages/ckeditor5-dev-utils/lib/logger/index.js b/packages/ckeditor5-dev-utils/lib/logger/index.js index d180cfb1d..cc0285e28 100644 --- a/packages/ckeditor5-dev-utils/lib/logger/index.js +++ b/packages/ckeditor5-dev-utils/lib/logger/index.js @@ -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' ] ) ); /** @@ -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 diff --git a/packages/ckeditor5-dev-utils/tests/logger/index.js b/packages/ckeditor5-dev-utils/tests/logger/index.js index 2ecdf99d4..e4de032e3 100644 --- a/packages/ckeditor5-dev-utils/tests/logger/index.js +++ b/packages/ckeditor5-dev-utils/tests/logger/index.js @@ -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();