Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 0b93003

Browse files
committed
feat(jasmine2): add 'grep' option to jasmine2
Allow users to filter the specs that they want to run using simple string match. To use this feature, either: 1) specify jasmineNodeOpts.grep in your conf.js file or 2) via commandline like "protractor conf.js --grep='pattern to match'"
1 parent 4e34424 commit 0b93003

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

docs/referenceConf.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,13 @@ exports.config = {
265265
showColors: true,
266266
// Default time to wait in ms before a test fails.
267267
defaultTimeoutInterval: 30000,
268-
// Function called to print jasmine results
268+
// Function called to print jasmine results.
269269
print: function() {},
270+
// If set, only execute specs whose names match the pattern, which is
271+
// internally compiled to a RegExp.
272+
grep: 'pattern',
273+
// Inverts 'grep' matches
274+
invertGrep: false
270275
},
271276

272277
// Options to be passed to Mocha.

lib/cli.js

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var optimist = require('optimist').
5959
alias('build', 'capabilities.build').
6060
alias('verbose', 'jasmineNodeOpts.isVerbose').
6161
alias('stackTrace', 'jasmineNodeOpts.includeStackTrace').
62+
alias('grep', 'jasmineNodeOpts.grep').
63+
alias('invert-grep', 'jasmineNodeOpts.invertGrep').
6264
string('capabilities.tunnel-identifier').
6365
check(function(arg) {
6466
if (arg._.length > 1) {

lib/frameworks/jasmine2.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ exports.run = function(runner, specs) {
5454

5555
require('jasminewd2');
5656

57+
var jasmineNodeOpts = runner.getConfig().jasmineNodeOpts;
58+
5759
// On timeout, the flow should be reset. This will prevent webdriver tasks
5860
// from overflowing into the next test and causing it to fail or timeout
5961
// as well. This is done in the reporter instead of an afterEach block
@@ -62,10 +64,20 @@ exports.run = function(runner, specs) {
6264
var reporter = new RunnerReporter(runner);
6365
jasmine.getEnv().addReporter(reporter);
6466

67+
// Filter specs to run based on jasmineNodeOpts.grep and jasmineNodeOpts.invert.
68+
jasmine.getEnv().specFilter = function(spec) {
69+
var grepMatch = !jasmineNodeOpts ||
70+
!jasmineNodeOpts.grep ||
71+
spec.getFullName().match(new RegExp(jasmineNodeOpts.grep)) != null;
72+
var invertGrep = !!(jasmineNodeOpts && jasmineNodeOpts.invertGrep);
73+
if (grepMatch == invertGrep) {
74+
spec.pend();
75+
}
76+
return true;
77+
}
78+
6579
return runner.runTestPreparer().then(function() {
6680
return q.promise(function (resolve, reject) {
67-
var jasmineNodeOpts = runner.getConfig().jasmineNodeOpts;
68-
6981
if (jasmineNodeOpts && jasmineNodeOpts.defaultTimeoutInterval) {
7082
jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineNodeOpts.defaultTimeoutInterval;
7183
}

0 commit comments

Comments
 (0)