diff --git a/README.md b/README.md index e048010..a1cd1c6 100644 --- a/README.md +++ b/README.md @@ -507,11 +507,19 @@ Configurations: Command | Testing TypeScript --- | --- -default | Run through PhantomJS one time with no file watching -headless (aliases: hl, h)| Run through PhantomJS with files being watched & tests automatically re-run -watch (alias: w)| Run through Chrome with files being watched & tests automatically re-run - -Note that Chrome still requires a manual refresh on the Debug tab to see updated test results. +default | Run through defined browsers one time with no file watching +headless (aliases: hl, h)| Run through PhantomJS +watch (alias: w)| Run through defined browsers with files being watched & tests automatically re-run +browsers (alias: b)| Overrides the browsers to use for testing. Note: These are applied last and merges +will be lost + +These commands can be combined allowing you to work the way you need to for a variety of situations. For +instance using `ngl test watch headless` will run though PhantomJS with files being watched & tests +automatically re-run. Or if you have defined in your karma config file to run against Chrome, Firefox, IE +and Edge but there is only an issue with IE you want to work on, then you can simply run +`ngl test watch browsers=IE` and only IE will run with files being watched and tests automatically re-run. + +Note that browsers still requires a manual refresh on the Debug tab to see updated test results. ## Custom Configurations diff --git a/commands/initial/templates/tasks/test.js b/commands/initial/templates/tasks/test.js index 74ae43c..ec2c38f 100644 --- a/commands/initial/templates/tasks/test.js +++ b/commands/initial/templates/tasks/test.js @@ -13,45 +13,40 @@ function run(type) { server.start(); } -function getConfig(type) { - switch (type) { - case 'headless': - case 'hl': - case 'h': - return getHeadlessConfig(); - case 'all': - case 'a': - return getAllConfig(); - case 'watch': - case 'w': - return getWatchConfig(); - default: - return getSingleConfig(); - } -} - -function getSingleConfig() { - let config = getHeadlessConfig(); - - config.singleRun = true; +function getConfig(options) { + let config = getAllConfig(options.watch); + const fallbackBrowsers = config.browsers && !config.browsers.length ? config.browsers : ['PhantomJS']; + config.browsers = options.browsers || fallbackBrowsers; + config.singleRun = !options.watch; - return config; + return config; } -function getHeadlessConfig() { - let config = getAllConfig(); - - config.browsers = ['PhantomJS']; - - return config; -} - -function getWatchConfig() { - let config = getAllConfig(true); - - config.browsers = ['Chrome']; - - return config; +function parseOptions(args){ + return args.reduce((previous, arg)=>{ + const value = arg.match(/^(\w+)/)[1]; + let current = Object.assign({}, previous); + switch(value){ //there are probably libraries that parse cmd line arguments... + case 'headless': + case 'hl': + case 'h': + current.browsers = ['PhantomJS']; + break; + case 'watch': + case 'w': + current.watch = true; + break; + case 'browsers': + case 'b': + let browsers = arg.match(/\w+=([\w,]*)/i); + current.browsers = (browsers && !current.browsers) ? browsers[1].split(',') : current.browsers; + break; + //the 'all' option did not modify the browser options and it did not change the watch option. + //therefore removing it will not break current setups. Unless the developer removed all browsers + //from the base karma.config.js file + } + return current; + }, {}); } const getAllConfig = (watch) => ({ @@ -62,5 +57,7 @@ const getAllConfig = (watch) => ({ module.exports = run; if (!module.parent) { - run(process.argv[2]); + //skip the first two args (exe and script) and grab all options that start with a 'word' + let optionArgs = process.argv.filter((value, index) => index > 1 && value.match(/^\w+/)); + run(parseOptions(optionArgs)); }