mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Improve errors / tests consistency.
This commit is contained in:
parent
86af2a2c4f
commit
c9ae2ffef3
@ -67,7 +67,7 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
// Load and parse the resume JSON
|
// Load and parse the resume JSON
|
||||||
var info = _parse( src, opts, emitter );
|
var info = _parse( src, opts, emitter );
|
||||||
if( info.error ) return info;
|
if( info.fluenterror ) return info;
|
||||||
|
|
||||||
// Determine the resume format: FRESH or JRS
|
// Determine the resume format: FRESH or JRS
|
||||||
var json = info.json;
|
var json = info.json;
|
||||||
@ -123,6 +123,8 @@ Definition of the ResumeFactory class.
|
|||||||
inner: e, raw: rawData, file: fileName, shouldExit: false
|
inner: e, raw: rawData, file: fileName, shouldExit: false
|
||||||
};
|
};
|
||||||
eve && eve.err( ex.fluenterror, ex );
|
eve && eve.err( ex.fluenterror, ex );
|
||||||
|
if( opts.throw ) throw ex;
|
||||||
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,16 @@ Implementation of the 'analyze' verb for HackMyResume.
|
|||||||
function analyze( sources, dst, opts ) {
|
function analyze( sources, dst, opts ) {
|
||||||
this.stat('begin');
|
this.stat('begin');
|
||||||
if( !sources || !sources.length ) throw { fluenterror: 3 };
|
if( !sources || !sources.length ) throw { fluenterror: 3 };
|
||||||
|
|
||||||
var nlzrs = _loadInspectors();
|
var nlzrs = _loadInspectors();
|
||||||
|
|
||||||
_.each(sources, function(src) {
|
_.each(sources, function(src) {
|
||||||
var result = ResumeFactory.loadOne( src, {
|
var result = ResumeFactory.loadOne( src, {
|
||||||
format: 'FRESH', objectify: true, throw: false
|
format: 'FRESH', objectify: true
|
||||||
});
|
|
||||||
result.error || _analyze.call(this, result, nlzrs, opts );
|
|
||||||
}, this);
|
}, this);
|
||||||
|
result.fluenterror || _analyze.call(this, result, nlzrs, opts );
|
||||||
|
}, this);
|
||||||
|
|
||||||
this.stat('end');
|
this.stat('end');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ Implementation of the 'build' verb for HackMyResume.
|
|||||||
// Load the theme...we do this first because the theme choice (FRESH or
|
// Load the theme...we do this first because the theme choice (FRESH or
|
||||||
// JSON Resume) determines what format we'll convert the resume to.
|
// JSON Resume) determines what format we'll convert the resume to.
|
||||||
this.stat( HME.beforeTheme, { theme: _opts.theme });
|
this.stat( HME.beforeTheme, { theme: _opts.theme });
|
||||||
var tFolder = verifyTheme( _opts.theme );
|
var tFolder = verifyTheme.call( this, _opts.theme );
|
||||||
var theme = loadTheme( tFolder );
|
var theme = loadTheme( tFolder );
|
||||||
this.stat( HME.afterTheme, { theme: theme });
|
this.stat( HME.afterTheme, { theme: theme });
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ Implementation of the 'validate' verb for HackMyResume.
|
|||||||
var ret = { file: src, isValid: false };
|
var ret = { file: src, isValid: false };
|
||||||
|
|
||||||
// If there was an error reading the resume
|
// If there was an error reading the resume
|
||||||
if( src.error ) {
|
if( src.fluenterror ) {
|
||||||
if( opts.assert ) throw { fluenterror: HACKMYSTATUS.invalid };
|
if( opts.assert ) throw src;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
76
test/test-cli.js
Normal file
76
test/test-cli.js
Normal 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
20
test/test-hmr.txt
Normal 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
|
@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
Output test routines for HackMyResume.
|
||||||
|
@module test-stdout.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
, expect = chai.expect
|
, expect = chai.expect
|
||||||
, HMRMAIN = require('../src/cli/main')
|
, HMRMAIN = require('../src/cli/main')
|
||||||
@ -7,23 +14,29 @@ var chai = require('chai')
|
|||||||
, PKG = require('../package.json')
|
, PKG = require('../package.json')
|
||||||
, _ = require('underscore');
|
, _ = require('underscore');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var gather = '';
|
var gather = '';
|
||||||
var ConsoleLogOrg = console.log;
|
var ConsoleLogOrg = console.log;
|
||||||
var ProcessExitOrg = process.exit;
|
var ProcessExitOrg = process.exit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('Testing Ouput interface', function () {
|
describe('Testing Ouput interface', function () {
|
||||||
|
|
||||||
|
// TODO: use sinon
|
||||||
|
// Replacement for console.log
|
||||||
function MyConsoleLog( msg ) {
|
function MyConsoleLog( msg ) {
|
||||||
gather += Array.prototype.slice.call(arguments).join(' ');
|
gather += Array.prototype.slice.call(arguments).join(' ');
|
||||||
ConsoleLogOrg.apply(this, arguments);
|
ConsoleLogOrg.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replacement for process.exit()
|
||||||
function MyProcessExit() {
|
function MyProcessExit() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HackMyResume CLI stub. Handle a single HMR invocation.
|
||||||
function HackMyResumeStub( args ) {
|
function HackMyResumeStub( args ) {
|
||||||
|
|
||||||
console.log = MyConsoleLog;
|
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 ) {
|
function run( title, args, tests ) {
|
||||||
it( title, function() {
|
it( title, function() {
|
||||||
|
|
||||||
@ -78,7 +93,8 @@ describe('Testing Ouput interface', function () {
|
|||||||
|
|
||||||
run('BUILD should display an error on a broken resume',
|
run('BUILD should display an error on a broken resume',
|
||||||
['build',
|
['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' ]);
|
], [ title, 'Error: Invalid or corrupt JSON on line' ]);
|
||||||
|
|
||||||
run('CONVERT should output a tip when no source is specified',
|
run('CONVERT should output a tip when no source is specified',
|
||||||
|
Loading…
Reference in New Issue
Block a user