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

Commit

Permalink
feat(jasmine2): add 'grep' option to jasmine2
Browse files Browse the repository at this point in the history
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'"
  • Loading branch information
hankduan committed Jan 6, 2015
1 parent 4e34424 commit 0b93003
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion docs/referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,13 @@ exports.config = {
showColors: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 30000,
// Function called to print jasmine results
// Function called to print jasmine results.
print: function() {},
// If set, only execute specs whose names match the pattern, which is
// internally compiled to a RegExp.
grep: 'pattern',
// Inverts 'grep' matches
invertGrep: false
},

// Options to be passed to Mocha.
Expand Down
2 changes: 2 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var optimist = require('optimist').
alias('build', 'capabilities.build').
alias('verbose', 'jasmineNodeOpts.isVerbose').
alias('stackTrace', 'jasmineNodeOpts.includeStackTrace').
alias('grep', 'jasmineNodeOpts.grep').
alias('invert-grep', 'jasmineNodeOpts.invertGrep').
string('capabilities.tunnel-identifier').
check(function(arg) {
if (arg._.length > 1) {
Expand Down
16 changes: 14 additions & 2 deletions lib/frameworks/jasmine2.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ exports.run = function(runner, specs) {

require('jasminewd2');

var jasmineNodeOpts = runner.getConfig().jasmineNodeOpts;

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

// Filter specs to run based on jasmineNodeOpts.grep and jasmineNodeOpts.invert.
jasmine.getEnv().specFilter = function(spec) {
var grepMatch = !jasmineNodeOpts ||
!jasmineNodeOpts.grep ||
spec.getFullName().match(new RegExp(jasmineNodeOpts.grep)) != null;
var invertGrep = !!(jasmineNodeOpts && jasmineNodeOpts.invertGrep);
if (grepMatch == invertGrep) {
spec.pend();
}
return true;
}

return runner.runTestPreparer().then(function() {
return q.promise(function (resolve, reject) {
var jasmineNodeOpts = runner.getConfig().jasmineNodeOpts;

if (jasmineNodeOpts && jasmineNodeOpts.defaultTimeoutInterval) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineNodeOpts.defaultTimeoutInterval;
}
Expand Down

0 comments on commit 0b93003

Please sign in to comment.