Skip to content

Commit

Permalink
Merge pull request #729 from ckeditor/ck/10668
Browse files Browse the repository at this point in the history
Other (tests): Upgraded the testing environment to webpack 5. See ckeditor/ckeditor5#10668.

Other (tests): Dropped support for resolving packages starting with the `ckeditor-` prefix.

MINOR BREAKING CHANGE (tests): Packages starting with the `ckeditor-` prefix are not supported anymore.
  • Loading branch information
pomek authored Dec 8, 2021
2 parents c155a2b + d56ab34 commit f5c4bef
Show file tree
Hide file tree
Showing 12 changed files with 954 additions and 1,397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function getKarmaConfig( options ) {
basePath,

// Frameworks to use. Available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [ 'mocha', 'sinon-chai' ],
frameworks: [ 'mocha', 'sinon-chai', 'webpack' ],

// For unknown reasons, sometimes Karma does not fill the list automatically. So, all available plugins must be specified manually.
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const path = require( 'path' );
const escapedPathSep = path.sep == '/' ? '/' : '\\\\';
const webpack = require( 'webpack' );
const { getPostCssConfig } = require( '@ckeditor/ckeditor5-dev-utils' ).styles;

/**
Expand All @@ -17,6 +18,12 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
const config = {
mode: 'development',

plugins: [
new webpack.ProvidePlugin( {
process: 'process/browser'
} )
],

module: {
rules: [
{
Expand All @@ -37,14 +44,17 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
}
}
},
'css-loader',
{
loader: 'postcss-loader',
options: getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
minify: true
} )
options: {
postcssOptions: getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
minify: true
} )
}
}
]
},
Expand All @@ -55,7 +65,7 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
{
test: /\.js$/,
loader: require.resolve( '../ck-debug-loader' ),
query: {
options: {
debugFlags: options.debug
}
}
Expand All @@ -71,12 +81,9 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
};

if ( options.sourceMap ) {
// Note: karma-sourcemap-loader works only with inline source maps.
// See https://github.com/webpack/karma-webpack/pull/76.
// We use cheap source maps for manual tests because Safari
// had problems with inline source maps and ES6. This means that
// you can't have source maps in automated tests in Safari.
config.devtool = 'inline-source-map';
// Available list: https://webpack.js.org/configuration/devtool/.
// In Safari, none of them seems to work.
config.devtool = 'cheap-source-map';
}

if ( options.coverage ) {
Expand All @@ -88,7 +95,7 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
exclude: [
new RegExp( `${ escapedPathSep }(lib)${ escapedPathSep }` )
],
query: {
options: {
esModules: true
}
}
Expand All @@ -111,7 +118,6 @@ function getPathsToIncludeForCoverage( globs ) {
}, [] )
.map( glob => {
const matchCKEditor5 = glob.match( /\/(ckeditor5-[^/]+)\// );
const matchCKEditor = glob.match( /\/(ckeditor-[^/]+)\// );

if ( matchCKEditor5 ) {
const packageName = matchCKEditor5[ 1 ]
Expand All @@ -120,12 +126,6 @@ function getPathsToIncludeForCoverage( globs ) {
.replace( /ckeditor5-!\(([^)]+)\)\*/, 'ckeditor5-(?!$1)[^' + escapedPathSep + ']+' )
.replace( 'ckeditor5-*', 'ckeditor5-[a-z]+' );

return new RegExp( packageName + escapedPathSep + 'src' + escapedPathSep );
} else if ( matchCKEditor ) {
const packageName = matchCKEditor[ 1 ]
.replace( /ckeditor-!\(([^)]+)\)\*/, 'ckeditor-(?!$1)[^' + escapedPathSep + ']+' )
.replace( 'ckeditor-*', 'ckeditor-[a-z]+' );

