From 71efb2b21ce695248bb56f1521edb4c0b4f964dd Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Fri, 12 Mar 2021 09:52:05 +0100 Subject: [PATCH] Added the "--silent" flag to the manual test server. --- .../lib/tasks/runmanualtests.js | 7 ++- .../utils/automated-tests/parsearguments.js | 6 +- .../utils/manual-tests/compilehtmlfiles.js | 39 +++++++++++-- .../lib/utils/manual-tests/removedir.js | 15 +++-- .../tests/tasks/runmanualtests.js | 56 ++++++++++++++++++- .../utils/manual-tests/compilehtmlfiles.js | 29 ++++++++++ .../tests/utils/manual-tests/removedir.js | 10 ++++ 7 files changed, 146 insertions(+), 16 deletions(-) diff --git a/packages/ckeditor5-dev-tests/lib/tasks/runmanualtests.js b/packages/ckeditor5-dev-tests/lib/tasks/runmanualtests.js index 2bd093fb5..aacc998ab 100644 --- a/packages/ckeditor5-dev-tests/lib/tasks/runmanualtests.js +++ b/packages/ckeditor5-dev-tests/lib/tasks/runmanualtests.js @@ -25,6 +25,7 @@ const transformFileOptionToTestGlob = require( '../utils/transformfileoptiontote * @param {Array.} [options.additionalLanguages] Additional languages passed to `CKEditorWebpackPlugin`. * @param {Number} [options.port] A port number used by the `createManualTestServer`. * @param {String} [options.identityFile] A file that provides secret keys used in the test scripts. + * @param {Boolean} [options.silent=false] Whether to hide files that will be processed by the script. * @returns {Promise} */ module.exports = function runManualTests( options ) { @@ -40,9 +41,10 @@ module.exports = function runManualTests( options ) { const language = options.language; const additionalLanguages = options.additionalLanguages; const identityFile = normalizeIdentityFile( options.identityFile ); + const silent = options.silent || false; return Promise.resolve() - .then( () => removeDir( buildDir ) ) + .then( () => removeDir( buildDir, { silent } ) ) .then( () => Promise.all( [ compileManualTestScripts( { buildDir, @@ -57,7 +59,8 @@ module.exports = function runManualTests( options ) { buildDir, patterns, language, - additionalLanguages + additionalLanguages, + silent } ), copyAssets( buildDir ) ] ) ) diff --git a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js index d36eb2d0f..9a30b8947 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js +++ b/packages/ckeditor5-dev-tests/lib/utils/automated-tests/parsearguments.js @@ -35,7 +35,8 @@ module.exports = function parseArguments( args ) { 'server', 'source-map', 'verbose', - 'watch' + 'watch', + 'silent' ], alias: { @@ -64,7 +65,8 @@ module.exports = function parseArguments( args ) { 'identity-file': null, repositories: [], 'theme-path': null, - 'additional-languages': null + 'additional-languages': null, + silent: false } }; diff --git a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/compilehtmlfiles.js b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/compilehtmlfiles.js index fc5b24268..41c817c2f 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/compilehtmlfiles.js +++ b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/compilehtmlfiles.js @@ -27,11 +27,13 @@ const writer = new commonmark.HtmlRenderer(); * @param {Array.} options.patterns An array of patterns that resolve manual test scripts. * @param {String} options.language A language passed to `CKEditorWebpackPlugin`. * @param {Array.} [options.additionalLanguages] Additional languages passed to `CKEditorWebpackPlugin`. + * @param {Boolean} [options.silent=false] Whether to hide files that will be processed by the script. * @returns {Promise} */ module.exports = function compileHtmlFiles( options ) { const buildDir = options.buildDir; const viewTemplate = fs.readFileSync( path.join( __dirname, 'template.html' ), 'utf-8' ); + const silent = options.silent || false; const sourceMDFiles = options.patterns.reduce( ( arr, manualTestPattern ) => { return [ @@ -64,15 +66,38 @@ module.exports = function compileHtmlFiles( options ) { staticFiles.forEach( staticFile => copyStaticFile( buildDir, staticFile ) ); // Generate real HTML files out of the MD + HTML files of each test. - sourceFilePathBases.forEach( sourceFilePathBase => compileHtmlFile( buildDir, sourceFilePathBase, viewTemplate, languagesToLoad ) ); + sourceFilePathBases.forEach( sourceFilePathBase => compileHtmlFile( buildDir, { + filePath: sourceFilePathBase, + template: viewTemplate, + languages: languagesToLoad, + silent + } ) ); // Watch files and compile on change. watchFiles( [ ...sourceMDFiles, ...sourceHtmlFiles ], file => { - compileHtmlFile( buildDir, getFilePathWithoutExtension( file ), viewTemplate, languagesToLoad ); + compileHtmlFile( buildDir, { + filePath: getFilePathWithoutExtension( file ), + template: viewTemplate, + languages: languagesToLoad, + silent + } ); } ); }; -function compileHtmlFile( buildDir, sourceFilePathBase, viewTemplate, languagesToLoad ) { +/** + * @param {String} buildDir An absolute path to the directory where the processed file should be saved. + * @param {Object} options + * @param {String} options.filePath An absolute path to the manual test assets without the extension. + * @param {String} options.template The HTML template which will be merged with the manual test HTML file. + * @param {Array.} options.languages Name of translations that should be added to the manual test. + * @param {Boolean} options.silent Whether to hide files that will be processed by the script. + */ +function compileHtmlFile( buildDir, options ) { + const sourceFilePathBase = options.filePath; + const viewTemplate = options.template; + const languagesToLoad = options.languages; + const silent = options.silent; + const log = logger(); const sourceMDFilePath = sourceFilePathBase + '.md'; const sourceHtmlFilePath = sourceFilePathBase + '.html'; @@ -81,7 +106,9 @@ function compileHtmlFile( buildDir, sourceFilePathBase, viewTemplate, languagesT const absoluteHtmlFilePath = getRelativeFilePath( sourceHtmlFilePath ); const absoluteJSFilePath = getRelativeFilePath( sourceJSFilePath ); - log.info( `Processing '${ chalk.cyan( sourceFilePathBase ) }'...` ); + if ( !silent ) { + log.info( `Processing '${ chalk.cyan( sourceFilePathBase ) }'...` ); + } // Compile test instruction (Markdown file). const parsedMarkdownTree = reader.parse( fs.readFileSync( sourceMDFilePath, 'utf-8' ) ); @@ -118,7 +145,9 @@ function compileHtmlFile( buildDir, sourceFilePathBase, viewTemplate, languagesT fs.outputFileSync( outputFilePath, preparedHtml ); - log.info( `Finished writing '${ chalk.cyan( outputFilePath ) }'` ); + if ( !silent ) { + log.info( `Finished writing '${ chalk.cyan( outputFilePath ) }'` ); + } } // Copies all non JS/HTML/MD files to build dir. Their relative paths to JS/HTML files are maintained. diff --git a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/removedir.js b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/removedir.js index 18e5d0b98..f8d1ce7c9 100644 --- a/packages/ckeditor5-dev-tests/lib/utils/manual-tests/removedir.js +++ b/packages/ckeditor5-dev-tests/lib/utils/manual-tests/removedir.js @@ -10,14 +10,21 @@ const { logger } = require( '@ckeditor/ckeditor5-dev-utils' ); const chalk = require( 'chalk' ); /** - * Removes directory - * dir package protects you against deleting the current working directory and above. + * Removes the specified directory. + * + * The `del` package protects you against deleting the current working directory and above. * * @param {String} dir Directory to remove. + * @param {Object} [options={}] options + * @param {Boolean} [options.silent=false] Whether to hide the path to the directory on the console. * @returns {Promise} */ -module.exports = function removeDir( dir ) { +module.exports = function removeDir( dir, options = {} ) { return del( dir ).then( () => { - logger().info( `Removed directory '${ chalk.cyan( dir ) }'` ); + if ( !options.silent ) { + logger().info( `Removed directory '${ chalk.cyan( dir ) }'` ); + } + + return Promise.resolve(); } ); }; diff --git a/packages/ckeditor5-dev-tests/tests/tasks/runmanualtests.js b/packages/ckeditor5-dev-tests/tests/tasks/runmanualtests.js index 2194d1d22..69133e317 100644 --- a/packages/ckeditor5-dev-tests/tests/tasks/runmanualtests.js +++ b/packages/ckeditor5-dev-tests/tests/tasks/runmanualtests.js @@ -72,7 +72,8 @@ describe( 'runManualTests', () => { 'workspace/packages/ckeditor-*/tests/**/manual/**/*.js' ], language: undefined, - additionalLanguages: undefined + additionalLanguages: undefined, + silent: false } ); expect( spies.scriptCompiler.calledOnce ).to.equal( true ); @@ -136,7 +137,8 @@ describe( 'runManualTests', () => { 'workspace/packages/ckeditor-editor-classic/tests/manual/**/*.js' ], language: undefined, - additionalLanguages: undefined + additionalLanguages: undefined, + silent: false } ); expect( spies.scriptCompiler.calledOnce ).to.equal( true ); @@ -206,7 +208,8 @@ describe( 'runManualTests', () => { 'workspace/packages/ckeditor-editor-classic/tests/manual/**/*.js' ], language: 'pl', - additionalLanguages: [ 'ar', 'en' ] + additionalLanguages: [ 'ar', 'en' ], + silent: false } ); expect( spies.scriptCompiler.calledOnce ).to.equal( true ); @@ -335,4 +338,51 @@ describe( 'runManualTests', () => { } ); } ); } ); + + it( 'should allow hiding processed files in the console', () => { + spies.transformFileOptionToTestGlob.returns( [ + 'workspace/packages/ckeditor5-*/tests/**/manual/**/*.js', + 'workspace/packages/ckeditor-*/tests/**/manual/**/*.js' + ] ); + + return runManualTests( { silent: true } ) + .then( () => { + expect( spies.removeDir.calledOnce ).to.equal( true ); + expect( spies.removeDir.firstCall.args[ 0 ] ).to.equal( 'workspace/build/.manual-tests' ); + expect( spies.removeDir.firstCall.args[ 1 ] ).to.deep.equal( { silent: true } ); + + expect( spies.transformFileOptionToTestGlob.calledOnce ).to.equal( true ); + expect( spies.transformFileOptionToTestGlob.firstCall.args[ 0 ] ).to.equal( '*' ); + expect( spies.transformFileOptionToTestGlob.firstCall.args[ 1 ] ).to.equal( true ); + + expect( spies.htmlFileCompiler.calledOnce ).to.equal( true ); + expect( spies.htmlFileCompiler.firstCall.args[ 0 ] ).to.deep.equal( { + buildDir: 'workspace/build/.manual-tests', + patterns: [ + 'workspace/packages/ckeditor5-*/tests/**/manual/**/*.js', + 'workspace/packages/ckeditor-*/tests/**/manual/**/*.js' + ], + language: undefined, + additionalLanguages: undefined, + silent: true + } ); + + expect( spies.scriptCompiler.calledOnce ).to.equal( true ); + expect( spies.scriptCompiler.firstCall.args[ 0 ] ).to.deep.equal( { + buildDir: 'workspace/build/.manual-tests', + patterns: [ + 'workspace/packages/ckeditor5-*/tests/**/manual/**/*.js', + 'workspace/packages/ckeditor-*/tests/**/manual/**/*.js' + ], + themePath: null, + language: undefined, + additionalLanguages: undefined, + debug: undefined, + identityFile: null + } ); + + expect( spies.server.calledOnce ).to.equal( true ); + expect( spies.server.firstCall.args[ 0 ] ).to.equal( 'workspace/build/.manual-tests' ); + } ); + } ); } ); diff --git a/packages/ckeditor5-dev-tests/tests/utils/manual-tests/compilehtmlfiles.js b/packages/ckeditor5-dev-tests/tests/utils/manual-tests/compilehtmlfiles.js index 94dd60714..22209399b 100644 --- a/packages/ckeditor5-dev-tests/tests/utils/manual-tests/compilehtmlfiles.js +++ b/packages/ckeditor5-dev-tests/tests/utils/manual-tests/compilehtmlfiles.js @@ -160,6 +160,10 @@ describe( 'compileHtmlFiles', () => { expect( stubs.fs.copySync ).to.be.calledWithExactly( 'static-file.png', path.join( 'buildDir', 'static-file.png' ) ); + + expect( stubs.logger.info.callCount ).to.equal( 2 ); + expect( stubs.logger.info.firstCall.args[ 0 ] ).to.match( /^Processing/ ); + expect( stubs.logger.info.secondCall.args[ 0 ] ).to.match( /^Finished writing/ ); } ); it( 'should compile files with options#language specified', () => { @@ -417,4 +421,29 @@ describe( 'compileHtmlFiles', () => { separator = '/'; } ); + + it( 'should compile the manual test and do not inform about the processed file', () => { + files = { + [ path.join( fakeDirname, 'template.html' ) ]: '
template html content
', + [ path.join( 'path', 'to', 'manual', 'file.md' ) ]: '## Markdown header', + [ path.join( 'path', 'to', 'manual', 'file.html' ) ]: '
html file content
' + }; + + patternFiles = { + [ path.join( 'manualTestPattern', '*.js' ) ]: [ path.join( 'path', 'to', 'manual', 'file.js' ) ], + [ path.join( 'path', 'to', 'manual', '**', '*.!(js|html|md)' ) ]: [ 'static-file.png' ] + }; + + compileHtmlFiles( { + buildDir: 'buildDir', + language: 'en', + patterns: [ path.join( 'manualTestPattern', '*.js' ) ], + silent: true + } ); + + expect( stubs.commonmark.parse ).to.be.calledWithExactly( '## Markdown header' ); + expect( stubs.fs.ensureDirSync ).to.be.calledWithExactly( 'buildDir' ); + + expect( stubs.logger.info.callCount ).to.equal( 0 ); + } ); } ); diff --git a/packages/ckeditor5-dev-tests/tests/utils/manual-tests/removedir.js b/packages/ckeditor5-dev-tests/tests/utils/manual-tests/removedir.js index 19caba8a2..bc580aa8c 100644 --- a/packages/ckeditor5-dev-tests/tests/utils/manual-tests/removedir.js +++ b/packages/ckeditor5-dev-tests/tests/utils/manual-tests/removedir.js @@ -64,4 +64,14 @@ describe( 'removeDir', () => { ] ); } ); } ); + + it( 'should remove directory and does not inform about it', () => { + return removeDir( 'workspace/directory', { silent: true } ).then( () => { + expect( logMessages ).to.deep.equal( [] ); + + expect( deletedPaths ).to.deep.equal( [ + 'workspace/directory' + ] ); + } ); + } ); } );