1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
HackMyResume/test/test-stdout.js

92 lines
2.5 KiB
JavaScript
Raw Normal View History

var chai = require('chai')
, expect = chai.expect
2016-01-09 21:14:28 +00:00
, HMRMAIN = require('../src/cli/main')
, CHALK = require('chalk')
2016-01-09 11:44:47 +00:00
, FS = require('fs')
, PATH = require('path')
, PKG = require('../package.json')
, _ = require('underscore');
2016-01-09 11:44:47 +00:00
var gather = '';
var ConsoleLogOrg = console.log;
var ProcessExitOrg = process.exit;
describe('Testing Ouput interface', function () {
2016-01-09 11:44:47 +00:00
function MyConsoleLog( msg ) {
gather += msg;
ConsoleLogOrg.apply(this, arguments);
}
2016-01-09 11:44:47 +00:00
function MyProcessExit() {
}
function HackMyResumeStub( args ) {
2016-01-09 11:44:47 +00:00
console.log = MyConsoleLog;
process.exit = MyProcessExit;
CHALK.enabled = false;
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');
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;
}
function run( title, args, tests ) {
it( title, function() {
2016-01-09 11:44:47 +00:00
gather = '';
HackMyResumeStub( args );
2016-01-09 11:44:47 +00:00
expect(
_.all( tests, function(t) {
return gather.indexOf(t) > -1;
})
).to.equal(true);
2016-01-09 11:44:47 +00:00
});
}
var title = '*** HackMyResume v' + PKG.version + ' ***';
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');
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 ]);
});