2016-01-14 19:22:26 +00:00
|
|
|
/**
|
2016-02-11 17:08:11 +00:00
|
|
|
Output test routines for HackMyResume. Make sure our outputs are consistent.
|
|
|
|
@module test-output.js
|
|
|
|
@license MIT. See LICENSE.md for details.
|
2016-01-14 19:22:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
var chai = require('chai')
|
2016-01-29 20:23:57 +00:00
|
|
|
, should = chai.should()
|
2016-01-09 10:29:45 +00:00
|
|
|
, expect = chai.expect
|
2018-02-14 15:13:48 +00:00
|
|
|
, HMRMAIN = require('../../src/cli/main')
|
2016-01-09 10:29:45 +00:00
|
|
|
, CHALK = require('chalk')
|
2016-01-09 11:44:47 +00:00
|
|
|
, FS = require('fs')
|
|
|
|
, PATH = require('path')
|
2016-01-29 20:23:57 +00:00
|
|
|
, PKG = require('../../package.json')
|
2016-01-26 15:58:10 +00:00
|
|
|
, STRIPCOLOR = require('stripcolorcodes')
|
2016-01-09 10:29:45 +00:00
|
|
|
, _ = 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;
|
2016-01-29 20:23:57 +00:00
|
|
|
var commandRetVal = 0;
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
// TODO: use sinon
|
|
|
|
// Replacement for process.exit()
|
|
|
|
function MyProcessExit( retVal ) {
|
|
|
|
commandRetVal = retVal;
|
|
|
|
}
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
// 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
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
describe('Testing Ouput interface', function () {
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2018-01-30 18:04:08 +00:00
|
|
|
this.timeout(50000);
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-14 19:22:26 +00:00
|
|
|
// HackMyResume CLI stub. Handle a single HMR invocation.
|
2016-01-29 20:23:57 +00:00
|
|
|
function HackMyResumeOutputStub( args ) {
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2016-01-09 11:44:47 +00:00
|
|
|
console.log = MyConsoleLog;
|
|
|
|
process.exit = MyProcessExit;
|
|
|
|
CHALK.enabled = false;
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
try {
|
|
|
|
args.unshift( process.argv[1] );
|
|
|
|
args.unshift( process.argv[0] );
|
|
|
|
HMRMAIN( args );
|
|
|
|
}
|
|
|
|
catch( ex ) {
|
2016-01-29 20:23:57 +00:00
|
|
|
console.error(ex);
|
2018-02-14 15:13:48 +00:00
|
|
|
require('../../src/cli/error').err( ex, false );
|
2016-01-09 10:29:45 +00:00
|
|
|
}
|
2016-01-09 11:44:47 +00:00
|
|
|
CHALK.enabled = true;
|
2016-01-29 20:23:57 +00:00
|
|
|
//process.exit = ProcessExitOrg;
|
2016-01-09 11:44:47 +00:00
|
|
|
console.log = ConsoleLogOrg;
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 19:22:26 +00:00
|
|
|
// Run a test through the stub, gathering console.log output into "gather"
|
|
|
|
// and testing against it.
|
2016-01-09 10:29:45 +00:00
|
|
|
function run( title, args, tests ) {
|
|
|
|
it( title, function() {
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
gather = '';
|
2016-01-29 20:23:57 +00:00
|
|
|
HackMyResumeOutputStub( args );
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
expect(
|
|
|
|
_.all( tests, function(t) {
|
|
|
|
return gather.indexOf(t) > -1;
|
|
|
|
})
|
|
|
|
).to.equal(true);
|
2016-01-09 11:44:47 +00:00
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-10 01:29:30 +00:00
|
|
|
var title = '*** HackMyResume v' + PKG.version + ' ***';
|
2016-01-09 10:29:45 +00:00
|
|
|
var feedMe = 'Please feed me a resume in FRESH or JSON Resume format.';
|
2018-02-11 13:13:13 +00:00
|
|
|
var manPage = FS.readFileSync( PATH.resolve( __dirname, '../../src/cli/help/use.txt' ), 'utf8').replace(/\*\*/g, '');
|
|
|
|
var manPages = { };
|
|
|
|
['build','new','convert','analyze','validate','peek'].forEach( function(verb) {
|
|
|
|
manPages[verb] = FS.readFileSync( PATH.resolve( __dirname, '../../src/cli/help/' + verb + '.txt' ), 'utf8').replace(/\*\*/g, '');
|
|
|
|
});
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2018-02-11 13:13:13 +00:00
|
|
|
// run('HMR should output a help string when no command is specified',
|
|
|
|
// [], [ title, 'Please give me a command (BUILD, ANALYZE, VALIDATE, CONVERT, NEW, or PEEK).' ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2018-02-11 13:13:13 +00:00
|
|
|
run('BUILD should output a help message when no source is specified',
|
|
|
|
['build'], [ title, manPages.build ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2018-02-11 13:13:13 +00:00
|
|
|
run('VALIDATE should output a help message when no source is specified',
|
|
|
|
['validate'], [ title, manPages.validate ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2018-02-11 13:13:13 +00:00
|
|
|
run('ANALYZE should output a help message when no source is specified',
|
|
|
|
['analyze'], [ title, manPages.analyze ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2016-01-14 13:48:07 +00:00
|
|
|
run('BUILD should display an error on a broken resume',
|
|
|
|
['build',
|
2016-01-16 21:29:00 +00:00
|
|
|
'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' ]);
|
|
|
|
|
2018-02-11 13:13:13 +00:00
|
|
|
run('CONVERT should output a help message when no source is specified',
|
|
|
|
['convert'], [ title, manPages.convert ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2018-02-11 13:13:13 +00:00
|
|
|
run('NEW should output a help message when no source is specified',
|
|
|
|
['new'], [ title, manPages.new ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
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 ]);
|
2016-01-09 10:29:45 +00:00
|
|
|
|
2016-01-12 01:52:17 +00:00
|
|
|
run('HMR should accept raw JSON via --options',
|
|
|
|
[
|
|
|
|
'build',
|
2016-01-16 21:29:00 +00:00
|
|
|
'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',
|
2016-01-12 01:52:17 +00:00
|
|
|
'-o',
|
|
|
|
"{ theme: 'compact', debug: true, pdf: 'wkhtmltopdf' }"],
|
2016-01-14 14:46:29 +00:00
|
|
|
[ 'Applying COMPACT theme (', '(with wkhtmltopdf)'] );
|
2016-01-12 01:52:17 +00:00
|
|
|
|
|
|
|
run('HMR should accept a JSON settings file via --options',
|
|
|
|
[
|
|
|
|
'build',
|
2016-01-16 21:29:00 +00:00
|
|
|
'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',
|
2016-01-12 01:52:17 +00:00
|
|
|
'--options',
|
2016-01-29 20:23:57 +00:00
|
|
|
"test/scripts/hmr-options.json"],
|
2016-01-12 01:52:17 +00:00
|
|
|
[ 'Applying POSITIVE theme'] );
|
2016-01-12 02:15:28 +00:00
|
|
|
|
|
|
|
run('Explicit command line options should override --options',
|
|
|
|
[
|
|
|
|
'build',
|
2016-01-16 21:29:00 +00:00
|
|
|
'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',
|
2018-01-29 07:04:00 +00:00
|
|
|
"test/scripts/hmr-options.json",
|
2016-01-12 02:15:28 +00:00
|
|
|
"-t",
|
|
|
|
"modern"
|
|
|
|
],
|
|
|
|
[ 'Applying MODERN theme'] );
|
2018-01-29 07:04:00 +00:00
|
|
|
|
|
|
|
run('HMR should detect a missing or inaccessible options file',
|
|
|
|
[
|
|
|
|
'build',
|
|
|
|
'doesntmatter.json',
|
|
|
|
'to',
|
|
|
|
'dontcare.all',
|
|
|
|
'--options',
|
|
|
|
"test/scripts/hmr-options-nonexistent.json",
|
|
|
|
"-t",
|
|
|
|
"modern"
|
|
|
|
],
|
|
|
|
[ 'The specified options file is missing or inaccessible'] );
|
|
|
|
|
|
|
|
run('HMR should detect an invalid or malformed options file',
|
|
|
|
[
|
|
|
|
'build',
|
|
|
|
'doesntmatter.json',
|
|
|
|
'to',
|
|
|
|
'dontcare.all',
|
|
|
|
'--options',
|
|
|
|
"test/scripts/hmr-options-broken.json",
|
|
|
|
"-t",
|
|
|
|
"modern"
|
|
|
|
],
|
|
|
|
[ 'The specified options file is invalid'] );
|
|
|
|
|
2016-01-09 10:29:45 +00:00
|
|
|
});
|