1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-02 12:27:08 +01:00
This commit is contained in:
hacksalot
2016-01-18 00:34:57 -05:00
parent c9e45d4991
commit 712cba57b8
17 changed files with 122 additions and 229 deletions

View File

@ -1,99 +0,0 @@
/**
@module test-api.js
*/
var chai = require('chai')
, expect = chai.expect
, should = chai.should()
, path = require('path')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, FCMD = require( '../src/hackmyapi')
, validator = require('is-my-json-valid')
, HMRMAIN = require('../src/cli/main')
, EXTEND = require('../src/utils/extend');
chai.config.includeStack = false;
describe('Testing CLI interface', function () {
var _sheet;
var opts = {
format: 'FRESH',
prettify: true,
silent: false,
assert: true // Causes validation errors to throw exceptions
};
var opts2 = {
format: 'JRS',
prettify: true,
silent: true
};
var sb = 'test/sandbox/';
var ft = 'node_modules/fresh-test-resumes/src/fresh/';
[
[ 'new', [sb + 'new-fresh-resume.json'], [], opts, ' (FRESH format)' ],
[ 'new', [sb + 'new-jrs-resume.json'], [], opts2, ' (JRS format)'],
[ 'new', [sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'], [], opts, ' (multiple FRESH resumes)' ],
[ 'new', [sb + 'new-jrs-1.json', sb + 'new-jrs-2.json', sb + 'new-jrs-3.json'], [], opts, ' (multiple JRS resumes)' ],
[ '!new', [], [], opts, " (when a filename isn't specified)" ],
[ 'validate', [ft + 'jane-fullstacker.json'], [], opts, ' (jane-q-fullstacker|FRESH)' ],
[ 'validate', [ft + 'johnny-trouble.json'], [], opts, ' (johnny-trouble|FRESH)' ],
[ 'validate', [sb + 'new-fresh-resume.json'], [], opts, ' (new-fresh-resume|FRESH)' ],
[ 'validate', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], [], opts2, ' (richard-hendriks.json|JRS)' ],
[ 'validate', ['test/resumes/jrs-0.0.0/jane-incomplete.json'], [], opts2, ' (jane-incomplete.json|JRS)' ],
[ 'validate', [sb + 'new-1.json', sb + 'new-jrs-resume.json', sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'], [], opts, ' (5|BOTH)' ],
[ 'analyze', [ft + 'jane-fullstacker.json'], [], opts, ' (jane-q-fullstacker|FRESH)' ],
[ 'analyze', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], [], opts2, ' (richard-hendriks|JRS)' ],
[ 'build', [ ft + 'jane-fullstacker.json', ft + 'override/jane-fullstacker-override.fresh.json' ], [ sb + 'merged/jane-fullstacker-gamedev.fresh.all'], opts, ' (jane-q-fullstacker w/ override|FRESH)' ],
[ '!build', [ ft + 'jane-fullstacker.json'], [ sb + 'shouldnt-exist.pdf' ], EXTEND(true, opts, { theme: 'awesome' }), ' (jane-q-fullstacker + Awesome + PDF|FRESH)' ]
].forEach( function(a) {
run.apply( /* The players of */ null, a );
});
function run( verb, src, dst, opts, msg ) {
msg = msg || '.';
var shouldSucceed = true;
if( verb[0] === '!' ) {
verb = verb.substr(1);
shouldSucceed = false;
}
it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () {
function runIt() {
try {
var v = new FCMD.verbs[verb]();
v.on('hmr:error', function(ex) {
throw ex;
});
v.invoke( src, dst, opts, opts.silent ?
function(){} : function(msg){ msg = msg || ''; console.log(msg); } );
}
catch(ex) {
console.error(ex);
console.error(ex.stack);
throw ex;
}
}
if( shouldSucceed )
runIt.should.not.Throw();
else
runIt.should.Throw();
});
}
});

View File

@ -1,44 +0,0 @@
var chai = require('chai')
, expect = chai.expect
, should = chai.should()
, path = require('path')
, parsePath = require('parse-filepath')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, JRSResume = require('../src/core/jrs-resume')
, CONVERTER = require('fresh-jrs-converter')
, FS = require('fs')
, MKDIRP = require('mkdirp')
, _ = require('underscore');
chai.config.includeStack = false;
describe('FRESH/JRS converter', function () {
var _sheet;
it('should round-trip from JRS to FRESH to JRS without modifying or losing data', function () {
var fileA = path.join( __dirname, 'resumes/jrs-0.0.0/richard-hendriks.json' );
var fileB = path.join( __dirname, 'sandbox/richard-hendriks.converted.fresh.json' );
var fileC = path.join( __dirname, 'sandbox/richard-hendriks.converted.jrs.json' );
_sheet = new JRSResume().open( fileA );
MKDIRP.sync( parsePath( fileB ).dirname );
_sheet.saveAs( fileB, 'FRESH' );
var freshSheet = new FRESHResume().open( fileB );
freshSheet.saveAs( fileC, 'JRS' );
var rawA = FS.readFileSync( fileA, 'utf8' );
var rawC = FS.readFileSync( fileC, 'utf8' );
var objA = JSON.parse( rawA );
var objC = JSON.parse( rawC );
_.isEqual(objA, objC).should.equal(true);
});
});

View File

@ -6,8 +6,8 @@
5|notacommand
3|build
14|build doesnt-exist.json
1|build doesnt-exist.json -t not-a-theme
1|build doesnt-exist.json -t node_modules/not-a-theme
14|build doesnt-exist.json -t not-a-theme
14|build doesnt-exist.json -t node_modules/not-a-theme
8|new
0|new test/sandbox/cli-test/new-empty-resume.auto.json
0|new test/sandbox/cli-test/new-empty-resume.jrs.json -f jrs

View File

@ -32,18 +32,16 @@ function genThemes( title, src, fmt ) {
format: fmt,
prettify: true,
silent: false,
css: 'embed'
css: 'embed',
debug: true
};
try {
var v = new HMR.verbs.build();
v.invoke( src, dst, opts, function(msg) {
msg = msg || '';
console.log(msg);
});
v.invoke( src, dst, opts );
}
catch(ex) {
console.log(ex);
console.log(ex.stack);
console.error( ex );
console.error( ex.stack );
throw ex;
}
}
@ -70,7 +68,7 @@ function folderContains( needle, haystack ) {
return _.some( READFILES( path.join(__dirname, haystack) ), function( absPath ) {
if( FS.lstatSync( absPath ).isFile() ) {
if( fileContains( absPath, needle ) ) {
console.log('Found invalid metadata in ' + absPath);
console.error('Found invalid metadata in ' + absPath);
return true;
}
}