Skip to content

Commit

Permalink
WIP resolves tj#649 switch to a modern test infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jan 22, 2018
1 parent e5d8f04 commit c9f9b07
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"url": "https://github.com/tj/commander.js.git"
},
"scripts": {
"ava": "ava test-ava",
"test": "make test && npm run test-typings",
"test-typings": "node_modules/typescript/bin/tsc -p tsconfig.json"
},
Expand All @@ -25,6 +26,7 @@
],
"dependencies": {},
"devDependencies": {
"ava": "^0.24.0",
"@types/node": "^7.0.48",
"should": "^11.2.1",
"sinon": "^2.4.1",
Expand Down
36 changes: 36 additions & 0 deletions test-ava/arguments.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// converted from test/test.arguments.js
var Command = require('../').Command
, test = require('ava');

function createProgram(capture) {
var program = new Command();
program
.version('0.0.1')
.arguments('<cmd> [env]')
.action(function (cmd, env) {
capture.cmdValue = cmd;
capture.envValue = env;
})
.option('-C, --chdir <path>', 'change the working directory')
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
.option('-T, --no-tests', 'ignore test hook');
return program;
}

test('option', (t) => {
var capture = {};
var program = createProgram(capture);
program.parse(['node', 'test', '--config', 'conf']);
t.is(program.config, 'conf');
t.is(capture.cmdValue, undefined);
t.is(capture.envValue, undefined);
})

test('option and command', (t) => {
var capture = {};
var program = createProgram(capture);
program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode3', 'env1']);
t.is(program.config, 'conf1');
t.is(capture.cmdValue, 'setup');
t.is(capture.envValue, 'env1');
})
18 changes: 18 additions & 0 deletions test-ava/command/action.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// converted from test/test.command.action.js
var Command = require('../../').Command
, test = require('ava');

test('command action', (t) => {
var val;
var program = new Command();
program
.command('info [options]')
.option('-C, --no-color', 'turn off color output')
.action(function () {
val = this.color;
});
program.parse(['node', 'test', 'info', '-C']);
t.is(program.commands.length, 1);
t.false(program.commands[0].color);
t.false(val);
})

0 comments on commit c9f9b07

Please sign in to comment.