2016-02-11 17:08:11 +00:00
|
|
|
/**
|
|
|
|
Theme test routines for HackMyResume. Test all preinstalled HackMyResume themes
|
|
|
|
along with a handful of JSON Resume themes for good measure. Uses the HMR verb
|
|
|
|
interface.
|
|
|
|
@module test-themes.js
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
var chai = require('chai')
|
|
|
|
, expect = chai.expect
|
|
|
|
, should = chai.should()
|
|
|
|
, path = require('path')
|
|
|
|
, _ = require('underscore')
|
|
|
|
, HackMyResume = require( '../../dist/index')
|
|
|
|
, readFolder = require('recursive-readdir-sync')
|
2016-01-29 20:23:57 +00:00
|
|
|
, fileContains = require('../../dist/utils/file-contains')
|
2018-01-29 03:34:05 +00:00
|
|
|
, dirCompare = require('dir-compare');
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Include stack traces for failed tests.
|
2016-01-29 20:23:57 +00:00
|
|
|
chai.config.includeStack = true;
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
/**
|
|
|
|
Test the specified resume against multiple themes.
|
|
|
|
*/
|
2016-01-29 20:23:57 +00:00
|
|
|
function genThemes( title, src, fmt ) {
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Set up a new suite
|
|
|
|
describe('Testing themes against ' + title.toUpperCase()
|
|
|
|
+ ' resume ' + '(' + fmt + ')' , function () {
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Increase the timeout since resume generation can be expensive..
|
2016-02-14 01:42:03 +00:00
|
|
|
this.timeout(30000);
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Define a local function to build a single resume to MULTIPLE themes
|
2016-01-29 20:23:57 +00:00
|
|
|
function genTheme( fmt, src, themeName, themeLoc, testTitle ) {
|
|
|
|
themeLoc = themeLoc || themeName;
|
2018-01-29 03:34:05 +00:00
|
|
|
testTitle = themeName.toUpperCase() + ' theme (' + fmt +
|
|
|
|
') should generate without throwing an exception';
|
|
|
|
|
|
|
|
// Instantiate a test case
|
2016-01-29 20:23:57 +00:00
|
|
|
it( testTitle, function () {
|
2018-01-29 03:34:05 +00:00
|
|
|
|
|
|
|
// Set up options
|
|
|
|
var dst = ['test/sandbox/' + fmt + '/' + title + '/' +
|
|
|
|
themeName + '/resume.all'];
|
|
|
|
var opts = {
|
|
|
|
theme: themeLoc,
|
|
|
|
format: fmt,
|
|
|
|
prettify: true,
|
|
|
|
silent: false,
|
|
|
|
css: 'embed',
|
|
|
|
debug: true
|
|
|
|
};
|
|
|
|
|
|
|
|
// Run the command!
|
|
|
|
var v = new HackMyResume.verbs.build();
|
|
|
|
v.on('hmr:error', function(ex) {
|
|
|
|
console.log('Error thrown');
|
|
|
|
assert(false);
|
|
|
|
});
|
|
|
|
var p = v.invoke( src, dst, opts );
|
|
|
|
|
|
|
|
// Let Mocha sort out the promise result
|
|
|
|
return p.then(
|
|
|
|
function(obj) { }
|
|
|
|
//,function(obj) { },
|
|
|
|
);
|
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Build the resume for each theme
|
|
|
|
//genTheme(fmt, src, 'hello-world');
|
2016-01-29 20:23:57 +00:00
|
|
|
genTheme(fmt, src, 'compact');
|
|
|
|
genTheme(fmt, src, 'modern');
|
2018-01-29 03:34:05 +00:00
|
|
|
//genTheme(fmt, src, 'underscore');
|
|
|
|
//genTheme(fmt, src, 'awesome');
|
2016-01-29 20:23:57 +00:00
|
|
|
genTheme(fmt, src, 'positive');
|
2018-01-29 03:34:05 +00:00
|
|
|
genTheme(fmt, src, 'jsonresume-theme-boilerplate',
|
|
|
|
'node_modules/jsonresume-theme-boilerplate' );
|
|
|
|
genTheme(fmt, src, 'jsonresume-theme-sceptile',
|
|
|
|
'node_modules/jsonresume-theme-sceptile' );
|
|
|
|
genTheme(fmt, src, 'jsonresume-theme-modern',
|
|
|
|
'node_modules/jsonresume-theme-modern' );
|
|
|
|
genTheme(fmt, src, 'jsonresume-theme-classy',
|
|
|
|
'node_modules/jsonresume-theme-classy' );
|
2016-01-29 20:23:57 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function folderContains( needle, haystack ) {
|
2018-01-29 03:34:05 +00:00
|
|
|
var safePath = path.normalize( path.join(__dirname, haystack));
|
|
|
|
return _.some( readFolder( safePath ), function( absPath ) {
|
|
|
|
if( require('fs').lstatSync( absPath ).isFile() ) {
|
2016-01-29 20:23:57 +00:00
|
|
|
if( fileContains( absPath, needle ) ) {
|
|
|
|
console.error('Found invalid metadata in ' + absPath);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-13 21:08:45 +00:00
|
|
|
function foldersMatch( a, b ) {
|
|
|
|
var ret;
|
2018-01-29 03:34:05 +00:00
|
|
|
ret = dirCompare.compareSync(a, b, {compareSize: true, skipSubdirs: true});
|
2016-02-13 21:08:45 +00:00
|
|
|
if( !ret.same ) return false;
|
2018-01-29 03:34:05 +00:00
|
|
|
ret = dirCompare.compareSync(a, b, {compareContent: true, skipSubdirs: true});
|
2016-02-13 21:08:45 +00:00
|
|
|
return ret.differences === 1;
|
|
|
|
}
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
genThemes(
|
|
|
|
'jane-q-fullstacker',
|
|
|
|
['node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json'],
|
|
|
|
'FRESH'
|
|
|
|
);
|
|
|
|
|
|
|
|
genThemes(
|
|
|
|
'johnny-trouble',
|
|
|
|
['node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json'],
|
|
|
|
'FRESH'
|
|
|
|
);
|
|
|
|
|
|
|
|
genThemes(
|
|
|
|
'richard-hendriks',
|
|
|
|
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
|
|
|
|
'JRS'
|
|
|
|
);
|
|
|
|
|
|
|
|
// describe('Verifying generated theme files...', function() {
|
|
|
|
//
|
|
|
|
// it('Generated files should not contain ICE.', function() {
|
|
|
|
// var q = folderContains('@@@@', '../sandbox');
|
|
|
|
// q.should.equal(false);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('Generated files should match exemplars...', function() {
|
|
|
|
// var q = foldersMatch( 'test/sandbox/FRESH/jane-q-fullstacker/modern',
|
|
|
|
// 'test/expected/modern' );
|
|
|
|
// q.should.equal(true);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// });
|