Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added possibility to override browsers via cli arguments #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}` );

Expand Down
16 changes: 12 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,

Expand All @@ -24,7 +32,7 @@ module.exports = ( { webpackConfig, karmaOptions, watch } ) => {

singleRun: !watch,

browsers: karmaOptions.browsers,
browsers: browsers,

frameworks: karmaOptions.frameworks,

Expand Down