Permalink
Browse files

minor, re-arrange for consistency

  • Loading branch information...
isao committed Jan 3, 2013
1 parent 75405e4 commit 28c2563d80ebfb7ed9a419c9bac81a7851ece804
Showing with 75 additions and 89 deletions.
  1. +75 −89 lib/app/commands/test.js
View
@@ -47,14 +47,12 @@ var libpath = require('path'),
collectedJUnitXML = [],
collectedCoverage = {},
- colorFactory,
- run,
usage,
- options,
inputOptions,
runTests,
Y = require('yui').YUI({useSync: true}).use('json-parse', 'json-stringify');
+
Y.applyConfig({useSync: false});
// OSX's /tmp directory is a symbolic link to /private/tmp, and we want to use
@@ -131,6 +129,16 @@ function configureYUI(YUI, store) {
}
+function colorFactory(code) {
+ function color(code, string) {
+ return '\u001b[' + code + 'm' + string + '\u001b[0m';
+ }
+ return function(string) {
+ return color(code, string);
+ };
+}
+
+
/**
* Pretty-prints the results to the console.
*
@@ -561,67 +569,7 @@ function instrumentDirectory(from, verbose, testType, callback) {
}
-colorFactory = function(code) {
- function color(code, string) {
- return '\u001b[' + code + 'm' + string + '\u001b[0m';
- }
- return function(string) {
- return color(code, string);
- };
-};
-
-
-run = function(params, opts) {
- var artifactsDir = 'artifacts',
- testOption = params[0],
- dir = params[1],
- testName,
- stat;
-
- inputOptions = opts || {};
-
- if (inputOptions.tmpdir) {
- if (!existsSync(inputOptions.tmpdir)) {
- utils.warn('The temporary directory you specified does not exist.' +
- ' It will be created.');
- libfs.mkdirSync(inputOptions.tmpdir, MODE_ALL);
- }
- mojitoTmp = libpath.join(inputOptions.tmpdir, 'mojitotmp');
- mojitoInstrumentedDir = libpath.join(inputOptions.tmpdir, 'mojitoinst');
- }
-
- if (!existsSync(artifactsDir)) {
- libfs.mkdirSync(artifactsDir, MODE_ALL);
- }
- if (existsSync(resultsDir)) {
- utils.removeDir(libfs.realpathSync(resultsDir));
- libfs.rmdirSync(libfs.realpathSync(resultsDir));
- }
- libfs.mkdirSync(resultsDir, MODE_ALL);
-
- if (testOption === 'app' || testOption === 'mojit') {
- testName = params[2];
- if (!dir) {
- utils.error('Please specify ' + testOption + ' directory to test.',
- usage,
- true
- );
- }
- try {
- stat = libfs.statSync(dir);
- if (!stat.isDirectory()) {
- utils.error('"' + dir + '" is not a directory.', usage, true);
- }
- } catch (err) {
- utils.error('Invalid directory: \'' + dir + '\'', usage, true);
- }
- runTests({path: dir, type: testOption, name: testName});
- } else {
- utils.error('Invalid parameter.', usage, true);
- }
-};
-
-runTests = function(opts) {
+function runTests(opts) {
var i,
ttn,
@@ -752,7 +700,58 @@ runTests = function(opts) {
testRunner(path);
}
-};
+}
+
+
+function run(params, opts) {
+ var artifactsDir = 'artifacts',
+ testOption = params[0],
+ dir = params[1],
+ testName,
+ stat;
+
+ inputOptions = opts || {};
+
+ if (inputOptions.tmpdir) {
+ if (!existsSync(inputOptions.tmpdir)) {
+ utils.warn('The temporary directory you specified does not exist.' +
+ ' It will be created.');
+ libfs.mkdirSync(inputOptions.tmpdir, MODE_ALL);
+ }
+ mojitoTmp = libpath.join(inputOptions.tmpdir, 'mojitotmp');
+ mojitoInstrumentedDir = libpath.join(inputOptions.tmpdir, 'mojitoinst');
+ }
+
+ if (!existsSync(artifactsDir)) {
+ libfs.mkdirSync(artifactsDir, MODE_ALL);
+ }
+ if (existsSync(resultsDir)) {
+ utils.removeDir(libfs.realpathSync(resultsDir));
+ libfs.rmdirSync(libfs.realpathSync(resultsDir));
+ }
+ libfs.mkdirSync(resultsDir, MODE_ALL);
+
+ if (testOption === 'app' || testOption === 'mojit') {
+ testName = params[2];
+ if (!dir) {
+ utils.error('Please specify ' + testOption + ' directory to test.',
+ usage,
+ true
+ );
+ }
+ try {
+ stat = libfs.statSync(dir);
+ if (!stat.isDirectory()) {
+ utils.error('"' + dir + '" is not a directory.', usage, true);
+ }
+ } catch (err) {
+ utils.error('Invalid directory: \'' + dir + '\'', usage, true);
+ }
+ runTests({path: dir, type: testOption, name: testName});
+ } else {
+ utils.error('Invalid parameter.', usage, true);
+ }
+}
/**
@@ -763,7 +762,17 @@ YUITest.Assert.skip = function() {
};
-options = [
+exports.run = run;
+
+exports.usage = usage = [
+ 'Options: -c --coverage Instruments code under test and prints coverage report',
+ ' -v --verbose Verbose logging',
+ 'To test a mojit:',
+ ' mojito test mojit ./path/to/mojit/directory',
+ 'To test a Mojito app:',
+ ' mojito test app ./path/to/mojito/app/directory'].join('\n');
+
+exports.options = [
{
longName: 'coverage',
shortName: 'c',
@@ -780,26 +789,3 @@ options = [
hasValue: true
}
];
-
-
-usage = 'Options: -c --coverage Instruments code under test and prints ' +
- 'coverage report\n' +
- ' -v --verbose Verbose logging\n' +
- 'To test a mojit:\n' +
- ' mojito test mojit ./path/to/mojit/directory\n' +
- 'To test a Mojito app:\n' +
- ' mojito test app ./path/to/mojito/app/directory\n' +
- ' \n' +
- 'NOTE: You cannot generate test coverage for a Mojito application,' +
- ' only individual mojits.';
-
-/**
- */
-exports.run = run;
-/**
- */
-exports.usage = usage;
-
-/**
- */
-exports.options = options;

0 comments on commit 28c2563

Please sign in to comment.