Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored options parsing to handle arbitrary options
- Loading branch information
Alexander Early
committed
Mar 16, 2015
1 parent
dc29955
commit f273622
Showing
4 changed files
with
82 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
var processOptions = require("../lib/process_options.js"); | ||
var expect = require("expect.js"); | ||
|
||
describe("processOptions", function () { | ||
var prevUser, prevKey; | ||
|
||
before(function () { | ||
prevUser = process.env.SAUCE_USERNAME; | ||
prevKey = process.env.SAUCE_ACCESS_KEY; | ||
delete process.env.SAUCE_USERNAME; | ||
delete process.env.SAUCE_ACCESS_KEY; | ||
}); | ||
|
||
after(function () { | ||
process.env.SAUCE_USERNAME = prevUser; | ||
process.env.SAUCE_ACCESS_KEY = prevKey; | ||
}); | ||
|
||
it("should process user and password", function () { | ||
var result = processOptions({username: "bermi", accessKey: "1234"}); | ||
expect(result).to.be.an(Array); | ||
expect(result).to.eql([ | ||
"-u", "bermi", | ||
"-k", "1234" | ||
]); | ||
}); | ||
|
||
it("should process user and password as env vars", function () { | ||
process.env.SAUCE_USERNAME = "bermi"; | ||
process.env.SAUCE_ACCESS_KEY = "1234"; | ||
var result = processOptions({}); | ||
expect(result).to.be.an(Array); | ||
expect(result).to.eql([ | ||
"-u", "bermi", | ||
"-k", "1234" | ||
]); | ||
delete process.env.SAUCE_USERNAME; | ||
delete process.env.SAUCE_ACCESS_KEY; | ||
}); | ||
|
||
it("should handle proxy ports", function () { | ||
expect(processOptions({port: 1234})).to.eql(["-P", 1234]); | ||
}); | ||
|
||
it("should handle boolean flags", function () { | ||
var result = processOptions({doctor: true}); | ||
expect(result).to.eql(["--doctor"]); | ||
}); | ||
|
||
it("should handle array values", function () { | ||
var result = processOptions({directDomains: ["google.com", "asdf.com"]}); | ||
expect(result).to.eql(["--direct-domains", "google.com,asdf.com"]); | ||
}); | ||
|
||
it("should handle future options", function () { | ||
var result = processOptions({ | ||
someFutureOption: "asdf", | ||
futureBoolean: true | ||
}); | ||
expect(result).to.eql(["--some-future-option", "asdf", "--future-boolean"]); | ||
}); | ||
|
||
it("should omit special launcher flags", function () { | ||
expect(processOptions({ | ||
readyFileId: "1", | ||
verbose: true, | ||
logger: function () {} | ||
})).to.eql([]); | ||
}); | ||
|
||
}); |