1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-02 12:27:08 +01:00

Improve errors / tests consistency.

This commit is contained in:
hacksalot
2016-01-14 14:22:26 -05:00
parent 86af2a2c4f
commit c9ae2ffef3
7 changed files with 127 additions and 10 deletions

76
test/test-cli.js Normal file
View File

@ -0,0 +1,76 @@
/**
CLI test routines for HackMyResume.
@module test-cli.js
*/
var chai = require('chai')
, should = chai.should()
, HMRMAIN = require('../src/cli/main')
, CHALK = require('chalk')
, FS = require('fs')
, PATH = require('path')
, PKG = require('../package.json')
, _ = require('underscore');
var gather = '';
var ConsoleLogOrg = console.log;
var ProcessExitOrg = process.exit;
var commandRetVal = 0;
describe('Testing Ouput interface', function () {
// TODO: use sinon
// Replacement for process.exit()
function MyProcessExit( retVal ) {
commandRetVal = retVal;
}
// HackMyResume CLI stub. Handle a single HMR invocation.
function HackMyResumeStub( argsString ) {
var args = argsString.split(' ');
args.unshift( process.argv[1] );
args.unshift( process.argv[0] );
process.exit = MyProcessExit;
try {
var HMRMAIN = require('../src/cli/main');
HMRMAIN( args );
}
catch( ex ) {
require('../src/cli/error').err( ex, false );
//if(ex.stack || (ex.inner && ex.inner.stacl))
//console.log(ex.stack || ex.inner.stack);
}
process.exit = ProcessExitOrg;
}
// 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() {
commandRetVal = 0;
HackMyResumeStub( args );
commandRetVal.should.equal( parseInt(expErr, 10) );
});
}
var lines = FS.readFileSync( PATH.join( __dirname, './test-hmr.txt'), 'utf8').split('\n');
lines.forEach(function(l){
if( l && l.trim() ) {
if(l[0] !== '#') {
var lineInfo = l.split('|');
var errCode = lineInfo[0];
run( lineInfo.length > 1 ? lineInfo[1] : '', errCode );
}
}
});
});

20
test/test-hmr.txt Normal file
View File

@ -0,0 +1,20 @@
0|
3|build
8|new
3|analyze
3|convert
3|validate
5|notacommand
4|--help
4|-h
4|--debug
4|-d
14|build doesnt-exist.json
14|analyze doesnt-exist.json
7|convert doesnt-exist.json
14|validate doesnt-exist.json
1|build doesnt-exist.json -t not-a-theme
1|build doesnt-exist.json -t node_modules/not-a-theme
0|new test/sandbox/cli-test/new-empty-resume.auto.json
0|new test/sandbox/cli-test/new-empty-resume.jrs.json -f jrs
0|new test/sandbox/cli-test/new-empty-resume.fresh.json -f fresh

View File

@ -1,3 +1,10 @@
/**
Output test routines for HackMyResume.
@module test-stdout.js
*/
var chai = require('chai')
, expect = chai.expect
, HMRMAIN = require('../src/cli/main')
@ -7,23 +14,29 @@ var chai = require('chai')
, PKG = require('../package.json')
, _ = require('underscore');
var gather = '';
var ConsoleLogOrg = console.log;
var ProcessExitOrg = process.exit;
describe('Testing Ouput interface', function () {
// TODO: use sinon
// Replacement for console.log
function MyConsoleLog( msg ) {
gather += Array.prototype.slice.call(arguments).join(' ');
ConsoleLogOrg.apply(this, arguments);
}
// Replacement for process.exit()
function MyProcessExit() {
}
// HackMyResume CLI stub. Handle a single HMR invocation.
function HackMyResumeStub( args ) {
console.log = MyConsoleLog;
@ -45,6 +58,8 @@ describe('Testing Ouput interface', function () {
}
// Run a test through the stub, gathering console.log output into "gather"
// and testing against it.
function run( title, args, tests ) {
it( title, function() {
@ -78,7 +93,8 @@ describe('Testing Ouput interface', function () {
run('BUILD should display an error on a broken resume',
['build',
'node_modules/fresh-test-resumes/src/johnny-trouble.broken.fresh.json'
'node_modules/fresh-test-resumes/src/johnny-trouble.broken.fresh.json',
'-t', 'modern'
], [ title, 'Error: Invalid or corrupt JSON on line' ]);
run('CONVERT should output a tip when no source is specified',