2016-01-09 10:29:45 +00:00
|
|
|
var chai = require('chai')
|
|
|
|
, expect = chai.expect
|
2016-01-09 21:14:28 +00:00
|
|
|
, HMRMAIN = require('../src/cli/main')
|
2016-01-09 10:29:45 +00:00
|
|
|
, CHALK = require('chalk')
|
2016-01-09 11:44:47 +00:00
|
|
|
, FS = require('fs')
|
|
|
|
, PATH = require('path')
|
2016-01-10 01:29:30 +00:00
|
|
|
, PKG = require('../package.json')
|
2016-01-09 10:29:45 +00:00
|
|
|
, _ = require('underscore');
|
|
|
|
|
2016-01-09 11:44:47 +00:00
|
|
|
var gather = '';
|
|
|
|
var ConsoleLogOrg = console.log;
|
|
|
|
var ProcessExitOrg = process.exit;
|
2016-01-09 10:29:45 +00:00
|
|
|
|
|
|
|
describe('Testing Ouput interface', function () {
|
|
|
|
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
|
|
|
|
function MyConsoleLog( msg ) {
|
|
|
|
gather += msg;
|
|
|
|
ConsoleLogOrg.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
2016-01-09 11:44:47 +00:00
|
|
|
function MyProcessExit() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
function HackMyResumeStub( args ) {
|
|
|
|
|
2016-01-09 11:44:47 +00:00
|
|
|
console.log = MyConsoleLog;
|
|
|
|
process.exit = MyProcessExit;
|
|
|
|
CHALK.enabled = false;
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
try {
|
|
|
|
args.unshift( process.argv[1] );
|
|
|
|
args.unshift( process.argv[0] );
|
2016-01-09 21:14:28 +00:00
|
|
|
var HMRMAIN = require('../src/cli/main');
|
2016-01-09 10:29:45 +00:00
|
|
|
HMRMAIN( args );
|
|
|
|
}
|
|
|
|
catch( ex ) {
|
|
|
|
require('../src/core/error-handler').err( ex, false );
|
|
|
|
}
|
2016-01-09 11:44:47 +00:00
|
|
|
CHALK.enabled = true;
|
|
|
|
process.exit = ProcessExitOrg;
|
|
|
|
console.log = ConsoleLogOrg;
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function run( title, args, tests ) {
|
|
|
|
it( title, function() {
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
gather = '';
|
|
|
|
HackMyResumeStub( args );
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
expect(
|
|
|
|
_.all( tests, function(t) {
|
|
|
|
return gather.indexOf(t) > -1;
|
|
|
|
})
|
|
|
|
).to.equal(true);
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-10 01:29:30 +00:00
|
|
|
var title = '*** HackMyResume v' + PKG.version + ' ***';
|
2016-01-09 10:29:45 +00:00
|
|
|
var feedMe = 'Please feed me a resume in FRESH or JSON Resume format.';
|
2016-01-09 21:14:28 +00:00
|
|
|
var manPage = FS.readFileSync( PATH.resolve( __dirname, '../src/cli/use.txt' ), 'utf8');
|
2016-01-09 10:29:45 +00:00
|
|
|
|
|
|
|
run('HMR should output a help string when no command is specified',
|
|
|
|
[], [ title, 'Please give me a command (BUILD, ANALYZE, VALIDATE, CONVERT, or NEW).' ]);
|
|
|
|
|
|
|
|
run('BUILD should output a tip when no source is specified',
|
|
|
|
['build'], [ title, feedMe ]);
|
|
|
|
|
|
|
|
run('VALIATE should output a tip when no source is specified',
|
|
|
|
['validate'], [ title, feedMe ]);
|
|
|
|
|
|
|
|
run('ANALYZE should output a tip when no source is specified',
|
|
|
|
['analyze'], [ title, feedMe ]);
|
|
|
|
|
|
|
|
run('CONVERT should output a tip when no source is specified',
|
|
|
|
['convert'], [ title, feedMe ]);
|
|
|
|
|
|
|
|
run('NEW should output a tip when no source is specified',
|
|
|
|
['new'], [ title, 'Please specify the filename of the resume to create.' ]);
|
|
|
|
|
2016-01-09 11:44:47 +00:00
|
|
|
// This will cause the HELP doc to be emitted, followed by an "unknown option --help"
|
|
|
|
// error in the log, based on the way we're calling into HMR. As long as the test
|
|
|
|
// passes, any extraneous error messages can be ignored here.
|
|
|
|
run('HMR should output help doc with --help',
|
|
|
|
['--help'], [ manPage ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
|
|
|
});
|