Skip to content

Commit

Permalink
Added support for multiple custom command and assertion folders - nig…
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Sep 7, 2014
1 parent 137027e commit ee8443e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
35 changes: 27 additions & 8 deletions lib/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,25 @@ module.exports = new (function() {

/**
* Loads custom commands defined by the user
* @param {string} [dirpath]
* @param {string} [dirPath]
* @param {object} [parent]
*/
function loadCustomCommands(dirpath, parent) {
if (!custom_commands_path && !dirpath) {
function loadCustomCommands(dirPath, parent) {
if (!custom_commands_path && !dirPath) {
return;
}

dirpath = dirpath || custom_commands_path;
dirPath = dirPath || custom_commands_path;
parent = parent || client.api;

var absPath = path.join(process.cwd(), dirpath);
if (Array.isArray(dirPath)) {
dirPath.forEach(function(folder) {
loadCustomCommands(folder, parent);
});
return;
}

var absPath = path.join(process.cwd(), dirPath);
var commandFiles = fs.readdirSync(absPath);

commandFiles.forEach(function(file) {
Expand All @@ -263,16 +270,28 @@ module.exports = new (function() {

/**
* Loads custom assertions, similarly to custom commands
* @param [folder]
*/
function loadCustomAssertions() {
function loadCustomAssertions(folder) {
folder = folder || custom_assertions_path;
if (!custom_assertions_path) {
return;
}

var absPath = path.join(process.cwd(), custom_assertions_path);
if (Array.isArray(folder)) {
folder.forEach(function(folderName) {
loadCustomAssertions(folderName);
});
return;
}

loadCustomAssertionFolder(folder);
}

function loadCustomAssertionFolder(folderName) {
var absPath = path.join(process.cwd(), folderName);
loadAssertionFiles(absPath, client.api.assert, true);
loadAssertionFiles(absPath, client.api.verify, false);

}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/src/testNightwatchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
browserName: 'firefox',
version: 'TEST',
platform: 'TEST'
});
});
test.done();
});
var command = function() {
Expand All @@ -44,7 +44,7 @@ module.exports = {
test.done();
});

client.options.custom_commands_path = './extra/commands';
client.options.custom_commands_path = ['./extra/commands'];
Api.init(client);
Api.loadCustomCommands();

Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = {
test.done();
});

client.options.custom_assertions_path = './extra/assertions';
client.options.custom_assertions_path = ['./extra/assertions'];
Api.init(client);
Api.loadCustomAssertions();

Expand Down

0 comments on commit ee8443e

Please sign in to comment.