Skip to content

Commit

Permalink
Merge 24276f5 into 67567dc
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Oct 12, 2020
2 parents 67567dc + 24276f5 commit 97bb39f
Show file tree
Hide file tree
Showing 9 changed files with 619 additions and 1,188 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' ],

// Files saved in directory `ckeditor5/packages/ckeditor5-utils/tests/_assets/` are available under: http://0.0.0.0:{port}/assets/
proxies: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
}
}
},
'css-loader',
{
loader: 'postcss-loader',
options: getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
minify: true
} )
options: {
postcssOptions: getPostCssConfig( {
themeImporter: {
themePath: getThemePath( options )
},
minify: true
} )
}
}
]
},
Expand All @@ -55,7 +58,7 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
{
test: /\.js$/,
loader: require.resolve( '../ck-debug-loader' ),
query: {
options: {
debugFlags: options.debug
}
}
Expand Down Expand Up @@ -88,7 +91,7 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
exclude: [
new RegExp( `${ escapedPathSep }(lib)${ escapedPathSep }` )
],
query: {
options: {
esModules: true
}
}
Expand Down Expand Up @@ -132,3 +135,14 @@ function getPathsToIncludeForCoverage( globs ) {
// Filter undefined ones.
.filter( path => path );
}

function getThemePath( options ) {
if ( options.themePath ) {
return options.themePath;
}

const themePackagePath = path.join( process.cwd(), 'node_modules', '@ckeditor/ckeditor5-theme-lark' );
const themePackageJson = require( path.join( themePackagePath, 'package.json' ) );

return path.join( themePackagePath, themePackageJson.main );
}
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 @@ -54,7 +54,7 @@ module.exports = function getWebpackConfigForManualTests( options ) {
module: {
rules: [
{
test: /\.svg$/,
test: /\.(svg|txt|html)$/,
use: [ 'raw-loader' ]
},
{
Expand All @@ -69,25 +69,26 @@ module.exports = function getWebpackConfigForManualTests( options ) {
}
}
},
'css-loader',
{
loader: 'postcss-loader',
options: getPostCssConfig( {
themeImporter: {
themePath: options.themePath
},
sourceMap: true
} )
options: {
postcssOptions: getPostCssConfig( {
themeImporter: {
themePath: require.resolve(
path.join( process.cwd(), 'node_modules', '@ckeditor/ckeditor5-theme-lark' )
)
},
minify: true
} )
}
}
]
},
{
test: /\.(txt|html)$/,
use: [ 'raw-loader' ]
},
{
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 @@ -17,16 +17,16 @@ module.exports = class WebpackNotifierPlugin {

/**
* Applies plugin to the Webpack.
* See: https://webpack.github.io/docs/plugins.html#the-compiler-instance
* See: https://webpack.js.org/contribute/writing-a-plugin/
*
* @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
17 changes: 8 additions & 9 deletions packages/ckeditor5-dev-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
"keywords": [],
"main": "lib/index.js",
"dependencies": {
"@babel/core": "^7.9.6",
"@babel/core": "^7.11.6",
"@ckeditor/ckeditor5-dev-utils": "^23.5.1",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^23.5.1",
"@ckeditor/ckeditor5-inspector": "^2.2.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"chai": "^4.2.0",
"chalk": "^4.0.0",
"chokidar": "^3.4.0",
"commonmark": "^0.29.1",
"cssnano": "^4.1.10",
"css-loader": "4.3.0",
"del": "^5.1.0",
"depcheck": "^0.9.2",
"dom-combiner": "^0.1.3",
Expand All @@ -26,26 +25,26 @@
"karma": "^5.0.9",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.2",
"karma-firefox-launcher": "^1.3.0",
"karma-coverage": "^2.0.3",
"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-alpha.3.0",
"lodash": "^4.17.15",
"minimatch": "^3.0.4",
"minimist": "^1.2.5",
"mkdirp": "^1.0.4",
"mocha": "^7.1.2",
"postcss-loader": "^3.0.0",
"postcss": "^8.1.1",
"postcss-loader": "^4.0.2",
"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"
"webpack": "^5.0.0"
},
"devDependencies": {
"mockery": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict';

const mockery = require( 'mockery' );
const sinon = require( 'sinon' );
const { expect } = require( 'chai' );

describe( 'getWebpackConfigForAutomatedTests()', () => {
Expand All @@ -26,10 +27,25 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
}
} );

mockery.registerMock( '@ckeditor/ckeditor5-dev-utils', {
styles: {
getPostCssConfig: options => {
postCssOptions = options;
}
}
} );

mockery.registerMock( '/tmp/node_modules/@ckeditor/ckeditor5-theme-lark/package.json', {
main: 'theme/theme.css'
} );

sinon.stub( process, 'cwd' ).returns( '/tmp' );

getWebpackConfigForAutomatedTests = require( '../../../lib/utils/automated-tests/getwebpackconfig' );
} );

afterEach( () => {
sinon.restore();
mockery.disable();
mockery.deregisterAll();
} );
Expand Down Expand Up @@ -59,7 +75,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
exclude: [
new RegExp( `${ escapedPathSep }(lib)${ escapedPathSep }` )
],
query: {
options: {
esModules: true
}
} );
Expand Down Expand Up @@ -125,7 +141,7 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
expect( require( 'fs' ).existsSync( secondPath ) ).to.equal( true );
} );

it( 'should return webpack configutation with the correct setup of the postcss-loader', () => {
it( 'should return webpack configuration with the correct setup of the postcss-loader', () => {
getWebpackConfigForAutomatedTests( {
themePath: 'path/to/theme'
} );
Expand All @@ -138,6 +154,17 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
} );
} );

it( 'should return a path to the main file if `options.themePath` is not specified loader', () => {
getWebpackConfigForAutomatedTests( {} );

expect( postCssOptions ).to.deep.equal( {
themeImporter: {
themePath: '/tmp/node_modules/@ckeditor/ckeditor5-theme-lark/theme/theme.css'
},
minify: true
} );
} );

it( 'should load svg files properly', () => {
const webpackConfig = getWebpackConfigForAutomatedTests( {} );
const svgRule = webpackConfig.module.rules.find( rule => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-dev-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"@ckeditor/ckeditor5-dev-utils": "^23.5.1",
"chalk": "^4.0.0",
"rimraf": "^3.0.2",
"webpack-sources": "^1.4.3"
"webpack-sources": "^2.0.1"
},
"devDependencies": {
"chai": "^4.2.0",
"proxyquire": "^2.1.3",
"sinon": "^9.0.2"
},
"peerDependencies": {
"webpack": "^4.43.0"
"webpack": "^5.0.0"
},
"engines": {
"node": ">=12.0.0",
Expand Down

0 comments on commit 97bb39f

Please sign in to comment.