nightwatch
Advanced tools
Comparing version 0.6.11 to 0.6.12
@@ -142,2 +142,6 @@ /** | ||
// $ nightwatch --skiptags | ||
this.command('skiptags') | ||
.description('Skips tests that have the specified tag or tags (comma separated).'); | ||
// $ nightwatch -h | ||
@@ -144,0 +148,0 @@ // $ nightwatch --help |
@@ -405,2 +405,6 @@ var fs = require('fs'); | ||
if (typeof this.argv.skiptags == 'string') { | ||
this.test_settings.skiptags = this.argv.skiptags.split(','); | ||
} | ||
return this; | ||
@@ -407,0 +411,0 @@ }, |
@@ -30,6 +30,6 @@ var path = require('path'); | ||
* @param {string} testFilePath - file path of a test | ||
* @param {Array} tags - tags to match | ||
* @param {object} opts - test options | ||
* @returns {boolean} true if specified test matches given tag | ||
*/ | ||
match : function (testFilePath, tags) { | ||
match : function (testFilePath, opts) { | ||
var test; | ||
@@ -44,3 +44,3 @@ | ||
return this.checkModuleTags(test, tags); | ||
return this.checkModuleTags(test, opts); | ||
}, | ||
@@ -50,8 +50,13 @@ | ||
* @param {object} test - test module | ||
* @param {Array} tags - tags to match | ||
* @param {object} opts - test options | ||
* @returns {boolean} | ||
*/ | ||
checkModuleTags: function (test, tags) { | ||
var testTags = test['@tags'] || test.tags; | ||
checkModuleTags: function (test, opts) { | ||
var moduleTags = test['@tags'] || test.tags; | ||
if (!Array.isArray(moduleTags)) { | ||
return typeof opts.tag_filter == 'undefined' && typeof opts.skiptags != 'undefined'; | ||
} | ||
var tags = opts.tag_filter || opts.skiptags; | ||
if (!Array.isArray(tags)) { | ||
@@ -61,17 +66,30 @@ tags = [tags]; | ||
if (!Array.isArray(testTags)) { | ||
return false; | ||
tags = this.convertTagsToString(tags); | ||
moduleTags = this.convertTagsToString(moduleTags); | ||
if (opts.tag_filter) { | ||
return this.containsTag(moduleTags, tags); | ||
} else if (opts.skiptags) { | ||
return this.excludesTag(moduleTags, tags); | ||
} | ||
tags = tags.map(function (tag) { | ||
return true; | ||
}, | ||
convertTagsToString : function(tags) { | ||
return tags.map(function (tag) { | ||
return String(tag).toLowerCase(); | ||
}); | ||
}, | ||
return testTags | ||
.map(function (testTag) { | ||
return String(testTag).toLowerCase(); | ||
}) | ||
.some(function (testTag) { | ||
return (tags.indexOf(testTag) !== -1); | ||
}); | ||
containsTag : function(moduleTags, tags) { | ||
return moduleTags.some(function (testTag) { | ||
return (tags.indexOf(testTag) > -1); | ||
}); | ||
}, | ||
excludesTag : function(moduleTags, tags) { | ||
return moduleTags.every(function (testTag) { | ||
return (tags.indexOf(testTag) == -1); | ||
}); | ||
} | ||
@@ -78,0 +96,0 @@ }, |
@@ -31,3 +31,3 @@ var Walk = require('./walk.js'); | ||
finishCallback({ | ||
message: 'An error occurred while running the tests:\n' + err.stack | ||
message: 'An error occurred while running the tests:\n' + (err && err.stack || err) | ||
}); | ||
@@ -34,0 +34,0 @@ }); |
@@ -118,4 +118,4 @@ var path = require('path'); | ||
if (opts.tag_filter) { | ||
return fileMatcher.tags.match(filePath, opts.tag_filter); | ||
if (opts.tag_filter || opts.skiptags) { | ||
return fileMatcher.tags.match(filePath, opts); | ||
} | ||
@@ -122,0 +122,0 @@ |
{ | ||
"name": "nightwatch", | ||
"description": "A node.js bindings implementation for selenium 2.0/webdriver", | ||
"version": "0.6.11", | ||
"version": "0.6.12", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Andrei Rusu", |
@@ -201,3 +201,5 @@ | ||
env : 'default', | ||
output : 'output' | ||
output : 'output', | ||
skiptags : 'home,arctic', | ||
tag : 'danger' | ||
}).init(); | ||
@@ -211,3 +213,5 @@ | ||
page_objects_path: '', | ||
output: true | ||
output: true, | ||
tag_filter: 'danger', | ||
skiptags: [ 'home', 'arctic' ] | ||
}}); | ||
@@ -214,0 +218,0 @@ |
@@ -12,3 +12,5 @@ | ||
var matched = matcher.tags.checkModuleTags(testModule, tags); | ||
var matched = matcher.tags.checkModuleTags(testModule, { | ||
tag_filter : tags | ||
}); | ||
@@ -25,3 +27,5 @@ test.ok(matched === true); | ||
var matched = matcher.tags.checkModuleTags(testModule, tags); | ||
var matched = matcher.tags.checkModuleTags(testModule, { | ||
tag_filter : tags | ||
}); | ||
@@ -36,3 +40,5 @@ test.ok(matched === false); | ||
var matched = matcher.tags.checkModuleTags(testModule, tags); | ||
var matched = matcher.tags.checkModuleTags(testModule, { | ||
tag_filter : tags | ||
}); | ||
@@ -46,3 +52,5 @@ test.ok(matched === false); | ||
var matched = matcher.tags.match(__dirname + '/../../sampletests/tags/sample.js', tags); | ||
var matched = matcher.tags.match(__dirname + '/../../sampletests/tags/sample.js', { | ||
tag_filter : tags | ||
}); | ||
@@ -59,3 +67,5 @@ test.ok(matched === true); | ||
var matched = matcher.tags.checkModuleTags(testModule, tags); | ||
var matched = matcher.tags.checkModuleTags(testModule, { | ||
tag_filter : tags | ||
}); | ||
test.ok(matched === true); | ||
@@ -71,6 +81,57 @@ test.done(); | ||
var matched = matcher.tags.checkModuleTags(testModule, tags); | ||
var matched = matcher.tags.checkModuleTags(testModule, { | ||
tag_filter : tags | ||
}); | ||
test.ok(matched === true); | ||
test.done(); | ||
}, | ||
'skiptag test not matching' : function(test) { | ||
var matched = matcher.tags.checkModuleTags({ | ||
tags: ['room', 101] | ||
}, { | ||
skiptags : ['101'] | ||
}); | ||
test.ok(matched === false); | ||
test.done(); | ||
}, | ||
'skiptag test matching' : function(test) { | ||
var matched = matcher.tags.checkModuleTags({ | ||
tags: ['room', 101] | ||
}, { | ||
skiptags : ['other'] | ||
}); | ||
test.ok(matched === true); | ||
test.done(); | ||
}, | ||
'skiptag test matching - undefined local tags' : function(test) { | ||
var matched = matcher.tags.checkModuleTags({}, { | ||
skiptags : ['other'] | ||
}); | ||
test.ok(matched === true); | ||
test.done(); | ||
}, | ||
'skiptag test loading module with matching tags' : function(test) { | ||
var matched = matcher.tags.match(__dirname + '/../../sampletests/tags/sample.js', { | ||
skiptags : ['login'] | ||
}); | ||
test.ok(matched === false); | ||
test.done(); | ||
}, | ||
'skiptag test loading module with no tags' : function(test) { | ||
var matched = matcher.tags.match(__dirname + '/../../sampletests/simple/sample.js', { | ||
skiptags : ['login'] | ||
}); | ||
test.ok(matched === true); | ||
test.done(); | ||
} | ||
}; |
445972
13051