-
-
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.
* Add "from" parameter to .parse() * Add docs for ParseOptions * Add .parse options to README * Lint, whitespace * Fill in parseAsync docs
- Loading branch information
1 parent
fbdd132
commit 30ae4ac
Showing
5 changed files
with
177 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const commander = require('../'); | ||
|
||
// Testing some Electron conventions but not directly using Electron to avoid overheads. | ||
// https://github.com/electron/electron/issues/4690#issuecomment-217435222 | ||
// https://www.electronjs.org/docs/api/process#processdefaultapp-readonly | ||
|
||
describe('.parse() user args', () => { | ||
test('when no args then use process.argv and app/script/args', () => { | ||
const program = new commander.Command(); | ||
const hold = process.argv; | ||
process.argv = 'node script.js user'.split(' '); | ||
program.parse(); | ||
process.argv = hold; | ||
expect(program.args).toEqual(['user']); | ||
}); | ||
|
||
// implicit also supports detecting electron but more implementation knowledge required than useful to test | ||
|
||
test('when args then app/script/args', () => { | ||
const program = new commander.Command(); | ||
program.parse('node script.js user'.split(' ')); | ||
expect(program.args).toEqual(['user']); | ||
}); | ||
|
||
test('when args from "node" then app/script/args', () => { | ||
const program = new commander.Command(); | ||
program.parse('node script.js user'.split(' '), { from: 'node' }); | ||
expect(program.args).toEqual(['user']); | ||
}); | ||
|
||
test('when args from "electron" and not default app then app/args', () => { | ||
const program = new commander.Command(); | ||
const hold = process.defaultApp; | ||
process.defaultApp = undefined; | ||
program.parse('customApp user'.split(' '), { from: 'electron' }); | ||
process.defaultApp = hold; | ||
expect(program.args).toEqual(['user']); | ||
}); | ||
|
||
test('when args from "electron" and default app then app/script/args', () => { | ||
const program = new commander.Command(); | ||
const hold = process.defaultApp; | ||
process.defaultApp = true; | ||
program.parse('electron script user'.split(' '), { from: 'electron' }); | ||
process.defaultApp = hold; | ||
expect(program.args).toEqual(['user']); | ||
}); | ||
|
||
test('when args from "user" then args', () => { | ||
const program = new commander.Command(); | ||
program.parse('user'.split(' '), { from: 'user' }); | ||
expect(program.args).toEqual(['user']); | ||
}); | ||
}); |
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