From 48b81aa323faf0904897dfeb875a3f9b6ff505ad Mon Sep 17 00:00:00 2001 From: Nathan Black Date: Tue, 13 Jan 2015 17:36:42 -0800 Subject: [PATCH] Implement the grep option, -g, and -i for inverting it. Fixes #145 --- bin/mocha-phantomjs | 4 ++++ lib/mocha-phantomjs.coffee | 9 +++++++-- test/mocha-phantomjs.coffee | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/bin/mocha-phantomjs b/bin/mocha-phantomjs index 11b543b..a549996 100755 --- a/bin/mocha-phantomjs +++ b/bin/mocha-phantomjs @@ -63,6 +63,8 @@ program .option('-R, --reporter ', 'specify the reporter to use', 'spec') .option('-f, --file ', 'specify the file to dump reporter output') .option('-t, --timeout ', 'specify the test startup timeout to use', parseInt, 6000) + .option('-g, --grep ', 'only run tests matching ') + .option('-i, --invert', 'invert --grep matches') .option('-b, --bail', 'exit on the first test failure') .option('-A, --agent ', 'specify the user agent to use') .option('-c, --cookies ', 'phantomjs cookie object http://git.io/RmPxgA', cookiesParser) // http://git.io/RmPxgA @@ -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 }); diff --git a/lib/mocha-phantomjs.coffee b/lib/mocha-phantomjs.coffee index cf9a311..ed90db2 100644 --- a/lib/mocha-phantomjs.coffee +++ b/lib/mocha-phantomjs.coffee @@ -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 diff --git a/test/mocha-phantomjs.coffee b/test/mocha-phantomjs.coffee index 627c011..033a198 100644 --- a/test/mocha-phantomjs.coffee +++ b/test/mocha-phantomjs.coffee @@ -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) ->