Skip to content

Commit

Permalink
feat!: use zero questions mode by default.
Browse files Browse the repository at this point in the history
feat!: "-y" argv replaced with "-v" with opposite meaning
feat!: "noQuestions" replaced with "extraQuestions" with opposite meaning

BREAKING CHANGE: use zero questions mode by default.
BREAKING CHANGE: "-y" argv replaced with "-v" with opposite meaning.
BREAKING CHANGE: "noQuestions" replaced with "extraQuestions" with opposite meaning.
  • Loading branch information
KuznetsovRoman committed Apr 22, 2024
1 parent 3ab3248 commit 537617b
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 42 deletions.
20 changes: 11 additions & 9 deletions docs/en/create-testplane.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ Without specifying the path, project will be created in the current directory.

If you already have a project at given path, the tool will try to guess used package manager.

### No questions mode
### Extra questions mode

You can add `-y` or `--yes` argument to launch a tool in *no-questions* mode:
By default, project will be created with zero questions.

You can add `-v` or `--verbose` argument to launch a tool in *extra-questions* mode, to pick custom package manager or pick extra plugins:

```bash
npm init testplane my-app -- -y
npm init testplane my-app -- -v
```

In this mode you won't be asked questions about desired plugins and packet manager.

Default packet manager, used with `--yes` argument: `npm`
Default packet manager, used without `--verbose` argument: `npm`

