Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Preliminary CLI test infrastructure. #817

Merged
merged 2 commits into from
Nov 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/cli/lib/lib_test_descriptor.json
Original file line number Diff line number Diff line change
@@ -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" ]
}
]
31 changes: 31 additions & 0 deletions tests/cli/lib/management/test-cli.js
Original file line number Diff line number Diff line change
@@ -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);
});
52 changes: 50 additions & 2 deletions tests/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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/';
Expand Down