return new RegExp( packageName + escapedPathSep + 'src' + escapedPathSep );
}
} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = function parseArguments( args ) {

function addPackagesToCollection( collection, directoryPath ) {
for ( const directory of tools.getDirectories( directoryPath ) ) {
collection.add( directory.replace( /^ckeditor5?-/, '' ) );
collection.add( directory.replace( /^ckeditor5-/, '' ) );
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/ckeditor5-dev-tests/lib/utils/ck-debug-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
*/
module.exports = function ckDebugLoader( source, map ) {
source = source.replace( /\/\/ @if (!?[\w]+) \/\/(.+)/g, ( match, flagName, body ) => {
// `this.query` comes from the webpack loader configuration.
// `this.query` comes from the webpack loader configuration specified as the loader options.
// {
// loader: 'path-to-the-file',
// options: { // <-- `this.query`
// debugFlags: true
// }
// }

// Do not uncomment the code if the flag is missing / falsy.
if ( !this.query.debugFlags.includes( flagName ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ module.exports = function getWebpackConfigForManualTests( options ) {
}
}
},
'css-loader',
{
loader: 'postcss-loader',
options: getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
sourceMap: true
} )
options: {
postcssOptions: getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
sourceMap: true
} )
}
}
]
},
Expand All @@ -87,7 +90,7 @@ module.exports = function getWebpackConfigForManualTests( options ) {
{
test: /\.js$/,
loader: require.resolve( '../ck-debug-loader' ),
query: {
options: {
debugFlags: options.debug
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ module.exports = class WebpackNotifierPlugin {
* @param {*} compiler
*/
apply( compiler ) {
compiler.plugin( 'compile', () => {
compiler.hooks.compile.tap( this.constructor.name, () => {
this.log.info( '[Webpack] Starting scripts compilation...' );
} );

compiler.plugin( 'done', stats => {
compiler.hooks.done.tap( this.constructor.name, stats => {
if ( stats.compilation.errors.length ) {
for ( const item of stats.compilation.errors ) {
this.log.error( item.message );
Expand Down
18 changes: 10 additions & 8 deletions packages/ckeditor5-dev-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [],
"main": "lib/index.js",
"dependencies": {
"@babel/core": "^7.9.6",
"@babel/core": "^7.15.8",
"@ckeditor/ckeditor5-dev-utils": "^26.1.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^26.1.0",
"@ckeditor/ckeditor5-inspector": "^2.2.2",
Expand All @@ -17,7 +17,8 @@
"chalk": "^4.0.0",
"chokidar": "^3.4.0",
"commonmark": "^0.29.1",
"cssnano": "^4.1.10",
"cssnano": "^5.0.8",
"css-loader": "^5.2.7",
"del": "^5.1.0",
"depcheck": "^1.3.1",
"dom-combiner": "^0.1.3",
Expand All @@ -28,27 +29,28 @@
"karma": "^5.0.9",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.2",
"karma-coverage": "^2.0.3",
"karma-firefox-launcher": "^1.3.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-sinon": "^1.0.5",
"karma-sinon-chai": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
"karma-sourcemap-loader": "^0.3.8",
"karma-webpack": "^5.0.0",
"lodash": "^4.17.15",
"minimatch": "^3.0.4",
"minimist": "^1.2.5",
"mkdirp": "^1.0.4",
"mocha": "^7.1.2",
"node-fetch": "^2.6.1",
"postcss-loader": "^3.0.0",
"postcss-loader": "^4.3.0",
"process": "^0.11.10",
"raw-loader": "^4.0.1",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"slack-notify": "^0.1.7",
"style-loader": "^1.2.1",
"webpack": "^4.43.0"
"style-loader": "^2.0.0",
"webpack": "^5.58.1"
},
"devDependencies": {
"mockery": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
exclude: [
new RegExp( `${ escapedPathSep }(lib)${ escapedPathSep }` )
],
query: {
options: {
esModules: true
}
} );
Expand All @@ -70,8 +70,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
coverage: true,
files: [
[
'node_modules/ckeditor5-utils/tests/**/*.js',
'node_modules/ckeditor-utils/tests/**/*.js'
'node_modules/ckeditor5-utils/tests/**/*.js'
]
]
} );
Expand All @@ -80,8 +79,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
.find( rule => rule.loader === 'istanbul-instrumenter-loader' );

expect( istanbulLoader.include ).to.deep.equal( [
new RegExp( [ 'ckeditor5-utils', 'src', '' ].join( escapedPathSep ) ),
new RegExp( [ 'ckeditor-utils', 'src', '' ].join( escapedPathSep ) )
new RegExp( [ 'ckeditor5-utils', 'src', '' ].join( escapedPathSep ) )
] );
} );

Expand All @@ -90,8 +88,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
coverage: true,
files: [
[
'node_modules/ckeditor5-!(utils)/tests/**/*.js',
'node_modules/ckeditor-!(utils)/tests/**/*.js'
'node_modules/ckeditor5-!(utils)/tests/**/*.js'
]
]
} );
Expand All @@ -100,8 +97,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
.find( rule => rule.loader === 'istanbul-instrumenter-loader' );

expect( istanbulLoader.include ).to.deep.equal( [
new RegExp( [ 'ckeditor5-!(utils)', 'src', '' ].join( escapedPathSep ) ),
new RegExp( [ 'ckeditor-!(utils)', 'src', '' ].join( escapedPathSep ) )
new RegExp( [ 'ckeditor5-!(utils)', 'src', '' ].join( escapedPathSep ) )
] );
} );

Expand All @@ -110,7 +106,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
sourceMap: true
} );

expect( webpackConfig.devtool ).to.equal( 'inline-source-map' );
expect( webpackConfig.devtool ).to.equal( 'cheap-source-map' );
} );

it( 'should contain a correct paths in resolveLoader', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,27 +295,5 @@ describe( 'parseArguments()', () => {
expect( options.files ).to.deep.equal( [ 'core', 'engine', 'foo-1', 'foo-2', 'bar-1', 'bar-2' ] );
}
);

it(
'returns an array of packages to tests when `--repositories` is specified ' +
'(removes "ckeditor-" prefix)',
() => {
stubs.cwd.returns( '/home/project' );

stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( false );
stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' );
stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [
'ckeditor-core',
'ckeditor-engine'
] );

const options = parseArguments( [
'--repositories',
'ckeditor5'
] );

expect( options.files ).to.deep.equal( [ 'core', 'engine' ] );
}
);
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ module.exports = function getDllPluginWebpackConfig( options ) {
}
}
},
'css-loader',
{
loader: 'postcss-loader',
options: styles.getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
minify: true
} )
options: {
postcssOptions: styles.getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
minify: true
} )
}
}
]
}
Expand Down
9 changes: 6 additions & 3 deletions packages/ckeditor5-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"fs-extra": "^8.1.0",
"javascript-stringify": "^1.6.0",
"pofile": "^1.0.9",
"postcss": "^7.0.36",
"postcss": "^7.0.39",
"postcss-import": "^12.0.0",
"postcss-loader": "^3.0.0",
"postcss-mixins": "^6.2.0",
"postcss-nesting": "^7.0.0",
"raw-loader": "^4.0.1",
"shelljs": "^0.8.1",
"style-loader": "^1.2.1",
"terser-webpack-plugin": "^3.0.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^4.2.3",
"through2": "^3.0.1"
},
"devDependencies": {
Expand All @@ -34,6 +34,9 @@
"sinon": "^7.3.2",
"vinyl": "^2.1.0"
},
"peerDependencies": {
"webpack": "^4.43.0 || ^5.24.0"
},
"engines": {
"node": ">=12.0.0",
"npm": ">=5.7.1"
Expand Down
Loading

0 comments on commit f5c4bef

Please sign in to comment.