Default plugins, installed with `--yes` argument:
Default plugins, installed without `--verbose` argument:
- [html-reporter](https://github.com/gemini-testing/html-reporter)

### Lang
Expand Down Expand Up @@ -86,14 +88,14 @@ createTestplane.run({

**Required parameter**

Default tool's CLI handles given path and `--yes` argument. In this callback you need to at least specify `path` and `noQuestions` values:
Default tool's CLI handles given path and `--verbose` argument. In this callback you need to at least specify `path` and `extraQuestions` values:

```ts
import type { DefaultOpts } from "create-testplane";

const argvOpts = {
path: ".",
noQuestions: true
extraQuestions: false
};

const createOpts = (defaultOpts: DefaultOpts) => {
Expand Down Expand Up @@ -160,7 +162,7 @@ const generalPromptsHandler: HandleGeneralPromptsCallback = (testplaneConfig, an
};
```

If `GeneralPrompt` does not have `default` value, the question will be asked even with `noQuestions: true`
If `GeneralPrompt` does not have `default` value, the question will be asked with `extraQuestions: false`

#### createPluginsConfig

Expand Down Expand Up @@ -245,7 +247,7 @@ const createOpts = (defaultOpts: DefaultOpts) => {
return {
...defaultOpts,
path: ".",
noQuestions: false
extraQuestions: false
};
};
```
Expand Down
24 changes: 15 additions & 9 deletions docs/ru/create-testplane.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ npm init testplane my-app

Если по указанному пути уже имеется проект, инструмент попробует определить используемый пакетный менеджер, и будет использовать его для установки пакетов.

### Режим «без вопросов»
### Режим продвинутой установки

Вы можете добавить аргумент `-y` или `--yes` чтобы запустить инструмент в режиме «без вопросов».
По умолчанию, проект будет настроен без всяких вопросов.

Для запуска инструмента в режиме продвинутой установки, Вы можете добавить аргумент `-v` или `--verbose`. Это позволит выбрать пакетный менеджер или сразу установить дополнительные плагины.

```bash
npm init testplane my-app -- -v
```

В этом режиме у вас не будут спрашивать о желаемых плагинах и пакетном менеджере, будут использоваться настройки по умолчанию.

Пакетный менеджер по умолчанию, используемый с аргументом `--yes`: `npm`
Пакетный менеджер по умолчанию, используемый без аргумента `--verbose`: `npm`

Плагины по умолчанию, устанавливаемые с аргументом `--yes`:
Плагины по умолчанию, устанавливаемые без аргумента `--verbose`:
- [html-reporter](https://github.com/gemini-testing/html-reporter)

### Язык
Expand Down Expand Up @@ -82,15 +88,15 @@ createTestplane.run({

**Обязательный параметр.**

Консольный интерфейс по умолчанию обрабатывает данный путь и аргумент `--yes`.
В этом коллбэке вам необходимо указать как минимум значения `path` и `noQuestions`:
Консольный интерфейс по умолчанию обрабатывает данный путь и аргумент `--verbose`.
В этом коллбэке вам необходимо указать, как минимум, значения `path` и `extraQuestions`:

```ts
import type { DefaultOpts } from "create-testplane";

const argvOpts = {
path: ".",
noQuestions: true
extraQuestions: false
};

const createOpts = (defaultOpts: DefaultOpts) => {
Expand Down Expand Up @@ -156,7 +162,7 @@ const generalPromptsHandler: HandleGeneralPromptsCallback = (testplaneConfig, an
};
```

Если у `GeneralPrompt` не указать значение по умолчанию, вопрос будет задан даже при `noQuestions: true`
Если у `GeneralPrompt` не указать значение по умолчанию, вопрос будет задан даже при `extraQuestions: false`

#### createPluginsConfig

Expand Down Expand Up @@ -241,7 +247,7 @@ const createOpts = (defaultOpts: DefaultOpts) => {
return {
...defaultOpts,
path: ".",
noQuestions: false
extraQuestions: false
};
};
```
Expand Down
6 changes: 3 additions & 3 deletions src/bin/create-testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const argv = yargs(hideBin(process.argv))
description: "Language, which will be used to write Testplane tests",
choices: ["ts", "js"],
})
.option("yes", {
alias: "y",
.option("verbose", {
alias: "v",
type: "boolean",
default: false,
description: "Auto configuration with 0 questions",
description: "Advanced configuration with extra questions",
})
.parse();

Expand Down
10 changes: 5 additions & 5 deletions src/configBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,30 @@ describe("configBuilder", () => {

describe("should do nothing if", () => {
it("prompts are empty", () => {
configBuilder.handleGeneralQuestions([], [jest.fn()], { path: "/", noQuestions: false });
configBuilder.handleGeneralQuestions([], [jest.fn()], { path: "/", extraQuestions: true });

expectConfig(defaultTestplaneConfig);
});

it("handlers are empty", () => {
configBuilder.handleGeneralQuestions([{ message: "foo", type: "input", name: "bar" }], [], {
path: "/",
noQuestions: false,
extraQuestions: true,
});

expectConfig(defaultTestplaneConfig);
});
});

it("should not ask extra questions in 'noQuestions' mode", () => {
it("should not ask extra questions if 'extraQuestions' is not set", () => {
configBuilder.handleGeneralQuestions(
[
{ message: "first silent question", type: "input", name: "1", default: "42" },
{ message: "loud question", type: "input", name: "2" },
{ message: "second silent question", type: "input", name: "3", default: "42" },
],
[jest.fn()],
{ path: "/", noQuestions: true },
{ path: "/", extraQuestions: false },
);

expect(inquirer.prompt).toBeCalledWith([{ message: "loud question", type: "input", name: "2" }]);
Expand All @@ -93,7 +93,7 @@ describe("configBuilder", () => {

configBuilder.handleGeneralQuestions(questions, [firstHandler, secondHandler], {
path: "/",
noQuestions: false,
extraQuestions: true,
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/configBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ConfigBuilder {
async handleGeneralQuestions(
promts: GeneralPrompt[],
handlers: HandleGeneralPromptsCallback[],
{ path, noQuestions }: { path: string; noQuestions: boolean },
{ path, extraQuestions }: { path: string; extraQuestions: boolean },
): Promise<Answers> {
const answers: Answers = {
_path: path,
Expand All @@ -54,7 +54,7 @@ export class ConfigBuilder {
return acc;
}, {});

const promptsToAsk = noQuestions ? promts.filter(prompt => _.isUndefined(prompt.default)) : promts;
const promptsToAsk = extraQuestions ? promts : promts.filter(prompt => _.isUndefined(prompt.default));
const inquirerAnswers = await inquirer.prompt(promptsToAsk);

Object.assign(answers, defaults, inquirerAnswers, answers);
Expand Down
2 changes: 1 addition & 1 deletion src/constants/pluginGroups/reportsGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const reportsGroup: PluginGroup = {
default: false,
},
{
description: "Add ability to autogenerate screenshot hermione tests on storybook components in runtime",
description: "Add ability to autogenerate screenshot testplane tests on storybook components in runtime",
plugin: TESTPLANE_STORYBOOK,
default: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const run = async ({
const opts = createOpts(defaultToolOpts);
const configBuilder = ConfigBuilder.create(createBaseConfig, { language: opts.language });

const packageManager = await initApp(opts.path, opts.noQuestions);
const packageManager = await initApp(opts.path, opts.extraQuestions);

const generalPromptsHandlers = generalPromptsHandler
? [baseGeneralPromptsHandler, generalPromptsHandler]
Expand Down
8 changes: 4 additions & 4 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Colors } from "./utils/colors";
import { askQuestion, packageNameFromPlugin } from "./utils";
import type { PackageManager } from "./constants/packageManagement";

const getPackageManager = async (dirPath: string, noQuestions: boolean): Promise<PackageManager> => {
const getPackageManager = async (dirPath: string, extraQuestions: boolean): Promise<PackageManager> => {
let packageManager: PackageManager | undefined;
const packageManagers = Object.keys(PMS) as PackageManager[];
await Promise.all(
Expand All @@ -24,7 +24,7 @@ const getPackageManager = async (dirPath: string, noQuestions: boolean): Promise
return packageManager;
}

if (noQuestions) {
if (!extraQuestions) {
return DEFAULT_PM;
}

Expand Down Expand Up @@ -61,7 +61,7 @@ const initNodeProject = (dirPath: string, packageManager: PackageManager): Promi
);
});

export const initApp = async (dirPath: string, noQuestions: boolean): Promise<PackageManager> => {
export const initApp = async (dirPath: string, extraQuestions: boolean): Promise<PackageManager> => {
await fsUtils.ensureDirectory(dirPath);

const existingConfigName = await findExistingConfig(dirPath);
Expand All @@ -72,7 +72,7 @@ export const initApp = async (dirPath: string, noQuestions: boolean): Promise<Pa
process.exit(1);
}

const packageManager = await getPackageManager(dirPath, noQuestions);
const packageManager = await getPackageManager(dirPath, extraQuestions);

const isPackageJsonExist = await fsUtils.exists(path.resolve(dirPath, PACKAGE_JSON));
if (!isPackageJsonExist) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ const askPluginNames = async (opts: ToolOpts): Promise<{ pluginNames: string[];
};

export const getPluginNames = async (opts: ToolOpts): Promise<{ pluginNames: string[]; configNotes: ConfigNote[] }> => {
return opts.noQuestions ? getDefaultPluginNames(opts) : await askPluginNames(opts);
return opts.extraQuestions ? await askPluginNames(opts) : getDefaultPluginNames(opts);
};
2 changes: 1 addition & 1 deletion src/types/toolArgv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Language } from "./testplaneConfig";
export interface ToolArgv {
$0: string;
_: string[];
yes?: boolean;
verbose?: boolean;
lang?: Language;
}
2 changes: 1 addition & 1 deletion src/types/toolOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type HandleGeneralPromptsCallback = (
export interface ArgvOpts {
path: string;
language: Language;
noQuestions: boolean;
extraQuestions: boolean;
}

export interface DefaultOpts {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ describe("utils", () => {
expect(result.path).toBe("/cwd/some folder");
});

describe("should return noQuestions", () => {
describe("should return extraQuestions", () => {
[true, false, undefined].forEach(state => {
it(`if "yes" is "${state}"`, () => {
it(`if "verbose" is "${state}"`, () => {
const result = utils.optsFromArgv({
_: ["some folder"],
$0: "",
lang: "ts",
yes: state,
verbose: state,
});

expect(result.noQuestions).toBe(Boolean(state));
expect(result.extraQuestions).toBe(Boolean(state));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const optsFromArgv = (argv: ToolArgv): ArgvOpts => {
return {
path: path.resolve(process.cwd(), argv["_"][0]),
language: argv.lang === "js" ? "js" : "ts",
noQuestions: Boolean(argv.yes),
extraQuestions: Boolean(argv.verbose),
};
};

Expand Down

0 comments on commit 537617b

Please sign in to comment.