1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 16:30:11 +00:00

Adjust error handling / tests.

This commit is contained in:
hacksalot 2016-02-01 22:56:08 -05:00
parent 70f45d468d
commit fd39cc9fd9
10 changed files with 34 additions and 23 deletions

9
dist/cli/main.js vendored
View File

@ -119,12 +119,9 @@ Definition of the `main` function.
}, true); }, true);
} }
Command.prototype.missingArgument = function(name) { Command.prototype.missingArgument = function(name) {
if (this.name() !== 'new') { _err.err({
throw { fluenterror: this.name() !== 'new' ? HMSTATUS.resumeNotFound : HMSTATUS.createNameMissing
fluenterror: HMSTATUS.resumeNotFound, }, true);
quit: true
};
}
}; };
Command.prototype.helpInformation = function() { Command.prototype.helpInformation = function() {
var manPage; var manPage;

View File

@ -52,7 +52,7 @@ Implementation of the 'create' verb for HackMyResume.
return r; return r;
}, this); }, this);
if (this.hasError() && !opts.assert) { if (this.hasError() && !opts.assert) {
this.reject(results); this.reject(this.errorCode);
} else if (!this.hasError()) { } else if (!this.hasError()) {
this.resolve(results); this.resolve(results);
} }

View File

@ -58,7 +58,6 @@ Implementation of the 'validate' verb for HackMyResume.
} }
r = _validateOne.call(this, t, validator, schemas); r = _validateOne.call(this, t, validator, schemas);
if (r.fluenterror) { if (r.fluenterror) {
console.log(r);
r.quit = opts.assert; r.quit = opts.assert;
this.err(r.fluenterror, r); this.err(r.fluenterror, r);
} }

3
dist/verbs/verb.js vendored
View File

@ -66,7 +66,8 @@ Definition of the Verb class.
payload["throw"] = hot; payload["throw"] = hot;
this.setError(errorCode, payload); this.setError(errorCode, payload);
if (payload.quit) { if (payload.quit) {
this.reject(payload); console.log(payload);
this.reject(errorCode);
} }
this.fire('error', payload); this.fire('error', payload);
if (hot) { if (hot) {

View File

@ -157,8 +157,14 @@ initialize = ( ar, exitCallback ) ->
# Override the .missingArgument behavior # Override the .missingArgument behavior
Command.prototype.missingArgument = (name) -> Command.prototype.missingArgument = (name) ->
if this.name() != 'new' _err.err
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true } fluenterror:
if this.name() != 'new'
then HMSTATUS.resumeNotFound
else HMSTATUS.createNameMissing
, true
return
# Override the .helpInformation behavior # Override the .helpInformation behavior
Command.prototype.helpInformation = -> Command.prototype.helpInformation = ->

View File

@ -39,7 +39,7 @@ _create = ( src, dst, opts ) ->
, @ , @
if @hasError() and !opts.assert if @hasError() and !opts.assert
@reject results @reject @errorCode
else if !@hasError() else if !@hasError()
@resolve results @resolve results
results results

View File

@ -43,7 +43,6 @@ _validate = (sources, unused, opts) ->
return { } if @hasError() and opts.assert return { } if @hasError() and opts.assert
r = _validateOne.call @, t, validator, schemas r = _validateOne.call @, t, validator, schemas
if r.fluenterror if r.fluenterror
console.log r
r.quit = opts.assert r.quit = opts.assert
@err r.fluenterror, r @err r.fluenterror, r
r r

View File

@ -64,7 +64,8 @@ Verb = module.exports = Class.extend
payload.throw = hot payload.throw = hot
@setError errorCode, payload @setError errorCode, payload
if payload.quit if payload.quit
@reject payload console.log payload
@reject errorCode
@fire 'error', payload @fire 'error', payload
if hot if hot
throw payload throw payload

View File

@ -63,7 +63,7 @@ var tests = [
' (multiple JRS resumes)' ' (multiple JRS resumes)'
], ],
[ '!new', [ 'new',
[], [],
[], [],
opts, opts,
@ -152,7 +152,7 @@ var tests = [
} }
], ],
[ '!build', [ 'build',
[ ft + 'jane-fullstacker.json'], [ ft + 'jane-fullstacker.json'],
[ sb + 'shouldnt-exist.pdf' ], [ sb + 'shouldnt-exist.pdf' ],
EXTEND(true, {}, opts, { theme: 'awesome' }), EXTEND(true, {}, opts, { theme: 'awesome' }),
@ -172,16 +172,24 @@ describe('Testing API interface', function () {
shouldSucceed = false; shouldSucceed = false;
} }
it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () { it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' NOT THROW' : ' THROW') + msg, function () {
function runIt() { function runIt() {
try { try {
var v = new FCMD.verbs[verb](); var v = new FCMD.verbs[verb]();
v.on('hmr:error', function(ex) { throw ex; }); v.on('hmr:error', function(ex) { throw ex; });
var r = v.invoke( src, dst, opts ); var prom = v.invoke( src, dst, opts );
if( fnTest ) prom.then(
if( !fnTest( r.sheet ) ) function( obj ) {
throw "Test: Unexpected API result."; if( fnTest )
if( !fnTest( obj ) )
throw "Test: Unexpected API result.";
},
function( error ) {
throw error;
}
);
} }
catch(ex) { catch(ex) {
console.error(ex); console.error(ex);

View File

@ -1,8 +1,8 @@
4| 4|
0|--help 0|--help
0|-h 0|-h
0|--debug 4|--debug
0|-d 4|-d
5|notacommand 5|notacommand
8|new 8|new
0|new test/sandbox/cli-test/new-empty-resume.auto.json 0|new test/sandbox/cli-test/new-empty-resume.auto.json