Skip to content

Commit 263082c

Browse files
committed
Merge pull request #3125 from hypothesis/dev-add-test-grep-option
Support filtering test suites to run using '--grep' argument to gulp
2 parents 913cf7e + 129dcc0 commit 263082c

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

docs/hacking/install.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,12 @@ source code. To start the test runner in auto-watch mode, run:
257257
258258
gulp test-watch-app
259259
260-
You can further speed up the testing cycle for front-end code by using
261-
mocha's `.only()`_ to only run a particular suite of tests or even just
262-
a single test.
260+
To run only a subset of tests for front-end code, use the ``--grep``
261+
argument or mocha's `.only()`_ modifier.
262+
263+
.. code-block:: bash
264+
265+
gulp test-watch-app --grep <pattern>
263266
264267
.. _.only(): http://jaketrent.com/post/run-single-mocha-test/
265268

gulpfile.js

+42-19
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ require('core-js/es6/promise');
44
require('core-js/fn/object/assign');
55
require('core-js/fn/string');
66

7+
var path = require('path');
8+
79
var batch = require('gulp-batch');
810
var changed = require('gulp-changed');
11+
var commander = require('commander');
912
var endOfStream = require('end-of-stream');
1013
var gulp = require('gulp');
1114
var gulpIf = require('gulp-if');
1215
var gulpUtil = require('gulp-util');
13-
var sass = require('gulp-sass');
1416
var postcss = require('gulp-postcss');
17+
var sass = require('gulp-sass');
1518
var sourcemaps = require('gulp-sourcemaps');
1619

1720
var manifest = require('./scripts/gulp/manifest');
@@ -24,6 +27,24 @@ var STYLE_DIR = 'build/styles';
2427
var FONTS_DIR = 'build/fonts';
2528
var IMAGES_DIR = 'build/images';
2629

30+
function parseCommandLine() {
31+
commander
32+
// Test configuration.
33+
// See https://github.com/karma-runner/karma-mocha#configuration
34+
.option('--grep [pattern]', 'Run only tests matching a given pattern')
35+
.parse(process.argv);
36+
37+
if (commander.grep) {
38+
gulpUtil.log(`Running tests matching pattern /${commander.grep}/`);
39+
}
40+
41+
return {
42+
grep: commander.grep,
43+
};
44+
}
45+
46+
var taskArgs = parseCommandLine();
47+
2748
function isSASSFile(file) {
2849
return file.path.match(/\.scss$/);
2950
}
@@ -224,34 +245,36 @@ gulp.task('watch',
224245
'watch-images',
225246
'watch-manifest']);
226247

227-
gulp.task('test-app', function (callback) {
248+
function runKarma(baseConfig, opts, done) {
249+
// See https://github.com/karma-runner/karma-mocha#configuration
250+
var cliOpts = {
251+
client: {
252+
mocha: {
253+
grep: taskArgs.grep,
254+
}
255+
},
256+
};
257+
228258
var karma = require('karma');
229-
new karma.Server({
230-
configFile: __dirname + '/h/static/scripts/karma.config.js',
231-
singleRun: true,
232-
}, callback).start();
259+
new karma.Server(Object.assign({}, {
260+
configFile: path.resolve(__dirname, baseConfig),
261+
}, cliOpts, opts), done).start();
262+
}
263+
264+
gulp.task('test-app', function (callback) {
265+
runKarma('./h/static/scripts/karma.config.js', {singleRun:true}, callback);
233266
});
234267

235268
gulp.task('test-extension', function (callback) {
236-
var karma = require('karma');
237-
new karma.Server({
238-
configFile: __dirname + '/h/browser/chrome/karma.config.js',
239-
singleRun: true,
240-
}, callback).start();
269+
runKarma('./h/browser/chrome/karma.config.js', {singleRun:true}, callback);
241270
});
242271

243272
gulp.task('test-watch-app', function (callback) {
244-
var karma = require('karma');
245-
new karma.Server({
246-
configFile: __dirname + '/h/static/scripts/karma.config.js',
247-
}, callback).start();
273+
runKarma('./h/static/scripts/karma.config.js', {}, callback);
248274
});
249275

250276
gulp.task('test-watch-extension', function (callback) {
251-
var karma = require('karma');
252-
new karma.Server({
253-
configFile: __dirname + '/h/browser/chrome/karma.config.js',
254-
}, callback).start();
277+
runKarma('./h/browser/chrome/karma.config.js', {}, callback);
255278
});
256279

257280
gulp.task('upload-sourcemaps',

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"browserify-ngannotate": "^1.0.1",
2121
"browserify-shim": "^3.8.12",
2222
"coffeeify": "^1.0.0",
23+
"commander": "^2.9.0",
2324
"compass-mixins": "^0.12.7",
2425
"core-js": "^1.2.5",
2526
"diff-match-patch": "^1.0.0",

0 commit comments

Comments
 (0)