-
Notifications
You must be signed in to change notification settings - Fork 64
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
1 parent
189c8d2
commit f0313d4
Showing
5 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Testplane } from "../../../testplane"; | ||
import { CliCommands } from "../../constants"; | ||
import logger from "../../../utils/logger"; | ||
|
||
const { CONFIG: commandName } = CliCommands; | ||
|
||
export const registerCmd = (cliTool: typeof commander, testplane: Testplane): void => { | ||
cliTool | ||
.command(commandName) | ||
.description("Lists all browsers from the config") | ||
.option("-c, --config <path>", "path to configuration file") | ||
.option("--space <count>", "white spaces count to insert into the JSON output", Number, 0) | ||
.action(async (options: typeof commander) => { | ||
const { space } = options; | ||
|
||
try { | ||
console.info(JSON.stringify(testplane.config, null, space)); | ||
|
||
process.exit(0); | ||
} catch (err) { | ||
logger.error((err as Error).stack || err); | ||
process.exit(1); | ||
} | ||
}); | ||
}; |
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,55 @@ | ||
import { Command } from "@gemini-testing/commander"; | ||
import sinon, { SinonStub, SinonSpy } from "sinon"; | ||
|
||
import { Testplane } from "../../../../../src/testplane"; | ||
import * as testplaneCli from "../../../../../src/cli"; | ||
|
||
describe("cli/commands/config", () => { | ||
const sandbox = sinon.createSandbox(); | ||
|
||
let testplaneStub: Testplane; | ||
let consoleInfoStub: SinonStub; | ||
let jsonStringifyStub: SinonSpy; | ||
|
||
const config_ = async (options: string[] = [], cli: { run: VoidFunction } = testplaneCli): Promise<void> => { | ||
process.argv = ["foo/bar/node", "foo/bar/script", "config", ...options]; | ||
cli.run(); | ||
|
||
await (Command.prototype.action as SinonStub).lastCall.returnValue; | ||
}; | ||
|
||
beforeEach(() => { | ||
testplaneStub = Object.create(Testplane.prototype); | ||
|
||
sandbox.stub(Testplane, "create").returns(testplaneStub); | ||
|
||
consoleInfoStub = sandbox.stub(console, "info"); | ||
jsonStringifyStub = sandbox.spy(JSON, "stringify"); | ||
|
||
sandbox.stub(process, "exit"); | ||
|
||
sandbox.spy(Command.prototype, "action"); | ||
}); | ||
|
||
afterEach(() => sandbox.restore()); | ||
|
||
it("should exit with code 0", async () => { | ||
await config_(); | ||
|
||
assert.calledOnceWith(process.exit as unknown as SinonStub, 0); | ||
}); | ||
|
||
it("should output testplane config", async () => { | ||
await config_(); | ||
|
||
assert.calledWith(jsonStringifyStub, testplaneStub.config, null, 0); | ||
assert.calledOnceWith(consoleInfoStub, JSON.stringify(testplaneStub.config, null, 0)); | ||
}); | ||
|
||
it("should output testplane config with spacing", async () => { | ||
await config_(["--space", "4"]); | ||
|
||
assert.calledWith(jsonStringifyStub, testplaneStub.config, null, 4); | ||
assert.calledOnceWith(consoleInfoStub, JSON.stringify(testplaneStub.config, null, 4)); | ||
}); | ||
}); |