From d7c83613df447e6d491777f8806ec662064011b2 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Tue, 2 Feb 2016 16:18:38 -0500 Subject: [PATCH] Make CLI tests asynchronous. --- test/scripts/test-cli.js | 43 +++++++++------------------------------ test/scripts/test-hmr.txt | 1 + 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/test/scripts/test-cli.js b/test/scripts/test-cli.js index da8fefe..1ccdf4f 100644 --- a/test/scripts/test-cli.js +++ b/test/scripts/test-cli.js @@ -8,52 +8,31 @@ CLI test routines for HackMyResume. var chai = require('chai') , should = chai.should() , expect = chai.expect - , HMRMAIN = require('../../dist/cli/main') - , CHALK = require('chalk') , FS = require('fs') , PATH = require('path') - , PKG = require('../../package.json') - , STRIPCOLOR = require('stripcolorcodes') - , _ = require('underscore') - , EXEC = require('child_process').execSync + , EXEC = require('child_process').exec - -var gather = ''; -var ConsoleLogOrg = console.log; -var ProcessExitOrg = process.exit; -var commandRetVal = 0; - -// TODO: use sinon -// Replacement for process.exit() -function MyProcessExit( retVal ) { - commandRetVal = retVal; -} - -// TODO: use sinon -// Replacement for console.log -function MyConsoleLog() { - var tx = Array.prototype.slice.call(arguments).join(' '); - gather += STRIPCOLOR( tx ); - ConsoleLogOrg.apply(this, arguments); -} - describe('Testing CLI interface', function () { + this.timeout(5000); // Run a test through the stub, gathering console.log output into "gather" // and testing against it. function run( args, expErr ) { var title = args; - it( 'Testing: "' + title + '"\n\n', function() { + it( 'Testing: "' + title + '"\n\n', function( done ) { try { - EXEC('hackmyresume ' + args); - commandRetVal = 0; + EXEC('hackmyresume ' + args, null, function(err,stdo,stde) { + var errCode = (err && err.code) || 0; + errCode.should.equal( parseInt(expErr, 10) ); + done(); + }); } catch(ex) { - commandRetVal = ex.status; + ex.status.should.equal( parseInt(expErr, 10) ); + done(); } - commandRetVal.should.equal( parseInt(expErr, 10) ); }); } @@ -68,6 +47,4 @@ describe('Testing CLI interface', function () { } }); - process.exit = ProcessExitOrg; - }); diff --git a/test/scripts/test-hmr.txt b/test/scripts/test-hmr.txt index 7debe24..bdf2c82 100644 --- a/test/scripts/test-hmr.txt +++ b/test/scripts/test-hmr.txt @@ -10,6 +10,7 @@ 0|new test/sandbox/cli-test/new-empty-resume.fresh.json -f fresh 3|analyze 14|analyze doesnt-exist.json +0|analyze node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json 3|convert 7|convert doesnt-exist.json 3|validate