Skip to content

Commit

Permalink
Implement the grep option, -g, and -i for inverting it. Fixes #145
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanboktae committed Jan 14, 2015
1 parent 3444349 commit 48b81aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bin/mocha-phantomjs
Expand Up @@ -63,6 +63,8 @@ program
.option('-R, --reporter <name>', 'specify the reporter to use', 'spec')
.option('-f, --file <filename>', 'specify the file to dump reporter output')
.option('-t, --timeout <timeout>', 'specify the test startup timeout to use', parseInt, 6000)
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
.option('-i, --invert', 'invert --grep matches')
.option('-b, --bail', 'exit on the first test failure')
.option('-A, --agent <userAgent>', 'specify the user agent to use')
.option('-c, --cookies <Object>', 'phantomjs cookie object http://git.io/RmPxgA', cookiesParser) // http://git.io/RmPxgA
Expand Down Expand Up @@ -109,6 +111,8 @@ var config = JSON.stringify({
useColors: program.color,
bail: program.bail,
file: program.file,
grep: program.grep,
invert: program.invert,
ignoreResourceErrors: program.ignoreResourceErrors
});

Expand Down
9 changes: 7 additions & 2 deletions lib/mocha-phantomjs.coffee
Expand Up @@ -93,8 +93,13 @@ class Reporter
false

runMocha: ->
if @config.useColors is false then @page.evaluate -> mocha.useColors false
if @config.bail then @page.evaluate -> mocha.bail true
@page.evaluate (config) ->
mocha.useColors config.useColors
mocha.bail config.bail
mocha.grep config.grep if config.grep
mocha.invert() if config.invert
, @config

@config.hooks.beforeStart?(this)

unless @page.evaluate(@setupReporter, @reporter) is true
Expand Down
12 changes: 12 additions & 0 deletions test/mocha-phantomjs.coffee
Expand Up @@ -353,6 +353,18 @@ describe 'mocha-phantomjs', ->
@runner done, ['-v', '123x456', fileURL('viewport')], (code, stdout, stderr) ->
expect(stdout).to.match /123x456/

describe 'grep', ->

it 'filters tests to match the criteria', (done) ->
@runner done, ['-g', 'pass', fileURL('mixed')], (code, stdout, stderr) ->
expect(code).to.equal 0
expect(stdout).to.not.match /fail/

it 'can be inverted to filter out tests matching the criteria', (done) ->
@runner done, ['-g', 'pass', '-i', fileURL('mixed')], (code, stdout, stderr) ->
expect(code).to.equal 6
expect(stdout).to.not.match /passes/

describe 'no-colors', ->

it 'suppresses color output', (done) ->
Expand Down

0 comments on commit 48b81aa

Please sign in to comment.