forked from nightwatchjs/nightwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue nightwatchjs#186: test case tagging
You can now tag a test case by adding the `tags` property to a test module. ``` module.exports = { tags: ['login', 'sanity'], 'demo login test': function (client) { // test code } }; ``` Select tags to run by specifying the `--tag` flag (`-a` for short): ``` bin/nightwatch --tag login --tag something_else ```
- Loading branch information
Showing
9 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module.exports = { | ||
/** | ||
* @param {string} testFilePath - file path of a test | ||
* @param {array} tags - tags to match | ||
* @returns {boolean} true if specified test matches given tag | ||
*/ | ||
tags: function (testFilePath, tags) { | ||
|
||
try { | ||
test = require(testFilePath); | ||
} catch (e) { | ||
// could not load test module | ||
return false; | ||
} | ||
|
||
return this.checkModuleTags(test, tags); | ||
}, | ||
|
||
/** | ||
* @param {object} test - test module | ||
* @param {array} tags - tags to match | ||
* @returns {boolean} | ||
*/ | ||
checkModuleTags: function (test, tags) { | ||
var testTags = test.tags; | ||
var match = false; | ||
|
||
if (typeof tags === 'string') { | ||
tags = [tags]; | ||
} | ||
|
||
if (!Array.isArray(testTags)) { | ||
return false; | ||
} | ||
|
||
tags = tags.map(function (tag) { | ||
return tag.toLowerCase(); | ||
}); | ||
|
||
testTags | ||
.map(function (testTag) { | ||
return testTag.toLowerCase(); | ||
}) | ||
.some(function (testTag) { | ||
match = (tags.indexOf(testTag) !== -1); | ||
return match; | ||
}); | ||
|
||
return match; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
tags: ['login'], | ||
demoTagTest: function (client) { | ||
client.url('http://localhost') | ||
.assert.elementPresent('#weblogin') | ||
.end(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var BASE_PATH = process.env.NIGHTWATCH_COV | ||
? 'lib-cov' | ||
: 'lib'; | ||
var matcher = require('../../../'+ BASE_PATH +'/runner/matcher.js'); | ||
|
||
module.exports = { | ||
'tag: test matching tags': function (test) { | ||
var tags = ['home', 'login', 'sign-up']; | ||
var testModule = { | ||
tags: ['home', 'siberia'] | ||
}; | ||
|
||
var matched = matcher.checkModuleTags(testModule, tags); | ||
|
||
test.ok(matched === true); | ||
test.done(); | ||
}, | ||
|
||
'tag: test non-matching tags': function (test) { | ||
var tags = ['home', 'login', 'sign-up']; | ||
var testModule = { | ||
tags: ['boroboro', 'siberia'] | ||
}; | ||
|
||
var matched = matcher.checkModuleTags(testModule, tags); | ||
|
||
test.ok(matched === false); | ||
test.done(); | ||
}, | ||
|
||
'tag: test undefined tags': function (test) { | ||
var tags = ['home', 'login', 'sign-up']; | ||
var testModule = {}; | ||
|
||
var matched = matcher.checkModuleTags(testModule, tags); | ||
|
||
test.ok(matched === false); | ||
test.done(); | ||
}, | ||
|
||
'tag: test loading module with tags': function (test) { | ||
var tags = ['home', 'login', 'sign-up']; | ||
var testModule = require('../../sampletests/tags/sample'); | ||
|
||
var matched = matcher.checkModuleTags(testModule, tags); | ||
|
||
test.ok(matched === true); | ||
test.done(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters