Skip to content

Commit

Permalink
use commander to parse script arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Feb 10, 2020
1 parent 7db444f commit 71179eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
35 changes: 27 additions & 8 deletions scripts/test_hardening.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@
*/

var execFileSync = require('child_process').execFileSync;
var basename = require('path').basename;
var readdirSync = require('fs').readdirSync;
var path = require('path');
var glob = require('glob');
var program = require('commander');

process.argv.slice(2).forEach(function(file) {
var files = glob.sync(file);
files.forEach(function(file) {
if (basename(file)[0] === '_') return;
console.log(process.argv[0], file);
execFileSync(process.argv[0], [file], { stdio: 'inherit' });
program
.name('node scripts/test_hardening.js')
.arguments('[file...]')
.description(
'Run the tests in test/harden directory. If no files are provided, all files within the directory will be run.'
)
.action(function(files) {
if (files.length === 0) files = allFiles();
files.forEach(function(file) {
var files = glob.sync(file);
files.forEach(function(file) {
if (path.basename(file)[0] === '_') return;
console.log(process.argv[0], file);
execFileSync(process.argv[0], [file], { stdio: 'inherit' });
});
});
})
.parse(process.argv);

function allFiles() {
var dir = path.join('test', 'harden');
return readdirSync(dir).map(function(file) {
return path.join(dir, file);
});
});
}
2 changes: 1 addition & 1 deletion tasks/config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ module.exports = function(grunt) {
test_hardening: scriptWithGithubChecks({
title: 'Node.js hardening tests',
cmd: NODE,
args: ['scripts/test_hardening.js', 'test/harden/*.js'],
args: ['scripts/test_hardening.js'],
}),

apiIntegrationTests: scriptWithGithubChecks({
Expand Down

0 comments on commit 71179eb

Please sign in to comment.