mirror of
https://github.com/SrIzan10/nodemon.git
synced 2026-05-01 10:55:09 +00:00
Test help
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
utils = require('../utils');
|
||||
path = require('path');
|
||||
|
||||
module.exports = help;
|
||||
|
||||
@@ -8,14 +7,17 @@ function help(item) {
|
||||
if (!item) {
|
||||
item = 'help';
|
||||
} else if (item === true) { // if used with -h or --help and no args
|
||||
item = 'help'
|
||||
item = 'help';
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt'), 'utf8', function (err, body) {
|
||||
if (err) {
|
||||
return utils.log.error(item + ' help can\'t be found');
|
||||
}
|
||||
console.log(body);
|
||||
process.exit(0);
|
||||
});
|
||||
// cleanse the filename to only contain letters
|
||||
// aka: /\W/g but figured this was eaiser to read
|
||||
item = item.replace(/[^a-z]/gi, '');
|
||||
|
||||
try {
|
||||
var body = fs.readFileSync(path.join(__dirname, '..', '..', 'doc', 'cli', item + '.txt'), 'utf8');
|
||||
return body;
|
||||
} catch (e) {
|
||||
return '"' + item + '" help can\'t be found';
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,8 @@ function nodemon(settings) {
|
||||
}
|
||||
|
||||
if (settings.help) {
|
||||
return help(settings.help);
|
||||
console.log(help(settings.help));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (settings.version) {
|
||||
|
||||
1
test/fixtures/help.txt
vendored
Normal file
1
test/fixtures/help.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
This file should not be read.
|
||||
20
test/help/help.test.js
Normal file
20
test/help/help.test.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/*global describe:true, it: true */
|
||||
var help = require('../../lib/help'),
|
||||
assert = require('assert');
|
||||
|
||||
describe('help', function () {
|
||||
it('should load index by default', function () {
|
||||
var page = help();
|
||||
assert(page.indexOf('Usage: nodemon') !== -1, 'shows default help page');
|
||||
});
|
||||
|
||||
it('should load specific help topic', function () {
|
||||
var page = help('authors');
|
||||
assert(page.indexOf('Remy Sharp') !== -1, 'shows specific topic');
|
||||
});
|
||||
|
||||
it('should not expose files', function () {
|
||||
var page = help('../../test/fixtures/help');
|
||||
assert(page.indexOf('" help can\'t be found') !== -1, 'shows help cannot be found');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user