From 43564bf380916b320b0f1031fb7b85449603a9ff Mon Sep 17 00:00:00 2001 From: hacksalot Date: Sat, 9 Jan 2016 06:44:47 -0500 Subject: [PATCH] Update tests. --- test/test-cli.js | 3 ++- test/test-stdout.js | 33 +++++++++++++++++++++++++++------ test/test-themes.js | 6 ++++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/test/test-cli.js b/test/test-cli.js index 957c3bb..b3fc9ec 100644 --- a/test/test-cli.js +++ b/test/test-cli.js @@ -73,7 +73,8 @@ describe('Testing CLI interface', function () { it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () { function runIt() { 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); } ); } catch(ex) { diff --git a/test/test-stdout.js b/test/test-stdout.js index aa425cb..b3d4c1b 100644 --- a/test/test-stdout.js +++ b/test/test-stdout.js @@ -2,23 +2,33 @@ var chai = require('chai') , expect = chai.expect , HMRMAIN = require('../src/main') , CHALK = require('chalk') + , FS = require('fs') + , PATH = require('path') , _ = require('underscore'); -// Disable colors for easier output testing -CHALK.enabled = false; +var gather = ''; +var ConsoleLogOrg = console.log; +var ProcessExitOrg = process.exit; describe('Testing Ouput interface', function () { - var gather = ''; - var ConsoleLogOrg = console.log; + function MyConsoleLog( msg ) { gather += msg; ConsoleLogOrg.apply(this, arguments); } + function MyProcessExit() { + + } + function HackMyResumeStub( args ) { + console.log = MyConsoleLog; + process.exit = MyProcessExit; + CHALK.enabled = false; + try { args.unshift( process.argv[1] ); args.unshift( process.argv[0] ); @@ -28,24 +38,30 @@ describe('Testing Ouput interface', function () { catch( ex ) { require('../src/core/error-handler').err( ex, false ); } + CHALK.enabled = true; + process.exit = ProcessExitOrg; + console.log = ConsoleLogOrg; + } function run( title, args, tests ) { it( title, function() { + gather = ''; - console.log = MyConsoleLog; HackMyResumeStub( args ); - console.log = ConsoleLogOrg; + expect( _.all( tests, function(t) { return gather.indexOf(t) > -1; }) ).to.equal(true); + }); } var title = '*** HackMyResume v1.5.2 ***'; 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', [], [ 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', ['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 ]); }); diff --git a/test/test-themes.js b/test/test-themes.js index 7cc7440..a030647 100644 --- a/test/test-themes.js +++ b/test/test-themes.js @@ -9,7 +9,8 @@ var chai = require('chai') , validator = require('is-my-json-valid') , READFILES = require('recursive-readdir-sync') , fileContains = require('../src/utils/file-contains') - , FS = require('fs'); + , FS = require('fs') + , CHALK = require('chalk'); chai.config.includeStack = true; @@ -34,7 +35,8 @@ function genThemes( title, src, fmt ) { css: 'embed' }; try { - HMR.verbs.build( src, dst, opts, function(msg) { + var v = new HMR.verbs.build(); + v.invoke( src, dst, opts, function(msg) { msg = msg || ''; console.log(msg); });