@@ -12,6 +12,7 @@ var yargs = require('../util/yargs'),
1212 streams = require ( '../config/streams' ) ,
1313 platform = require ( '../config/platform' ) ;
1414
15+ //TODO @bguiz get this from config
1516var defaultReporterName = 'karma-angularity-reporter' ;
1617
1718var basePathRegex = / [ ' " ] ? \s * \/ \* + \s * A N G U L A R I T Y _ B A S E _ P A T H \s * \* + \/ \s * [ ' " ] ? / ;
@@ -37,14 +38,21 @@ function getKarmaReporterPluginPath(reporterName) {
3738 throw 'Reporter name is unspecified' ;
3839 }
3940
40- //Default reporter is a dependency of angularity
41- var reporterPath = ( reporterName === defaultReporterName ) ?
42- path . resolve ( __dirname , '../../node_modules' , defaultReporterName ) :
43- reporterName ;
41+ var reporterPath ;
42+
43+ // Default reporter is a dependency of angularity
44+ if ( reporterName === defaultReporterName ) {
45+ reporterPath = path . resolve ( __dirname , '../../node_modules' , defaultReporterName ) ;
46+ }
47+ else {
48+ reporterPath = reporterName ;
49+ }
50+
4451 //Specific reporters are expected to be dependencies of the local project
45- reporterPath = ( path . dirname ( reporterPath ) === '.' ) ?
46- path . resolve ( 'node_modules' , 'karma-' + reporterName + '-reporter' ) :
47- reporterPath ;
52+ if ( path . dirname ( reporterPath ) === '.' ) { //not an absolute path
53+ reporterPath = path . resolve ( 'node_modules' , 'karma-' +
54+ getKarmaReporterName ( reporterName ) + '-reporter' ) ;
55+ }
4856
4957 //Either way, the absolute path of the reporter is `require`d
5058 //Only to determine if it is indeed `require`able,
@@ -55,8 +63,8 @@ function getKarmaReporterPluginPath(reporterName) {
5563 catch ( ex ) {
5664 throw 'Attempt to require reporter from path ' + reporterPath + ' with no success.' ;
5765 }
58- reporterPath = path . normalize ( reporterPath ) ;
5966
67+ reporterPath = path . normalize ( reporterPath ) ;
6068 if ( platform . isWindows ( ) ) {
6169 //Sanitise path for Windows
6270 //Replace any single backslash characters in file paths with
@@ -74,7 +82,7 @@ function getKarmaReporterPluginPath(reporterName) {
7482 */
7583function getKarmaReporterName ( reporterName ) {
7684 if ( typeof reporterName !== 'string' ) {
77- throw 'Get Karma Reporter Name: Reporter name is unspecified' ;
85+ throw 'Reporter name is unspecified' ;
7886 }
7987
8088 var name = ( path . dirname ( reporterName ) === '.' ) ?
@@ -172,54 +180,27 @@ function karmaRun() {
172180 var appPath = path . join ( __dirname , 'karma-background.js' ) ;
173181 var data = querystring . escape ( JSON . stringify ( options ) ) ;
174182
175- childProcess . spawn ( 'node' , [ appPath , data ] , {
176- cwd : process . cwd ( ) ,
177- stdio : 'inherit' ,
178- env : lodashMerge ( process . env , {
179- //NOTE this workaround is necessary, see issue:
180- //https://github.com/sindresorhus/supports-color/issues/13
181- //TODO @bguiz remove workaround when issue has been resolved
182- SUPPORTS_COLOR : true
183+ childProcess
184+ . spawn ( 'node' , [ appPath , data ] , {
185+ cwd : process . cwd ( ) ,
186+ stdio : 'inherit' ,
187+ env : lodashMerge ( process . env , {
188+ //NOTE this workaround is necessary, see issue:
189+ //https://github.com/sindresorhus/supports-color/issues/13
190+ //TODO @bguiz remove workaround when issue has been resolved
191+ SUPPORTS_COLOR : true
192+ } )
183193 } )
184- } )
185194 . on ( 'close' , function ( ) {
186195 done ( ) ;
187196 } ) ;
188197 }
189198 return through . obj ( transformFn , flushFn ) ;
190199}
191200
192- var yargsOptionDefinition = {
193- key : 'karma-reporter' ,
194- value : {
195- describe : 'Specify a custom Karma reporter to use. Either a locally npm installed module, or an asolute path to ' +
196- 'one.' ,
197- alias : [ 'k' ] ,
198- default : defaultReporterName ,
199- string : true
200- }
201- } ;
202- var checkKarmaReporter = yargs . createCheck ( )
203- . withGate ( function ( argv ) {
204- return ! argv . help ;
205- } )
206- . withTest ( {
207- 'karma-reporter' : function ( value ) {
208- if ( typeof value !== 'undefined' ) {
209- try {
210- getKarmaReporterPluginPath ( value ) ;
211- }
212- catch ( ex ) {
213- return 'Illegal value for "karma-reporter": ' + ex ;
214- }
215- }
216- }
217- } )
218- . commit ( ) ;
219-
220201module . exports = {
221- createConfig : karmaCreateConfig ,
222- run : karmaRun ,
223- yargsCheck : checkKarmaReporter ,
224- yargsOption : yargsOptionDefinition
202+ createConfig : karmaCreateConfig ,
203+ run : karmaRun ,
204+ defaultReporterName : defaultReporterName ,
205+ getPluginPath : getKarmaReporterPluginPath
225206} ;
0 commit comments