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.
refactored the runner and matcher to included other matchers
- Loading branch information
1 parent
bef7516
commit 425c686
Showing
6 changed files
with
110 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
var path = require('path'); | ||
var minimatch = require('minimatch'); | ||
|
||
module.exports = { | ||
tags: { | ||
/** | ||
* @param {string} testFilePath - file path of a test | ||
* @param {Array} tags - tags to match | ||
* @returns {boolean} true if specified test matches given tag | ||
*/ | ||
match : function (testFilePath, tags) { | ||
var test; | ||
|
||
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(); | ||
}); | ||
|
||
match = testTags | ||
.map(function (testTag) { | ||
return testTag.toLowerCase(); | ||
}) | ||
.some(function (testTag) { | ||
return (tags.indexOf(testTag) !== -1); | ||
}); | ||
|
||
return match; | ||
} | ||
}, | ||
|
||
exclude : { | ||
adaptFilePath : function(filePath, excludedPath) { | ||
if (!Array.isArray(excludedPath)) { | ||
excludedPath = [excludedPath]; | ||
} | ||
return excludedPath.map(function(item) { | ||
// remove trailing slash | ||
if (item.charAt(item.length-1) === path.sep) { | ||
item = item.substring(0, item.length-1); | ||
} | ||
return path.join(filePath, item); | ||
}); | ||
}, | ||
|
||
match : function(filePath, excludePath) { | ||
for (var i = 0; i < excludePath.length; i++) { | ||
if (minimatch(filePath, excludePath[i])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}, | ||
|
||
filter : { | ||
adaptFilePath : function(filePath, filterPath) { | ||
if (filterPath.charAt(filterPath.length-1) === path.sep) { | ||
filterPath = filterPath.substring(0, filterPath.length-1); | ||
} | ||
return path.join(filePath, filterPath); | ||
}, | ||
|
||
match : function(filePath, filterPath) { | ||
return minimatch(filePath, filterPath); | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -121,5 +121,5 @@ module.exports = { | |
test.ok(Object.keys(results.modules).length === 1); | ||
test.done(); | ||
}); | ||
}, | ||
} | ||
}; |