Skip to content

Commit

Permalink
Added the "--silent" flag to the manual test server.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Mar 12, 2021
1 parent c567710 commit 71efb2b
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 16 deletions.
7 changes: 5 additions & 2 deletions packages/ckeditor5-dev-tests/lib/tasks/runmanualtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const transformFileOptionToTestGlob = require( '../utils/transformfileoptiontote
* @param {Array.<String>} [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 ) {
Expand All @@ -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,
Expand All @@ -57,7 +59,8 @@ module.exports = function runManualTests( options ) {
buildDir,
patterns,
language,
additionalLanguages
additionalLanguages,
silent
} ),
copyAssets( buildDir )
] ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module.exports = function parseArguments( args ) {
'server',
'source-map',
'verbose',
'watch'
'watch',
'silent'
],

alias: {
Expand Down Expand Up @@ -64,7 +65,8 @@ module.exports = function parseArguments( args ) {
'identity-file': null,
repositories: [],
'theme-path': null,
'additional-languages': null
'additional-languages': null,
silent: false
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ const writer = new commonmark.HtmlRenderer();
* @param {Array.<String>} options.patterns An array of patterns that resolve manual test scripts.
* @param {String} options.language A language passed to `CKEditorWebpackPlugin`.
* @param {Array.<String>} [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 [
Expand Down Expand Up @@ -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.<String>} 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';
Expand All @@ -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' ) );
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 11 additions & 4 deletions packages/ckeditor5-dev-tests/lib/utils/manual-tests/removedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
};
56 changes: 53 additions & 3 deletions packages/ckeditor5-dev-tests/tests/tasks/runmanualtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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' );
} );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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' ) ]: '<div>template html content</div>',
[ path.join( 'path', 'to', 'manual', 'file.md' ) ]: '## Markdown header',
[ path.join( 'path', 'to', 'manual', 'file.html' ) ]: '<div>html file content</div>'
};

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 );
} );
} );
10 changes: 10 additions & 0 deletions packages/ckeditor5-dev-tests/tests/utils/manual-tests/removedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
] );
} );
} );
} );

0 comments on commit 71efb2b

Please sign in to comment.