From 4d1b4cb828cfa0c2bcd3e76447a51b3c1e53e369 Mon Sep 17 00:00:00 2001 From: yshepilov Date: Sun, 12 Apr 2020 18:08:50 +0200 Subject: [PATCH] added possibility to override browsers via cli arguments --- index.js | 11 ++++++++--- karma.conf.js | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 0ba7d2d..3f75c59 100644 --- a/index.js +++ b/index.js @@ -27,11 +27,15 @@ module.exports = ( api, projectOptions ) => { api.registerCommand( 'test:unit', { description: 'Run unit tests with karma', usage: 'vue-cli-service test:unit [options] [...files]', + options: { + '--watch, -w': 'run in watch mode', + '--browsers, -b': ' A list of browsers to launch and capture' + } }, ( args ) => { const webpackConfig = api.resolveWebpackConfig(); - process.env.VUE_CLI_BABEL_TARGET_NODE = true - process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true + process.env.VUE_CLI_BABEL_TARGET_NODE = true; + process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true; return new Promise( ( resolve, reject ) => { let KarmaServer = require( 'karma' ).Server; @@ -41,7 +45,8 @@ module.exports = ( api, projectOptions ) => { generateKarmaConfig( { webpackConfig, karmaOptions, - watch: args.watch || args.w + watch: args.watch || args.w, + browsers: args.browsers || args.b } ), ( exitCode ) => { console.log( `Karma exited with exitCode ${exitCode}` ); diff --git a/karma.conf.js b/karma.conf.js index b09b344..146ea58 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,7 +1,7 @@ -const karmaConstants = require('karma').constants; -const merge = require('webpack-merge'); +const karmaConstants = require( 'karma' ).constants; +const merge = require( 'webpack-merge' ); -module.exports = ( { webpackConfig, karmaOptions, watch } ) => { +module.exports = ( { webpackConfig, karmaOptions, watch, browsers } ) => { delete webpackConfig.entry; webpackConfig = merge( webpackConfig, { devtool: 'inline-source-map' @@ -13,6 +13,14 @@ module.exports = ( { webpackConfig, karmaOptions, watch } ) => { preprocessors[ fileNameOrPattern ] = [ 'webpack' ]; } ); + if ( browsers ) { + if ( (typeof browsers === 'string') || (browsers instanceof String) ) { + browsers = browsers.split( ',' ); + } + } else { + browsers = karmaOptions.browsers; + } + let karmaConfig = { files: karmaOptions.files, @@ -24,7 +32,7 @@ module.exports = ( { webpackConfig, karmaOptions, watch } ) => { singleRun: !watch, - browsers: karmaOptions.browsers, + browsers: browsers, frameworks: karmaOptions.frameworks,