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')
|
2018-02-14 15:13:48 +00:00
|
|
|
, HackMyResume = require( '../../src/index')
|
2018-01-29 03:34:05 +00:00
|
|
|
, readFolder = require('recursive-readdir-sync')
|
2018-02-14 15:13:48 +00:00
|
|
|
, fileContains = require('../../src/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..
|
2018-01-30 18:04:08 +00:00
|
|
|
this.timeout(50000);
|
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) {
|
2018-02-04 09:06:49 +00:00
|
|
|
console.error('Error thrown: %o', ex);
|
|
|
|
throw ex;
|
|
|
|
//assert(false);
|
2018-01-29 03:34:05 +00:00
|
|
|
});
|
|
|
|
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-02-04 10:34:47 +00:00
|
|
|
genTheme(fmt, src, 'underscore', 'node_modules/fresh-theme-underscore' );
|
2018-02-05 04:35:42 +00:00
|
|
|
genTheme(fmt, src, 'awesome');
|
2016-01-29 20:23:57 +00:00
|
|
|
genTheme(fmt, src, 'positive');
|
2018-02-05 04:35:42 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
genTheme(fmt, src, 'jsonresume-theme-boilerplate',
|
2018-02-05 04:35:42 +00:00
|
|
|
'node_modules/jsonresume-theme-boilerplate' );
|
2018-01-29 03:34:05 +00:00
|
|
|
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-02-05 05:06:14 +00:00
|
|
|
var ignoreExts = ['.png','.jpg','.jpeg','.bmp','.pdf', '.gif'];
|
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() ) {
|
2018-02-05 05:06:14 +00:00
|
|
|
var pathInfo = path.parse( absPath );
|
|
|
|
if( !_.contains(ignoreExts, pathInfo.ext) &&
|
|
|
|
fileContains(absPath, needle) ) {
|
2016-01-29 20:23:57 +00:00
|
|
|
console.error('Found invalid metadata in ' + absPath);
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-05 05:06:14 +00:00
|
|
|
return false;
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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',
|
2018-02-01 10:58:35 +00:00
|
|
|
['node_modules/fresh-test-resumes/src/jrs/richard-hendriks.json'],
|
2018-01-29 03:34:05 +00:00
|
|
|
'JRS'
|
|
|
|
);
|
|
|
|
|
2018-02-05 04:35:42 +00:00
|
|
|
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);
|
|
|
|
// });
|
|
|
|
|
|
|
|
});
|