Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 'config' command #1053

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/cli/commands/config/index.ts
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("Outputs Testplane config (including default and overriden by environment variables values)")
.option("-c, --config <path>", "path to configuration file")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for config command you can pass the configuration file as an argument rather than as an option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can't

.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);
}
});
};
1 change: 1 addition & 0 deletions src/cli/commands/install-deps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const registerCmd = (cliTool: typeof commander, testplane: Testplane): vo
cliTool
.command(commandName)
.description("Install browsers to run locally with 'gridUrl': 'local' or '--local' cli argument")
.option("-c, --config <path>", "path to configuration file")
.arguments("[browsers...]")
.action(async (browsers: string[]) => {
try {
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/list-browsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const registerCmd = (cliTool: typeof commander, testplane: Testplane): vo
cliTool
.command(commandName)
.description("Lists all browsers from the config")
.option("-c, --config <path>", "path to configuration file")
.option(
"--type [type]",
"return browsers in specified type ('tags': browserName and browserVersion, 'ids': browserId from config)",
Expand Down
1 change: 1 addition & 0 deletions src/cli/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const CliCommands = {
CONFIG: "config",
LIST_TESTS: "list-tests",
LIST_BROWSERS: "list-browsers",
INSTALL_DEPS: "install-deps",
Expand Down
55 changes: 55 additions & 0 deletions test/src/cli/commands/config/index.ts
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));
});
});
Loading