Skip to content

Commit

Permalink
The ck-debug-loader should not be included in TypeScript files when c…
Browse files Browse the repository at this point in the history
…hecking the coverage.
  • Loading branch information
pomek committed Feb 23, 2023
1 parent ccc3b61 commit c076bbc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 35 deletions.
Expand Up @@ -18,6 +18,13 @@ const getDefinitionsFromFile = require( '../getdefinitionsfromfile' );
module.exports = function getWebpackConfigForAutomatedTests( options ) {
const definitions = Object.assign( {}, getDefinitionsFromFile( options.identityFile ) );

const ckDebugLoader = {
loader: require.resolve( '../ck-debug-loader' ),
options: {
debugFlags: options.debug
}
};

const config = {
mode: 'development',

Expand Down Expand Up @@ -78,10 +85,7 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
},
{
test: /\.js$/,
loader: require.resolve( '../ck-debug-loader' ),
options: {
debugFlags: options.debug
}
...ckDebugLoader
},
{
test: /\.ts$/,
Expand All @@ -102,12 +106,6 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
noEmitOnError: true
}
}
},
{
loader: require.resolve( '../ck-debug-loader' ),
options: {
debugFlags: options.debug
}
}
]
}
Expand Down Expand Up @@ -145,18 +143,30 @@ module.exports = function getWebpackConfigForAutomatedTests( options ) {
config.module.rules.unshift(
{
test: /\.[jt]s$/,
loader: 'babel-loader',
options: {
plugins: [
'babel-plugin-istanbul'
]
},
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'babel-plugin-istanbul'
]
}
},
{
...ckDebugLoader
}
],
include: getPathsToIncludeForCoverage( options.files ),
exclude: [
new RegExp( `${ escapedPathSep }(lib)${ escapedPathSep }` )
]
}
);
} else {
const tsRules = config.module.rules.find( loader => 'typescript.ts'.match( loader.test ) );
tsRules.use.push( {
...ckDebugLoader
} );
}

if ( options.cache ) {
Expand Down
Expand Up @@ -63,22 +63,41 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
files: [ '**/*.js' ]
} );

const coverageLoader = webpackConfig.module.rules
.find( rule => rule.loader === 'babel-loader' );

expect( coverageLoader ).to.deep.equal( {
test: /\.[jt]s$/,
loader: 'babel-loader',
include: [],
exclude: [
new RegExp( `${ escapedPathSep }(lib)${ escapedPathSep }` )
],
options: {
plugins: [
'babel-plugin-istanbul'
]
}
const coverageLoader = webpackConfig.module.rules[ 0 ];

expect( coverageLoader ).to.not.equal( undefined );
expect( '/path/to/javascript.js' ).to.match( coverageLoader.test );
expect( '/path/to/typescript.ts' ).to.match( coverageLoader.test );

expect( coverageLoader.include ).to.be.an( 'array' );
expect( coverageLoader.include ).to.lengthOf( 0 );
expect( coverageLoader.exclude ).to.be.an( 'array' );
expect( coverageLoader.exclude ).to.lengthOf( 1 );

expect( coverageLoader.use ).to.be.an( 'array' );
expect( coverageLoader.use ).to.lengthOf.above( 1 );

const babelLoader = coverageLoader.use[ 0 ];

expect( babelLoader.loader ).to.equal( 'babel-loader' );
} );

it( 'should include the ck-debug-loader when checking the coverage', () => {
const webpackConfig = getWebpackConfigForAutomatedTests( {
coverage: true,
files: [ '**/*.js' ]
} );

const coverageLoader = webpackConfig.module.rules[ 0 ];

expect( coverageLoader ).to.not.equal( undefined );

expect( coverageLoader.use ).to.be.an( 'array' );
expect( coverageLoader.use ).to.lengthOf( 2 );

const ckDebugLoader = coverageLoader.use[ 1 ];

expect( ckDebugLoader.loader ).to.contain( 'ck-debug-loader' );
} );

it( 'should return webpack configuration containing a loader for measuring the coverage (include check)', () => {
Expand All @@ -91,9 +110,11 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
]
} );

const coverageLoader = webpackConfig.module.rules
.find( rule => rule.loader === 'babel-loader' );
const coverageLoader = webpackConfig.module.rules[ 0 ];

expect( coverageLoader ).to.not.equal( undefined );

expect( coverageLoader.include ).to.be.an( 'array' );
expect( coverageLoader.include ).to.deep.equal( [
new RegExp( [ 'ckeditor5-utils', 'src', '' ].join( escapedPathSep ) )
] );
Expand All @@ -109,9 +130,11 @@ describe( 'getWebpackConfigForAutomatedTests()', () => {
]
} );

const coverageLoader = webpackConfig.module.rules
.find( rule => rule.loader === 'babel-loader' );
const coverageLoader = webpackConfig.module.rules[ 0 ];

expect( coverageLoader ).to.not.equal( undefined );

expect( coverageLoader.include ).to.be.an( 'array' );
expect( coverageLoader.include ).to.deep.equal( [
new RegExp( [ 'ckeditor5-!(utils)', 'src', '' ].join( escapedPathSep ) )
] );
Expand Down

0 comments on commit c076bbc

Please sign in to comment.