1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-23 00:40:10 +00:00
HackMyResume/test/scripts/test-output.js

151 lines
4.2 KiB
JavaScript
Raw Permalink Normal View History

2016-01-14 19:22:26 +00:00
/**
CLI test routines for HackMyResume.
@module test-cli.js
2016-01-14 19:22:26 +00:00
*/
var chai = require('chai')
, should = chai.should()
, expect = chai.expect
, HMRMAIN = require('../../dist/cli/main')
, CHALK = require('chalk')
2016-01-09 11:44:47 +00:00
, FS = require('fs')
, PATH = require('path')
, PKG = require('../../package.json')
2016-01-26 15:58:10 +00:00
, STRIPCOLOR = require('stripcolorcodes')
, _ = require('underscore');
2016-01-14 19:22:26 +00:00
2016-01-09 11:44:47 +00:00
var gather = '';
var ConsoleLogOrg = console.log;
var ProcessExitOrg = process.exit;
var commandRetVal = 0;
// TODO: use sinon
// Replacement for process.exit()
function MyProcessExit( retVal ) {
commandRetVal = retVal;
}
// TODO: use sinon
// Replacement for console.log
function MyConsoleLog() {
var tx = Array.prototype.slice.call(arguments).join(' ');
gather += STRIPCOLOR( tx );
ConsoleLogOrg.apply(this, arguments);
}
2016-01-09 11:44:47 +00:00
describe('Testing Ouput interface', function () {
2016-01-09 11:44:47 +00:00
2016-01-14 19:22:26 +00:00
// HackMyResume CLI stub. Handle a single HMR invocation.
function HackMyResumeOutputStub( args ) {
2016-01-09 11:44:47 +00:00
console.log = MyConsoleLog;
process.exit = MyProcessExit;
CHALK.enabled = false;
try {
args.unshift( process.argv[1] );
args.unshift( process.argv[0] );
HMRMAIN( args );
}
catch( ex ) {
console.error(ex);
require('../../dist/cli/error').err( ex, false );
}
2016-01-09 11:44:47 +00:00
CHALK.enabled = true;
//process.exit = ProcessExitOrg;
2016-01-09 11:44:47 +00:00
console.log = ConsoleLogOrg;
}
2016-01-14 19:22:26 +00:00
// Run a test through the stub, gathering console.log output into "gather"
// and testing against it.
function run( title, args, tests ) {
it( title, function() {
2016-01-09 11:44:47 +00:00
gather = '';
HackMyResumeOutputStub( args );
2016-01-09 11:44:47 +00:00
expect(
_.all( tests, function(t) {
return gather.indexOf(t) > -1;
})
).to.equal(true);
2016-01-09 11:44:47 +00:00
});
}
var title = '*** HackMyResume v' + PKG.version + ' ***';
var feedMe = 'Please feed me a resume in FRESH or JSON Resume format.';
var manPage = FS.readFileSync( PATH.resolve( __dirname, '../../src/cli/use.txt' ), 'utf8');
run('HMR should output a help string when no command is specified',
2016-01-15 18:36:57 +00:00
[], [ title, 'Please give me a command (BUILD, ANALYZE, VALIDATE, CONVERT, NEW, or PEEK).' ]);
run('BUILD should output a tip when no source is specified',
['build'], [ title, feedMe ]);
2016-01-14 13:48:07 +00:00
run('VALIDATE should output a tip when no source is specified',
['validate'], [ title, feedMe ]);
run('ANALYZE should output a tip when no source is specified',
['analyze'], [ title, feedMe ]);
2016-01-14 13:48:07 +00:00
run('BUILD should display an error on a broken resume',
['build',
'node_modules/fresh-test-resumes/src/fresh/johnny-trouble.broken.json',
2016-01-14 19:22:26 +00:00
'-t', 'modern'
2016-01-14 13:48:07 +00:00
], [ title, 'Error: Invalid or corrupt JSON on line' ]);
run('CONVERT should output a tip when no source is specified',
['convert'], [ title, feedMe ]);
run('NEW should output a tip when no source is specified',
['new'], [ title, 'Please specify the filename of the resume to create.' ]);
2016-01-09 11:44:47 +00:00
// This will cause the HELP doc to be emitted, followed by an "unknown option --help"
// error in the log, based on the way we're calling into HMR. As long as the test
// passes, any extraneous error messages can be ignored here.
run('HMR should output help doc with --help',
['--help'], [ manPage ]);
run('HMR should accept raw JSON via --options',
[
'build',
'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json',
2016-01-12 02:15:28 +00:00
'to',
'test/sandbox/temp/janeq-1.all',
'-o',
"{ theme: 'compact', debug: true, pdf: 'wkhtmltopdf' }"],
2016-01-14 14:46:29 +00:00
[ 'Applying COMPACT theme (', '(with wkhtmltopdf)'] );
run('HMR should accept a JSON settings file via --options',
[
'build',
'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json',
2016-01-12 02:15:28 +00:00
'to',
'test/sandbox/temp/janeq-2.all',
'--options',
"test/scripts/hmr-options.json"],
[ 'Applying POSITIVE theme'] );
2016-01-12 02:15:28 +00:00
run('Explicit command line options should override --options',
[
'build',
'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json',
2016-01-12 02:15:28 +00:00
'to',
'test/sandbox/temp/janeq-3.all',
'--options',
"test/hmr-options.json",
"-t",
"modern"
],
[ 'Applying MODERN theme'] );
});