Skip to content

Commit

Permalink
Merge pull request #736 from ckeditor/ck/10982
Browse files Browse the repository at this point in the history
Feature (tests): Added an option for disabling watchers in the manual test server. See: ckeditor/ckeditor5#10982.
  • Loading branch information
pomek authored Dec 10, 2021
2 parents cdf2660 + 2876281 commit ff7a411
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 36 deletions.
5 changes: 5 additions & 0 deletions packages/ckeditor5-dev-tests/bin/test-manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const tests = require( '../lib/index' );
const cwd = process.cwd();
const options = tests.parseArguments( process.argv.slice( 2 ) );

// By default, the watch mechanism should be enabled in manual tests.
// However, it makes sense to disable it when a developer wants to compile these files once,
// without rebuilding it. See: https://github.com/ckeditor/ckeditor5/issues/10982.
options.disableWatch = process.argv.includes( '--disable-watch' );

if ( options.files.length === 0 ) {
options.files = [ '*', 'ckeditor5' ];
}
Expand Down
2 changes: 0 additions & 2 deletions packages/ckeditor5-dev-tests/lib/tasks/runautomatedtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see LICENSE.md.
*/

/* jshint node: true, strict: true */

'use strict';

const fs = require( 'fs' );
Expand Down
11 changes: 7 additions & 4 deletions packages/ckeditor5-dev-tests/lib/tasks/runmanualtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see LICENSE.md.
*/

/* jshint node: true, strict: true */

'use strict';

const path = require( 'path' );
Expand All @@ -21,6 +19,8 @@ const transformFileOptionToTestGlob = require( '../utils/transformfileoptiontote
* @param {Object} options
* @param {Array.<String>} options.files Glob patterns specifying which tests to run.
* @param {String} options.themePath A path to the theme the PostCSS theme-importer plugin is supposed to load.
* @param {Boolean} [options.disableWatch=false] Whether to disable the watch mechanism. If set to true, changes in source files
* will not trigger webpack.
* @param {String} [options.language] A language passed to `CKEditorWebpackPlugin`.
* @param {Array.<String>} [options.additionalLanguages] Additional languages passed to `CKEditorWebpackPlugin`.
* @param {Number} [options.port] A port number used by the `createManualTestServer`.
Expand All @@ -42,6 +42,7 @@ module.exports = function runManualTests( options ) {
const additionalLanguages = options.additionalLanguages;
const identityFile = normalizeIdentityFile( options.identityFile );
const silent = options.silent || false;
const disableWatch = options.disableWatch || false;

return Promise.resolve()
.then( () => removeDir( buildDir, { silent } ) )
Expand All @@ -53,14 +54,16 @@ module.exports = function runManualTests( options ) {
language,
additionalLanguages,
debug: options.debug,
identityFile
identityFile,
disableWatch
} ),
compileManualTestHtmlFiles( {
buildDir,
patterns,
language,
additionalLanguages,
silent
silent,
disableWatch
} ),
copyAssets( buildDir )
] ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* For licensing, see LICENSE.md.
*/

/* jshint browser: false, node: true, strict: true */
'use strict';

const path = require( 'path' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const writer = new commonmark.HtmlRenderer();
* @param {String} options.buildDir A path where compiled files will be saved.
* @param {Array.<String>} options.patterns An array of patterns that resolve manual test scripts.
* @param {String} options.language A language passed to `CKEditorWebpackPlugin`.
* @param {Boolean} options.disableWatch Whether to disable the watch mechanism. If set to true, changes in source files
* will not trigger webpack.
* @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}
Expand Down Expand Up @@ -73,14 +75,16 @@ module.exports = function compileHtmlFiles( options ) {
} ) );

