-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
105 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
console.log('default'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var util = require('util'); | ||
var program = require('../') | ||
, should = require('should'); | ||
, sinon = require('sinon').sandbox.create() | ||
, should = require('should'); | ||
|
||
var oldProcessExit = process.exit; | ||
var oldConsoleError = console.error; | ||
var stubError = sinon.stub(console, 'error'); | ||
var stubExit = sinon.stub(process, 'exit'); | ||
|
||
program | ||
.version('0.0.1') | ||
.option('-p, --pepper', 'add pepper'); | ||
program.parse('node test -m'.split(' ')); | ||
|
||
var consoleErrors = []; | ||
process.exit = function () { | ||
}; | ||
console.error = function () { | ||
consoleErrors.push(util.format.apply(util, arguments)); | ||
}; | ||
stubError.callCount.should.equal(3); | ||
|
||
program.parse('node test -m'.split(' ')); | ||
consoleErrors.length.should.equal(3); | ||
|
||
// test subcommand | ||
var consoleErrors = []; | ||
resetStubStatus(); | ||
program | ||
.command('sub') | ||
.action(function () { | ||
}); | ||
program.parse('node test sub -m'.split(' ')); | ||
consoleErrors.length.should.equal(3); | ||
|
||
consoleErrors = []; | ||
stubError.callCount.should.equal(3); | ||
stubExit.calledOnce.should.be.true(); | ||
|
||
// command with `allowUnknownOption` | ||
resetStubStatus(); | ||
program | ||
.version('0.0.1') | ||
.option('-p, --pepper', 'add pepper'); | ||
|
||
program | ||
.allowUnknownOption() | ||
.parse('node test -m'.split(' ')); | ||
consoleErrors.length.should.equal(0); | ||
|
||
// test subcommand | ||
var consoleErrors = []; | ||
stubError.callCount.should.equal(0); | ||
stubExit.calledOnce.should.be.false(); | ||
|
||
// subcommand with `allowUnknownOption` | ||
resetStubStatus(); | ||
program | ||
.command('sub') | ||
.command('sub2') | ||
.allowUnknownOption() | ||
.action(function () { | ||
}); | ||
program.parse('node test sub -m'.split(' ')); | ||
consoleErrors.length.should.equal(3); | ||
program.parse('node test sub2 -m'.split(' ')); | ||
|
||
stubError.callCount.should.equal(0); | ||
stubExit.calledOnce.should.be.false(); | ||
|
||
process.exit = oldProcessExit; | ||
console.error = oldConsoleError; | ||
|
||
function resetStubStatus() { | ||
stubError.reset(); | ||
stubExit.reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var exec = require('child_process').exec | ||
, path = require('path') | ||
, should = require('should'); | ||
|
||
|
||
|
||
var bin = path.join(__dirname, './fixtures/pm') | ||
// success case | ||
exec(bin + ' default', function(error, stdout, stderr) { | ||
stdout.should.equal('default\n'); | ||
}); | ||
|
||
// success case (default) | ||
exec(bin, function(error, stdout, stderr) { | ||
stdout.should.equal('default\n'); | ||
}); | ||
|
||
// not exist | ||
exec(bin + ' list', function (error, stdout, stderr) { | ||
//stderr.should.equal('\n pm-list(1) does not exist, try --help\n\n'); | ||
// TODO error info are not the same in between <=v0.8 and later version | ||
should.notEqual(0, stderr.length); | ||
}); | ||
|
||
// success case | ||
exec(bin + ' install', function (error, stdout, stderr) { | ||
stdout.should.equal('install\n'); | ||
}); | ||
|
||
// subcommand bin file with explicit extension | ||
exec(bin + ' publish', function (error, stdout, stderr) { | ||
stdout.should.equal('publish\n'); | ||
}); | ||
|
||
// spawn EACCES | ||
exec(bin + ' search', function (error, stdout, stderr) { | ||
// TODO error info are not the same in between <v0.10 and v0.12 | ||
should.notEqual(0, stderr.length); | ||
}); | ||
|
||
// when `bin` is a symbol link for mocking global install | ||
var bin = path.join(__dirname, './fixtures/pmlink') | ||
// success case | ||
exec(bin + ' install', function (error, stdout, stderr) { | ||
stdout.should.equal('install\n'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters