Skip to content

Commit

Permalink
refactored the cli runner to better accomodate external build runners…
Browse files Browse the repository at this point in the history
… such as grunt
  • Loading branch information
beatfactor committed Oct 24, 2014
1 parent e578137 commit 2ca4605
Show file tree
Hide file tree
Showing 59 changed files with 460 additions and 358 deletions.
70 changes: 0 additions & 70 deletions bin/_cli.js

This file was deleted.

2 changes: 1 addition & 1 deletion bin/nightwatch
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node
require('./runner.js');
require('./runner.js');

90 changes: 4 additions & 86 deletions bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,12 @@
* Module dependencies
*/
var Logger = require('../lib/util/logger.js');
var cli = require('./_cli.js');
var CliRunner = require('./_clirunner.js');

// CLI definitions

// $ nightwatch -c
// $ nightwatch --config
cli.command('config')
.demand(true)
.description('Path to configuration file')
.alias('c')
.defaults('./nightwatch.json');

// $ nightwatch -o
// $ nightwatch --output
cli.command('output')
.description('Where to save the JUnit XML test reports.')
.alias('o')
.defaults('tests_output');

// $ nightwatch -e
// $ nightwatch --env saucelabs
cli.command('env')
.description('Testing environment to use.')
.alias('e')
.defaults('default');

// $ nightwatch --verbose
cli.command('verbose')
.description('Turns on selenium command logging during the session.');

// $ nightwatch -t
// $ nightwatch --test
cli.command('test')
.description('Runs a single test.')
.alias('t');

// $ nightwatch -g
// $ nightwatch --group
cli.command('group')
.description('Runs a group of tests (i.e. a folder)')
.alias('g');

// $ nightwatch -s
// $ nightwatch --skipgroup
cli.command('skipgroup')
.description('Skips one or several (comma separated) group of tests.')
.alias('s');

// $ nightwatch -f
// $ nightwatch --filter
cli.command('filter')
.description('Specify a filter (glob expression) as the file name format to use when loading the files.')
.defaults('')
.alias('f');

// $ nightwatch -a
// $ nightwatch --tag
cli.command('tag')
.description('Only run tests with the given tag.')
.defaults('')
.alias('a');

// $ nightwatch -h
// $ nightwatch --help
cli.command('help')
.description('Shows this help.')
.alias('h');

// $ nightwatch -v
// $ nightwatch --version
cli.command('version')
.alias('v')
.description('Shows version information.');
var Nightwatch = require('../lib/index.js');

try {
var argv = cli.init();
if (argv.help) {
cli.showHelp();
} else if (argv.version) {
var packageConfig = require(__dirname + '/../package.json');
console.log(packageConfig.name + ' v' + packageConfig.version);
} else {
process.chdir(process.cwd());

var runner = module.exports = new CliRunner(argv);
runner.init().runTests();
}
Nightwatch.cli(function(argv) {
Nightwatch.runner(argv);
});
} catch (ex) {
Logger.error('There was an error while starting the test runner:\n\n');
process.stderr.write(ex.stack + '\n');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions lib/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = new (function() {
}
}

var dirPath = path.join(__dirname, './../selenium/assertions/');
var dirPath = path.join(__dirname, './../api/assertions/');

loadAssertionFiles(dirPath, client.api.assert, true);
loadAssertionFiles(dirPath, client.api.verify, false);
Expand Down Expand Up @@ -130,7 +130,7 @@ module.exports = new (function() {
* Loads selenium protocol actions
*/
function loadProtocolActions() {
var protocol = require('./../selenium/protocol.js')(client);
var protocol = require('./../api/protocol.js')(client);
var actions = Object.keys(protocol);
actions.forEach(function(command) {
addCommand(command, protocol[command], client.api, client.api);
Expand All @@ -142,14 +142,14 @@ module.exports = new (function() {
*/
function loadClientCommands() {
// adding element specific commands
var elementCommands = require('./../selenium/element-commands.js')(client);
var elementCommands = require('./../api/element-commands.js')(client);
var entries = Object.keys(elementCommands);
entries.forEach(function(command) {
addCommand(command, elementCommands[command], client.api, client.api);
});

// adding client specific commands
var clientCommands = require('./../selenium/client-commands.js')(client);
var clientCommands = require('./../api/client-commands.js')(client);
entries = Object.keys(clientCommands);
entries.forEach(function(command) {
addCommand(command, clientCommands[command], client.api, client.api, true);
Expand All @@ -162,7 +162,7 @@ module.exports = new (function() {
* Loads the external commands
*/
function loadCommandFiles(context) {
var relativePath = './../selenium/commands/';
var relativePath = './../api/commands/';
var commandFiles = fs.readdirSync(path.join(__dirname, relativePath));
var commandName;
var commandModule;
Expand Down
33 changes: 30 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ Nightwatch.prototype.saveScreenshotToFile = function(fileName, content, cb) {
Nightwatch.prototype.handleTestError = function(result) {
var errorMessage = '';
if (result && result.status) {
var errorCodes = require('./selenium/errors.json');
var errorCodes = require('./api/errors.json');
errorMessage = errorCodes[result.status] && errorCodes[result.status].message || '';
}

Expand Down Expand Up @@ -429,7 +429,34 @@ Nightwatch.prototype.followRedirect = function (request, response) {
return this;
};

exports.client = function(options) {
return new Nightwatch(options);
module.exports = {
client : function(options) {
return new Nightwatch(options);
},

cli : function(runTests) {
var cli = require('./runner/cli/cli.js');
cli.setup();
var argv = cli.init();

if (argv.help) {
cli.showHelp();
} else if (argv.version) {
var packageConfig = require(__dirname + '/../package.json');
console.log(packageConfig.name + ' v' + packageConfig.version);
} else {
if (typeof runTests != 'function') {
throw new Error('Supplied argument needs to be a function!');
}
runTests(argv);
}
},

runner : function(argv, done, settings) {
var CliRunner = require('./runner/cli/clirunner.js');

var runner = new CliRunner(argv);
return runner.init(done).runTests(done, settings);
}
};

Loading

0 comments on commit 2ca4605

Please sign in to comment.