Skip to content

Commit f5188e9

Browse files
committed
=BG= add CLI option to specify karma reporter, either by name or with an absolute path
1 parent 250151f commit f5188e9

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

lib/test/karma.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var gulp = require('gulp'),
77
querystring = require('querystring'),
88
childProcess = require('child_process');
99

10+
var yargs = require('../util/yargs');
11+
1012
/**
1113
* Wrap the given value in quotation marks
1214
* @param {*} value The value to wrap
@@ -17,6 +19,7 @@ function quote(value) {
1719
}
1820

1921
var defaultReporterName = 'angularity-karma-reporter';
22+
2023
var filesAppendRegex = /\/\*+\s*ANGULARITY_FILE_LIST\s*\*+\// ;
2124
var reportersAppendRegex = /\/\*+\s*ANGULARITY_REPORTER_LIST\s*\*+\// ;
2225
var pluginsAppendRegex = /\/\*+\s*ANGULARITY_PLUGIN_LIST\s*\*+\// ;
@@ -200,7 +203,38 @@ function karmaRun(reporters, bannerWidth) {
200203
});
201204
};
202205

206+
var yargsOptionDefiniton = {
207+
key: 'karmareporter',
208+
value: {
209+
describe: 'Specify a custom Karma reporter to use. '+
210+
'Either a locally npm installed module, or an asolute path to one.',
211+
alias: ['k'],
212+
default: defaultReporterName,
213+
string:true,
214+
}
215+
};
216+
var checkKarmaReporter = yargs.createCheck()
217+
.withGate(function (argv) {
218+
return !argv.help;
219+
})
220+
.withTest({
221+
'karmareporter': function(value) {
222+
if (typeof value === 'undefined') {
223+
return;
224+
}
225+
try {
226+
getKarmaReporterPluginPath(value);
227+
}
228+
catch (ex) {
229+
return 'Illegal value for "reporter"\n'+ex;
230+
}
231+
},
232+
})
233+
.commit();
234+
203235
module.exports = {
204236
createConfig: karmaCreateConfig,
205-
run: karmaRun
237+
run: karmaRun,
238+
yargsCheck: checkKarmaReporter,
239+
yargsOption: yargsOptionDefiniton,
206240
};

lib/util/jshint-reporter.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ var gulpJshint = require('gulp-jshint');
77
var yargs = require('./yargs');
88

99
var defaultReporterName = 'angularity-jshint-reporter';
10-
var yargsOptionDefiniton = {
11-
key: 'reporter',
12-
value: {
13-
describe: 'Specify a custom JsHint reporter to use. '+
14-
'Either a locally npm installed module, or an asolute path to one.',
15-
alias: ['r'],
16-
default: defaultReporterName,
17-
string:true,
18-
}
19-
};
2010

2111
/**
2212
* Dynamically load a JsHint reporter
@@ -64,12 +54,22 @@ function getJsHintReporter(reporterName) {
6454
return jsHintReporter;
6555
}
6656

57+
var yargsOptionDefiniton = {
58+
key: 'reporter',
59+
value: {
60+
describe: 'Specify a custom JsHint reporter to use. '+
61+
'Either a locally npm installed module, or an asolute path to one.',
62+
alias: ['r'],
63+
default: defaultReporterName,
64+
string: true,
65+
}
66+
};
6767
var checkJsHintReporter = yargs.createCheck()
6868
.withGate(function (argv) {
6969
return !argv.help;
7070
})
7171
.withTest({
72-
reporter: function(value) {
72+
'reporter': function(value) {
7373
if (typeof value === 'undefined') {
7474
return;
7575
}

tasks/javascript.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ yargs.getInstance('test')
6464
boolean : true
6565
})
6666
.options(jshintReporter.yargsOption.key, jshintReporter.yargsOption.value)
67+
.options(karma.yargsOption.key, karma.yargsOption.value)
6768
.strict()
6869
.check(yargs.subCommandCheck)
6970
.check(jshintReporter.yargsCheck)
71+
.check(karma.yargsCheck)
7072
.wrap(80);
7173

7274
gulp.task('javascript', function (done) {
@@ -113,7 +115,17 @@ gulp.task('javascript:lint', function () {
113115

114116
// karma unit tests in local library only
115117
gulp.task('javascript:unit', function () {
116-
var reporters = [];
118+
var reporters = cliArgs.karmareporter;
119+
if (reporters.constructor === Array) {
120+
reporters = Array;
121+
}
122+
else if (typeof reporters === 'string' &&
123+
reporters !== karma.yargsOption.value.default) {
124+
reporters = [reporters];
125+
}
126+
else {
127+
reporters = [];
128+
}
117129
return combined.create()
118130
.append(
119131
streams

0 commit comments

Comments
 (0)