1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-03 00:30:05 +01:00

Update tests.

This commit is contained in:
hacksalot 2016-01-09 06:44:47 -05:00
parent 88c71f6e9c
commit 43564bf380
3 changed files with 33 additions and 9 deletions

View File

@ -73,7 +73,8 @@ describe('Testing CLI interface', function () {
it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () { it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () {
function runIt() { function runIt() {
try { try {
FCMD.verbs[verb]( src, dst, opts, opts.silent ? var v = new FCMD.verbs[verb]();
v.invoke( src, dst, opts, opts.silent ?
function(){} : function(msg){ msg = msg || ''; console.log(msg); } ); function(){} : function(msg){ msg = msg || ''; console.log(msg); } );
} }
catch(ex) { catch(ex) {

View File

@ -2,23 +2,33 @@ var chai = require('chai')
, expect = chai.expect , expect = chai.expect
, HMRMAIN = require('../src/main') , HMRMAIN = require('../src/main')
, CHALK = require('chalk') , CHALK = require('chalk')
, FS = require('fs')
, PATH = require('path')
, _ = require('underscore'); , _ = require('underscore');
// Disable colors for easier output testing var gather = '';
CHALK.enabled = false; var ConsoleLogOrg = console.log;
var ProcessExitOrg = process.exit;
describe('Testing Ouput interface', function () { describe('Testing Ouput interface', function () {
var gather = '';
var ConsoleLogOrg = console.log;
function MyConsoleLog( msg ) { function MyConsoleLog( msg ) {
gather += msg; gather += msg;
ConsoleLogOrg.apply(this, arguments); ConsoleLogOrg.apply(this, arguments);
} }
function MyProcessExit() {
}
function HackMyResumeStub( args ) { function HackMyResumeStub( args ) {
console.log = MyConsoleLog;
process.exit = MyProcessExit;
CHALK.enabled = false;
try { try {
args.unshift( process.argv[1] ); args.unshift( process.argv[1] );
args.unshift( process.argv[0] ); args.unshift( process.argv[0] );
@ -28,24 +38,30 @@ describe('Testing Ouput interface', function () {
catch( ex ) { catch( ex ) {
require('../src/core/error-handler').err( ex, false ); require('../src/core/error-handler').err( ex, false );
} }
CHALK.enabled = true;
process.exit = ProcessExitOrg;
console.log = ConsoleLogOrg;
} }
function run( title, args, tests ) { function run( title, args, tests ) {
it( title, function() { it( title, function() {
gather = ''; gather = '';
console.log = MyConsoleLog;
HackMyResumeStub( args ); HackMyResumeStub( args );
console.log = ConsoleLogOrg;
expect( expect(
_.all( tests, function(t) { _.all( tests, function(t) {
return gather.indexOf(t) > -1; return gather.indexOf(t) > -1;
}) })
).to.equal(true); ).to.equal(true);
}); });
} }
var title = '*** HackMyResume v1.5.2 ***'; var title = '*** HackMyResume v1.5.2 ***';
var feedMe = 'Please feed me a resume in FRESH or JSON Resume format.'; var feedMe = 'Please feed me a resume in FRESH or JSON Resume format.';
var manPage = FS.readFileSync( PATH.resolve( __dirname, '../src/use.txt' ), 'utf8');
run('HMR should output a help string when no command is specified', run('HMR should output a help string when no command is specified',
[], [ title, 'Please give me a command (BUILD, ANALYZE, VALIDATE, CONVERT, or NEW).' ]); [], [ title, 'Please give me a command (BUILD, ANALYZE, VALIDATE, CONVERT, or NEW).' ]);
@ -65,5 +81,10 @@ describe('Testing Ouput interface', function () {
run('NEW should output a tip when no source is specified', run('NEW should output a tip when no source is specified',
['new'], [ title, 'Please specify the filename of the resume to create.' ]); ['new'], [ title, 'Please specify the filename of the resume to create.' ]);
// 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 ]);
}); });

View File

@ -9,7 +9,8 @@ var chai = require('chai')
, validator = require('is-my-json-valid') , validator = require('is-my-json-valid')
, READFILES = require('recursive-readdir-sync') , READFILES = require('recursive-readdir-sync')
, fileContains = require('../src/utils/file-contains') , fileContains = require('../src/utils/file-contains')
, FS = require('fs'); , FS = require('fs')
, CHALK = require('chalk');
chai.config.includeStack = true; chai.config.includeStack = true;
@ -34,7 +35,8 @@ function genThemes( title, src, fmt ) {
css: 'embed' css: 'embed'
}; };
try { try {
HMR.verbs.build( src, dst, opts, function(msg) { var v = new HMR.verbs.build();
v.invoke( src, dst, opts, function(msg) {
msg = msg || ''; msg = msg || '';
console.log(msg); console.log(msg);
}); });