// Watch files and compile on change.
watchFiles( [ ...sourceMDFiles, ...sourceHtmlFiles ], file => {
compileHtmlFile( buildDir, {
filePath: getFilePathWithoutExtension( file ),
template: viewTemplate,
languages: languagesToLoad,
silent
if ( !options.disableWatch ) {
watchFiles( [ ...sourceMDFiles, ...sourceHtmlFiles ], file => {
compileHtmlFile( buildDir, {
filePath: getFilePathWithoutExtension( file ),
template: viewTemplate,
languages: languagesToLoad,
silent
} );
} );
} );
}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see LICENSE.md.
*/

/* jshint node: true, strict: true */

'use strict';

const path = require( 'path' );
Expand All @@ -19,6 +17,8 @@ const getRelativeFilePath = require( '../getrelativefilepath' );
* @param {Array.<String>} options.patterns An array of patterns that resolve manual test scripts.
* @param {String} options.themePath A path to the theme the PostCSS theme-importer plugin is supposed to load.
* @param {String} options.language A language passed to `CKEditorWebpackPlugin`.
* @param {Boolean} options.disableWatch Whether to disable the watch mechanism. If set to true, changes in source files
* will not trigger webpack.
* @param {Array.<String>} [options.additionalLanguages] Additional languages passed to `CKEditorWebpackPlugin`.
* @param {String} [options.identityFile] A file that provides secret keys used in the test scripts.
* @returns {Promise}
Expand All @@ -43,7 +43,8 @@ module.exports = function compileManualTestScripts( options ) {
language: options.language,
additionalLanguages: options.additionalLanguages,
debug: options.debug,
identityFile: options.identityFile
identityFile: options.identityFile,
disableWatch: options.disableWatch
} );

return runWebpack( webpackConfig );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see LICENSE.md.
*/

/* jshint node: true, strict: true */

const path = require( 'path' );
const fs = require( 'fs-extra' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const webpack = require( 'webpack' );
* @param {Object} options.entries
* @param {String} options.buildDir
* @param {String} options.themePath
* @param {Boolean} options.disableWatch
* @param {String} [options.language]
* @param {Array.<String>} [options.additionalLanguages]
* @param {String|null} [options.identityFile]
Expand All @@ -24,15 +25,8 @@ const webpack = require( 'webpack' );
module.exports = function getWebpackConfigForManualTests( options ) {
const definitions = Object.assign( {}, getDefinitionsFromFile( options.identityFile ) );

return {
mode: 'development',

// Use cheap source maps because Safari had problem with ES6 + inline source maps.
// We could use cheap source maps every where but karma-webpack doesn't support it:
// https://github.com/webpack/karma-webpack/pull/76
devtool: 'cheap-source-map',

watch: true,
const webpackConfig = {
mode: 'none',

entry: options.entries,

Expand Down Expand Up @@ -107,6 +101,16 @@ module.exports = function getWebpackConfigForManualTests( options ) {
]
}
};

if ( !options.disableWatch ) {
// Use cheap source maps because Safari had problem with ES6 + inline source maps.
// We could use cheap source maps every where but karma-webpack doesn't support it:
// https://github.com/webpack/karma-webpack/pull/76
webpackConfig.devtool = 'cheap-source-map';
webpackConfig.watch = true;
}

return webpackConfig;
};

/**
Expand Down
55 changes: 55 additions & 0 deletions packages/ckeditor5-dev-tests/tests/tasks/runmanualtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe( 'runManualTests', () => {
],
language: undefined,
additionalLanguages: undefined,
disableWatch: false,
silent: false
} );

Expand All @@ -87,6 +88,7 @@ describe( 'runManualTests', () => {
language: undefined,
additionalLanguages: undefined,
debug: undefined,
disableWatch: false,
identityFile: null
} );

Expand Down Expand Up @@ -138,6 +140,7 @@ describe( 'runManualTests', () => {
],
language: undefined,
additionalLanguages: undefined,
disableWatch: false,
silent: false
} );

Expand All @@ -154,6 +157,7 @@ describe( 'runManualTests', () => {
language: undefined,
additionalLanguages: undefined,
debug: [ 'CK_DEBUG' ],
disableWatch: false,
identityFile: null
} );

Expand Down Expand Up @@ -209,6 +213,7 @@ describe( 'runManualTests', () => {
],
language: 'pl',
additionalLanguages: [ 'ar', 'en' ],
disableWatch: false,
silent: false
} );

Expand All @@ -225,6 +230,7 @@ describe( 'runManualTests', () => {
language: 'pl',
additionalLanguages: [ 'ar', 'en' ],
debug: [ 'CK_DEBUG' ],
disableWatch: false,
identityFile: null
} );

Expand Down Expand Up @@ -294,6 +300,7 @@ describe( 'runManualTests', () => {
language: undefined,
debug: undefined,
additionalLanguages: undefined,
disableWatch: false,
identityFile: '/absolute/path/to/secrets.js'
} );
} );
Expand Down Expand Up @@ -334,6 +341,7 @@ describe( 'runManualTests', () => {
language: undefined,
debug: undefined,
additionalLanguages: undefined,
disableWatch: false,
identityFile: 'workspace/path/to/secrets.js'
} );
} );
Expand Down Expand Up @@ -364,6 +372,7 @@ describe( 'runManualTests', () => {
],
language: undefined,
additionalLanguages: undefined,
disableWatch: false,
silent: true
} );

Expand All @@ -378,6 +387,52 @@ describe( 'runManualTests', () => {
language: undefined,
additionalLanguages: undefined,
debug: undefined,
disableWatch: false,
identityFile: null
} );

expect( spies.server.calledOnce ).to.equal( true );
expect( spies.server.firstCall.args[ 0 ] ).to.equal( 'workspace/build/.manual-tests' );
} );
} );

it( 'should allow disabling listening for changes in source files', () => {
spies.transformFileOptionToTestGlob.returns( [
'workspace/packages/ckeditor5-*/tests/**/manual/**/*.js',
'workspace/packages/ckeditor-*/tests/**/manual/**/*.js'
] );

return runManualTests( { disableWatch: true } )
.then( () => {
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,
disableWatch: true,
silent: false
} );

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,
disableWatch: true,
identityFile: null
} );

Expand Down
Loading

0 comments on commit ff7a411

Please sign in to comment.