diff --git a/tests/cli/lib/lib_test_descriptor.json b/tests/cli/lib/lib_test_descriptor.json new file mode 100644 index 000000000..e53da8a76 --- /dev/null +++ b/tests/cli/lib/lib_test_descriptor.json @@ -0,0 +1,23 @@ +[ + { + "settings": [ "master" ], + "name": "lib-cli-tests", + "config": { + "lib": "../../../lib", + "base": "../../base" + }, + "commonlib": "$$config.base$$/mojito-test.js", + "dataprovider" : { + "cli.js": { + "params": { + "test": "./management/test-cli.js", + "driver": "nodejs" + }, + "group": "fw,cli" + } + } + }, + { + "settings": [ "environment:development" ] + } +] diff --git a/tests/cli/lib/management/test-cli.js b/tests/cli/lib/management/test-cli.js new file mode 100644 index 000000000..642fb097d --- /dev/null +++ b/tests/cli/lib/management/test-cli.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved. + * Copyrights licensed under the New BSD License. + * See the accompanying LICENSE file for terms. + */ + +// NOTE the dependency on 'test' here, but not 'cli', since cli.js is NOT a YUI +// module...and most command files aren't either. +YUI().use('test', function(Y) { + + var suite = new Y.Test.Suite('cli tests'), + A = Y.Assert, + OA = Y.ObjectAssert, + libpath = require('path'); + + suite.add(new Y.Test.Case({ + + name: 'cli tests', + + 'load check': function() { + var cli = require(libpath.join(__dirname, + '../../../../lib/management/cli.js')); + + A.isNotNull(cli); + A.isFunction(cli.run); + } + + })); + + Y.Test.Runner.add(suite); +}); diff --git a/tests/run.js b/tests/run.js index 299c558d4..9e7da0a4f 100755 --- a/tests/run.js +++ b/tests/run.js @@ -14,6 +14,7 @@ var fs = require('fs'), program.command('test') .description('Run unit and functional tests') + .option('-c, --cli', 'Run command line tests') .option('-u, --unit', 'Run unit tests') .option('-f, --func', 'Run functional tests') .option('-b, --no-build', 'Don\'t build the apps') @@ -49,17 +50,28 @@ function test (cmd) { var series = []; cmd.logLevel = cmd.logLevel || 'WARN'; // Default to all tests - if (!cmd.unit && !cmd.func) { + if (!cmd.unit && !cmd.func && !cmd.cli) { + cmd.cli = true; cmd.unit = true; cmd.func = true; } cmd.unitBrowser = cmd.unitBrowser || cmd.browser || 'firefox'; cmd.funcBrowser = cmd.funcBrowser || cmd.browser || 'firefox'; + cmd.cliPath = path.resolve(cwd, cmd.cliPath || cmd.path || './cli'); cmd.unitPath = path.resolve(cwd, cmd.unitPath || cmd.path || './unit'); cmd.funcPath = path.resolve(cwd, cmd.funcPath || cmd.path || './func'); - if (cmd.arrow) { + + // We only start the Arrow server when we're running unit or functional + // tests. If we're only running cli tests we skip that since it slows things + // down without adding value. + if (cmd.arrow && (!cmd.cli || (!cmd.cli && !cmd.unit && !cmd.func))) { series.push(startArrowServer); } + if (cmd.cli) { + series.push(function (callback) { + runCliTests(cmd, callback) + }); + } if (cmd.unit) { if ('phantomjs' !== cmd.unitBrowser) { if (cmd.selenium) { @@ -122,6 +134,42 @@ function startArrowServer (callback) { }, 5000); } +function runCliTests (cmd, callback) { + console.log('---Running CLI Tests---'); + var arrowReportDir = cmd.cliPath + '/artifacts/arrowreport/'; + try { + wrench.rmdirSyncRecursive(arrowReportDir); + } catch (e) {} + wrench.mkdirSyncRecursive(arrowReportDir); + + var commandArgs = [ + cwd + "/../node_modules/yahoo-arrow/index.js", + "--descriptor=" + cmd.cliPath + "/**/*_descriptor.json", + "--report=true", + "--reportFolder=" + arrowReportDir + ]; + // Unlike other test types the CLI tests force use of the nodejs driver and + // do not specify a browser since one won't be useful for CLI testing. + commandArgs.push('--driver=nodejs'); + + commandArgs.push('--logLevel=' + cmd.logLevel); + cmd.testName && commandArgs.push('--testName=' + cmd.testName); + cmd.group && commandArgs.push('--group=' + cmd.group); + cmd.coverage && commandArgs.push('--coverage=' + cmd.coverage); + + var p = runCommand( + cmd.cliPath, + "node", + commandArgs, + function (code) { + callback(code); + } + ); + p.stdout.on('data', function (data) { + process.stdout.write(data); + }); +} + function runUnitTests (cmd, callback) { console.log('---Running Unit Tests---'); var arrowReportDir = cmd.unitPath + '/artifacts/arrowreport/';