1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-16 13:50:10 +00:00
HackMyResume/test/scripts/test-themes.js

145 lines
4.1 KiB
JavaScript
Raw Normal View History

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.
*/
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')
, fileContains = require('../../dist/utils/file-contains')
2018-01-29 03:34:05 +00:00
, dirCompare = require('dir-compare');
2018-01-29 03:34:05 +00:00
// Include stack traces for failed tests.
chai.config.includeStack = true;
2018-01-29 03:34:05 +00:00
/**
Test the specified resume against multiple themes.
*/
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 () {
2018-01-29 03:34:05 +00:00
// Increase the timeout since resume generation can be expensive..
this.timeout(50000);
2018-01-29 03:34:05 +00:00
// Define a local function to build a single resume to MULTIPLE themes
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
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) { },
);
});
}
2018-01-29 03:34:05 +00:00
// Build the resume for each theme
//genTheme(fmt, src, 'hello-world');
genTheme(fmt, src, 'compact');
genTheme(fmt, src, 'modern');
2018-01-29 03:34:05 +00:00
//genTheme(fmt, src, 'underscore');
//genTheme(fmt, src, 'awesome');
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' );
});
}
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() ) {
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',
['node_modules/fresh-test-resumes/src/jrs/richard-hendriks.json'],
2018-01-29 03:34:05 +00:00
'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);
// });
//
// });