Skip to content

Commit

Permalink
Bumped Karma to v6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
psmyrek committed Mar 17, 2022
1 parent d4976bf commit 7f7001e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/ckeditor5-package-tools/lib/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const path = require( 'path' );
const chalk = require( 'chalk' );
const { Server: KarmaServer } = require( 'karma' );
const karma = require( 'karma' );

const generateEntryFile = require( '../utils/generate-entry-file' );
const getKarmaConfig = require( '../utils/get-karma-config' );
Expand All @@ -23,9 +23,13 @@ module.exports = options => {

function runKarma( options ) {
return new Promise( ( resolve, reject ) => {
const KarmaServer = karma.Server;
const parseConfig = karma.config.parseConfig;

const config = getKarmaConfig( options );
const parsedConfig = parseConfig( null, config, { throwErrors: true } );

const server = new KarmaServer( config, exitCode => {
const server = new KarmaServer( parsedConfig, exitCode => {
if ( exitCode === 0 ) {
resolve();
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-package-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"chai": "^4.3.4",
"css-loader": "^5.2.7",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^5.2.3",
"karma": "^6.3.17",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.3",
Expand Down
31 changes: 30 additions & 1 deletion packages/ckeditor5-package-tools/tests/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ describe( 'lib/tasks/test', () => {
}
},
karmaServerOn: sinon.stub(),
karmaServerStart: sinon.stub()
karmaServerStart: sinon.stub(),
config: {
parseConfig: sinon.stub()
}
},
fs: {
writeFileSync: sinon.stub(),
Expand Down Expand Up @@ -101,6 +104,7 @@ describe( 'lib/tasks/test', () => {
};

stubs.getKarmaConfig.returns( karmaConfig );
stubs.karma.config.parseConfig.returns( karmaConfig );

setTimeout( () => {
// Call the karma callback when finished executing tests.
Expand Down Expand Up @@ -146,6 +150,31 @@ describe( 'lib/tasks/test', () => {
);
} );

it( 'should reject a promise when karma config parser throws an error', done => {
const options = {
cwd: '/cwd'
};

const karmaConfig = {
basePath: '/cwd'
};

stubs.getKarmaConfig.returns( karmaConfig );
stubs.karma.config.parseConfig.throws( new Error( 'Example error from Karma config parser.' ) );

testTask( options )
.then(
() => {
throw new Error( 'Expected to be rejected.' );
},
err => {
expect( err.message ).to.equal( 'Example error from Karma config parser.' );

done();
}
);
} );

it( 'should display a path to the "coverage/" directory if the coverage option is set to true', done => {
const options = {
cwd: '/cwd',
Expand Down

0 comments on commit 7f7001e

Please sign in to comment.