mirror of
https://github.com/zhigang1992/viff.git
synced 2026-04-29 05:05:30 +08:00
Merge pull request #14 from winsonwq/run_specific_testcases
add filter to run specific testcases
This commit is contained in:
@@ -81,7 +81,7 @@ repo for viff reporter is [ViffReport](https://github.com/xjsi/ViffReport)
|
||||
|
||||
# History
|
||||
|
||||
2013-09-22 **viff@0.4.2** won't stop testing if one of them fail.
|
||||
2013-10-27 **viff@0.4.2** won't stop testing if one of them fail.
|
||||
|
||||
2013-09-22 **viff@0.4.1** could write testcase description.
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
"grunt-contrib-watch": "~0.2.0",
|
||||
"grunt-contrib-coffee": "~0.7.0",
|
||||
"grunt-contrib-nodeunit": "~0.2.0",
|
||||
"sinon": "*"
|
||||
"sinon": "*",
|
||||
"chai": "*"
|
||||
},
|
||||
"keywords": ["testing", "viff", "diff", "web", "e2e"],
|
||||
"bin": {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
_ = require 'underscore'
|
||||
|
||||
Viff = require './viff.js'
|
||||
Reporter = require './reporter.js'
|
||||
processArgs = require './process.argv.js'
|
||||
|
||||
config = processArgs process.argv
|
||||
|
||||
if typeof(config) == 'string'
|
||||
console.log config
|
||||
return
|
||||
return console.log(config) if _.isString config
|
||||
|
||||
viff = new Viff config.seleniumHost
|
||||
viff.takeScreenshots(config.browsers, config.envHosts, config.paths).done (compares)->
|
||||
|
||||
@@ -20,12 +20,12 @@ parseEnvHosts = (value) ->
|
||||
envHosts
|
||||
|
||||
parsePaths = (value) ->
|
||||
_.select value.split(','), (path) -> !_.isEmpty(path.trim())
|
||||
(p.trim() for p in value.split(',') when !_.isEmpty(p.trim()))
|
||||
|
||||
mergeAndValidateConfig = (seleniumHost, browsers, envHosts, paths, reportFormat, config) ->
|
||||
c = config || {}
|
||||
|
||||
for name, idx in ['seleniumHost', 'browsers', 'envHosts', 'paths', 'reportFormat']
|
||||
mergeAndValidateConfig = (seleniumHost, browsers, envHosts, paths, reportFormat, grep, config) ->
|
||||
c = _.extend {}, config
|
||||
|
||||
for name, idx in ['seleniumHost', 'browsers', 'envHosts', 'paths', 'reportFormat', 'grep']
|
||||
c[name] = arguments[idx] || c[name]
|
||||
|
||||
c.browsers = ['firefox'] if c.browsers is undefined or c.browsers.length == 0
|
||||
@@ -37,6 +37,19 @@ mergeAndValidateConfig = (seleniumHost, browsers, envHosts, paths, reportFormat,
|
||||
|
||||
c
|
||||
|
||||
filterByGrep = (paths, grep) ->
|
||||
[ret, ps] = [[], paths || []]
|
||||
reg = new RegExp grep
|
||||
|
||||
ps.forEach (p, idx) ->
|
||||
target = p if _.isString p
|
||||
target = _.first(p) if _.isArray p
|
||||
target = _.first(_.keys(p)) if Object.prototype.toString.call(p) is '[object Object]'
|
||||
|
||||
ret.push(p) if reg.test target
|
||||
|
||||
ret
|
||||
|
||||
checkIfNeedHelp = (args) ->
|
||||
argsCollection = ['-browsers', '-envs', '-paths', '--report-format', '--selenium-host']
|
||||
needHelp = true
|
||||
@@ -48,14 +61,17 @@ checkIfNeedHelp = (args) ->
|
||||
needHelp
|
||||
|
||||
help = ->
|
||||
version = require('../package.json').version
|
||||
"""
|
||||
|
||||
Version: #{version}
|
||||
|
||||
Usage: viff [options] [config file path]
|
||||
|
||||
Options:
|
||||
|
||||
-browsers <borwser1/*, browser2 ...*/> config the browsers using browser name, by default firefox
|
||||
-envs <env1=url1, env2=url2> config two environments, env1 and env2 could be updated
|
||||
-grep <grep> config description or path matched testcases
|
||||
-paths <path1/*, path2 ...*/> config the paths to compare
|
||||
--report-format <format> config the output format in file/json/html, by default file
|
||||
--selenium-host <host> config selenium host, such as "http://localhost:4444/wd/hub"
|
||||
@@ -70,6 +86,7 @@ help = ->
|
||||
-browsers "firefox,chrome"
|
||||
-envs build=http://localhost:4000,prod=http://ishouldbeageek.me
|
||||
-paths "/404.html,/page2"
|
||||
-grep "path1"
|
||||
--report-format file
|
||||
/Users/xx/test.config.js
|
||||
|
||||
@@ -97,10 +114,15 @@ processArgv = (args) ->
|
||||
when '--selenium-host'
|
||||
seleniumHost = args.shift().trim()
|
||||
|
||||
when '-grep'
|
||||
grep = args.shift().trim()
|
||||
|
||||
else
|
||||
if arg.indexOf('.config.js') > 0
|
||||
config = require path.resolve process.cwd(), arg
|
||||
|
||||
mergeAndValidateConfig seleniumHost, browsers, envHosts, paths, reportFormat, config
|
||||
c = mergeAndValidateConfig seleniumHost, browsers, envHosts, paths, reportFormat, grep, config
|
||||
c.paths = filterByGrep(c.paths, grep) if grep
|
||||
c
|
||||
|
||||
module.exports = processArgv
|
||||
@@ -1,7 +1,11 @@
|
||||
correct_config = {
|
||||
seleniumHost: 'http://localhost:4000/wd/hub',
|
||||
browsers: ['safari', 'firefox'],
|
||||
paths: ['/strict-mode'],
|
||||
paths: [
|
||||
'/strict-mode',
|
||||
{ 'test case description': ['/', '#selector'] },
|
||||
['/hello-world', '#selector2']
|
||||
],
|
||||
envHosts: {
|
||||
custom: 'http://localhost:4000',
|
||||
custom2: 'http://localhost:4001'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
_ = require 'underscore'
|
||||
sinon = require 'sinon'
|
||||
should = require('chai').should()
|
||||
path = require 'path'
|
||||
|
||||
processArgv = require '../../lib/process.argv.js'
|
||||
@@ -24,17 +25,20 @@ module.exports =
|
||||
'--report-format',
|
||||
'html',
|
||||
'--selenium-host',
|
||||
'http://localhost:4444/wd/hub'
|
||||
'http://localhost:4444/wd/hub',
|
||||
'-grep',
|
||||
'404'
|
||||
]
|
||||
|
||||
config = processArgv argv
|
||||
|
||||
test.ok _.isEqual _.keys(config), ['seleniumHost', 'browsers', 'envHosts', 'paths', 'reportFormat']
|
||||
test.ok _.isEqual _.keys(config), ['seleniumHost', 'browsers', 'envHosts', 'paths', 'reportFormat', 'grep']
|
||||
test.ok _.isEqual config.browsers, ['firefox', 'chrome']
|
||||
test.ok _.isEqual config.envHosts, { build: 'http://localhost:4000', prod: 'http://ishouldbeageek.me' }
|
||||
test.ok _.isEqual config.paths, ['/404.html']
|
||||
test.ok _.isEqual config.reportFormat, 'html'
|
||||
test.ok _.isEqual config.seleniumHost, 'http://localhost:4444/wd/hub'
|
||||
test.ok _.isEqual config.grep, '404'
|
||||
test.done()
|
||||
|
||||
'it should ignore the blank between ","': (test) ->
|
||||
@@ -167,11 +171,45 @@ module.exports =
|
||||
|
||||
test.ok _.isEqual config.browsers, ['safari', 'firefox']
|
||||
test.ok _.isEqual config.envHosts, { custom: 'http://localhost:4000', custom2: 'http://localhost:4001' }
|
||||
test.ok _.isEqual config.paths, ['/strict-mode']
|
||||
test.ok _.isEqual config.paths, [
|
||||
'/strict-mode',
|
||||
{ 'test case description': ['/', '#selector'] },
|
||||
['/hello-world', '#selector2']
|
||||
]
|
||||
test.ok _.isEqual config.reportFormat, 'json'
|
||||
|
||||
test.done()
|
||||
|
||||
'it should return config for matched cases': (test) ->
|
||||
argv = [
|
||||
'node',
|
||||
'/Users/tw/Projects/viff/lib/index.js',
|
||||
'-paths',
|
||||
'/404.html, /find-path, /hello',
|
||||
'./test/src/correct.config.js',
|
||||
'-grep', '-'
|
||||
]
|
||||
|
||||
config = processArgv argv
|
||||
config.paths.length.should.equal 1
|
||||
config.paths.should.contain '/find-path'
|
||||
test.done()
|
||||
|
||||
'it should return config for matched cases when only using config.js': (test) ->
|
||||
argv = [
|
||||
'node',
|
||||
'/Users/tw/Projects/viff/lib/index.js',
|
||||
'./test/src/correct.config.js',
|
||||
'-grep', '-'
|
||||
]
|
||||
|
||||
config = processArgv argv
|
||||
|
||||
config.paths.length.should.equal 2
|
||||
config.paths[0].should.equal '/strict-mode'
|
||||
config.paths[1][0].should.equal '/hello-world'
|
||||
test.done()
|
||||
|
||||
'it should return help menu when only executing "viff"': (test) ->
|
||||
argv = [
|
||||
'node'
|
||||
|
||||
Reference in New Issue
Block a user