Skip to content

Commit 6b471aa

Browse files
chore!: update dependencies
1 parent 911d218 commit 6b471aa

File tree

14 files changed

+1188
-925
lines changed

14 files changed

+1188
-925
lines changed

package-lock.json

Lines changed: 1072 additions & 823 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"devDependencies": {
4242
"@commitlint/cli": "^16.3.0",
4343
"@commitlint/config-conventional": "^16.2.4",
44+
"@inquirer/type": "^3.0.8",
4445
"@tsconfig/recommended": "^1.0.1",
45-
"@types/inquirer": "^9.0.1",
4646
"@types/jest": "^29.5.11",
4747
"@types/jest-when": "^3.5.5",
4848
"@types/lodash": "^4.14.185",
@@ -60,15 +60,16 @@
6060
"prettier": "^2.7.1",
6161
"testplane": "^0.1.0-rc.0",
6262
"ts-jest": "^29.1.1",
63-
"typescript": "^4.4.4"
63+
"typescript": "^5.9.2"
6464
},
6565
"dependencies": {
66-
"inquirer": "^8.2.4",
66+
"@inquirer/prompts": "^7.8.6",
67+
"load-esm": "^1.0.3",
6768
"lodash": "^4.17.21",
68-
"ora": "^4.1.1",
69-
"yargs": "^17.5.1"
69+
"ora": "^8.2.0",
70+
"yargs": "^17.7.2"
7071
},
7172
"engines": {
72-
"node": ">=12.0.0"
73+
"node": ">=18.19.0"
7374
}
7475
}

src/bin/create-testplane.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
#!/usr/bin/env node
22

3-
import yargs from "yargs";
4-
import { hideBin } from "yargs/helpers";
3+
import { loadEsm } from "load-esm";
54

65
import launcher from "../index";
76
import { optsFromArgv } from "../utils";
87
import { ToolArgv } from "../types/toolArgv";
98
import { DefaultOpts, ToolOpts } from "../types/toolOpts";
109

11-
const argv = yargs(hideBin(process.argv))
12-
.usage("Usage: $0 <path>")
13-
.option("lang", {
14-
alias: "l",
15-
type: "string",
16-
default: "ts",
17-
description: "Language, which will be used to write Testplane tests",
18-
choices: ["ts", "js"],
19-
})
20-
.option("verbose", {
21-
alias: "v",
22-
type: "boolean",
23-
default: false,
24-
description: "Advanced configuration with extra questions",
25-
})
26-
.parse();
10+
async function main(): Promise<void> {
11+
const [{ default: yargs }, { hideBin }] = await Promise.all([
12+
loadEsm<typeof import("yargs")>("yargs"),
13+
loadEsm<typeof import("yargs/helpers")>("yargs/helpers"),
14+
]);
2715

28-
const argvOpts = optsFromArgv(argv as ToolArgv);
29-
const createOpts = (defaultOpts: DefaultOpts): ToolOpts => ({ ...defaultOpts, ...argvOpts });
30-
launcher.run({ createOpts });
16+
const argv = yargs(hideBin(process.argv))
17+
.usage("Usage: $0 <path>")
18+
.option("lang", {
19+
alias: "l",
20+
type: "string",
21+
default: "ts",
22+
description: "Language, which will be used to write Testplane tests",
23+
choices: ["ts", "js"],
24+
})
25+
.option("verbose", {
26+
alias: "v",
27+
type: "boolean",
28+
default: false,
29+
description: "Advanced configuration with extra questions",
30+
})
31+
.parse();
32+
33+
const argvOpts = optsFromArgv(argv as ToolArgv);
34+
const createOpts = (defaultOpts: DefaultOpts): ToolOpts => ({ ...defaultOpts, ...argvOpts });
35+
36+
await launcher.run({ createOpts });
37+
}
38+
39+
main();

src/configBuilder.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import _ from "lodash";
22
import { when } from "jest-when";
3-
import inquirer from "inquirer";
3+
import { inquirerPrompt } from "./utils/inquirer";
44
import defaultTestplaneConfig from "./constants/defaultTestplaneConfig";
55
import { ConfigBuilder } from "./configBuilder";
66
import fsUtils from "./fsUtils";
77
import defaultPluginsConfig from "./pluginsConfig";
88
import type { Answers, GeneralPrompt, TestplaneConfig } from "./types";
99

10-
jest.mock("inquirer");
10+
jest.mock("./utils/inquirer");
1111

1212
jest.mock("./fsUtils");
1313

@@ -73,7 +73,8 @@ describe("configBuilder", () => {
7373
{ path: "/", extraQuestions: false },
7474
);
7575

76-
expect(inquirer.prompt).toBeCalledWith([{ message: "loud question", type: "input", name: "2" }]);
76+
expect(inquirerPrompt).toBeCalledWith({ message: "loud question", type: "input", name: "2" });
77+
expect(inquirerPrompt).toBeCalledTimes(1);
7778
});
7879

7980
it("should mutate config with handlers", () => {
@@ -89,7 +90,9 @@ describe("configBuilder", () => {
8990
when(firstHandler).calledWith(defaultTestplaneConfig, answers).mockResolvedValue(firstHandlerResult);
9091
when(secondHandler).calledWith(firstHandlerResult, answers).mockResolvedValue(secondHandlerResult);
9192

92-
when(inquirer.prompt).calledWith(questions).mockResolvedValue(answers);
93+
jest.mocked(inquirerPrompt).mockImplementation((prompt: unknown) => {
94+
return Promise.resolve(answers[(prompt as { name: string }).name as keyof typeof answers]);
95+
});
9396

9497
configBuilder.handleGeneralQuestions(questions, [firstHandler, secondHandler], {
9598
path: "/",

src/configBuilder.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import _ from "lodash";
2-
import inquirer from "inquirer";
32
import { writeTestplaneConfig } from "./fsUtils";
43
import defaultPluginsConfig from "./pluginsConfig";
54
import defaultToolOpts from "./constants/defaultToolOpts";
65
import defaultTestplaneConfig from "./constants/defaultTestplaneConfig";
6+
import { getTemplate } from "./utils/configTemplates";
7+
import { inquirerPrompt } from "./utils";
78
import type { TestplaneConfig, Language } from "./types/testplaneConfig";
89
import type { Answers, HandleGeneralPromptsCallback } from "./types/toolOpts";
910
import type { CreateBaseConfigCallback, CreatePluginsConfigCallback } from ".";
1011
import type { GeneralPrompt } from "./types/toolOpts";
11-
import { getTemplate } from "./utils/configTemplates";
1212

1313
type ConfigurePluginsOpts = {
1414
pluginNames: string[];
@@ -52,10 +52,17 @@ export class ConfigBuilder {
5252
}
5353

5454
return acc;
55-
}, {});
55+
}, {} as Answers);
5656

5757
const promptsToAsk = extraQuestions ? promts : promts.filter(prompt => _.isUndefined(prompt.default));
58-
const inquirerAnswers = await inquirer.prompt(promptsToAsk);
58+
59+
const inquirerAnswers = {} as Answers;
60+
61+
for (const prompt of promptsToAsk) {
62+
const result = await inquirerPrompt(prompt);
63+
64+
inquirerAnswers[prompt.name] = result;
65+
}
5966

6067
Object.assign(answers, defaults, inquirerAnswers, answers);
6168

src/fsUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const writeTest = async (dirPath: string, testName: string, testContent:
120120
export const writeJson = async (filePath: string, obj: Record<string, unknown>): Promise<void> => {
121121
await ensureDirectory(path.dirname(filePath));
122122

123-
return fs.promises.writeFile(filePath, JSON.stringify(obj, null, 4));
123+
return fs.promises.writeFile(filePath, JSON.stringify(obj, null, 4) + "\n");
124124
};
125125

126126
export const readJson = async (filePath: string): Promise<Record<string, unknown>> => {

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import defaultToolOpts from "./constants/defaultToolOpts";
22
import { initApp, installPackages } from "./package";
33
import {
4-
askQuestion,
54
baseGeneralPromptsHandler,
65
extendWithTypescript,
6+
inquirerPrompt,
77
printSuccessMessage,
88
writeTestExample,
99
} from "./utils";
@@ -43,7 +43,7 @@ process.on("unhandledRejection", (reason, p) => {
4343
console.error("Unhandled Rejection:\n Promise: ", p, "\n Reason: ", reason);
4444
});
4545

46-
export { askQuestion, defineVariable, addModule, asExpression } from "./utils";
46+
export { inquirerPrompt, defineVariable, addModule, asExpression } from "./utils";
4747
export { baseGeneralPrompts };
4848
export { defaultTestplaneTestsDir } from "./constants/defaultTestplaneConfig";
4949

@@ -87,5 +87,5 @@ export const run = async ({
8787
printSuccessMessage(configNotes.concat(extraPackages.notes));
8888
};
8989

90-
export default { run, askQuestion, baseGeneralPrompts };
90+
export default { run, inquirerPrompt, baseGeneralPrompts };
9191
export * from "./types";

src/package.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import ora from "ora";
1+
import { loadEsm } from "load-esm";
22
import path from "path";
33
import { exec } from "child_process";
44

55
import fsUtils from "./fsUtils";
66
import { DEFAULT_PM, CONFIG_NAMES, PMS, PACKAGE_JSON } from "./constants/packageManagement";
77
import { Colors } from "./utils/colors";
8-
import { askQuestion, packageNameFromPlugin } from "./utils";
8+
import { inquirerPrompt, packageNameFromPlugin } from "./utils";
99
import type { PackageManager } from "./constants/packageManagement";
1010

1111
const getPackageManager = async (dirPath: string, extraQuestions: boolean): Promise<PackageManager> => {
@@ -28,8 +28,8 @@ const getPackageManager = async (dirPath: string, extraQuestions: boolean): Prom
2828
return DEFAULT_PM;
2929
}
3030

31-
return askQuestion<PackageManager>({
32-
type: "list",
31+
return inquirerPrompt({
32+
type: "select",
3333
message: "Choose preferred package manager:",
3434
choices: Object.keys(PMS),
3535
default: DEFAULT_PM,
@@ -104,6 +104,7 @@ export const installPackages = async (
104104
pluginsToInstall: string[],
105105
registry: string,
106106
): Promise<string> => {
107+
const { default: ora } = await loadEsm<typeof import("ora")>("ora");
107108
const spinner = ora("Installing packages (this may take a while)").start();
108109

109110
const pluginsPackages = pluginsToInstall.map(packageNameFromPlugin).join(" ");

src/plugins.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ToolOpts } from "./types/toolOpts";
2-
import { askQuestion, packageNameFromPlugin } from "./utils";
2+
import { inquirerPrompt, packageNameFromPlugin } from "./utils";
33

44
export type ConfigNote = { plugin: string; configNote: string };
55

@@ -17,42 +17,33 @@ const askPluginNames = async (opts: ToolOpts): Promise<{ pluginNames: string[];
1717
let pluginNames: string[] = [];
1818
let configNotes: ConfigNote[] = [];
1919

20-
const getDefaultFeatures = (opts: ToolOpts): number[] => {
21-
const inds: number[] = [];
22-
opts.pluginGroups.forEach(({ plugins }, ind) => {
23-
if (plugins.some(plugin => plugin.default)) {
24-
inds.push(ind);
25-
}
26-
});
27-
return inds;
28-
};
29-
30-
const wantedFeatures = await askQuestion<number[]>({
20+
const wantedFeatures = await inquirerPrompt<number[]>({
3121
type: "checkbox",
3222
message: "Which features do you need?",
33-
choices: opts.pluginGroups.map((group, ind) => ({ name: group.description, value: ind })),
34-
default: getDefaultFeatures(opts),
23+
choices: opts.pluginGroups.map((group, ind) => ({
24+
name: group.description,
25+
value: ind,
26+
checked: group.plugins.some(plugin => plugin.default),
27+
})),
3528
});
3629

3730
for (const ind of wantedFeatures) {
3831
const { description, plugins } = opts.pluginGroups[ind];
39-
const curGroupPlugins = await askQuestion<number[]>({
32+
const curGroupPlugins = await inquirerPrompt<number[]>({
4033
type: "checkbox",
4134
message: `Plugins: ${description}`,
42-
choices: plugins.map(({ plugin, description }, index) => ({
35+
choices: plugins.map(({ plugin, description, default: checked }, index) => ({
4336
name: `${description} (${packageNameFromPlugin(plugin)})`,
4437
value: index,
38+
checked,
4539
})),
46-
default: plugins.reduce((def: number[], plugin, index) => {
47-
return plugin.default ? def.concat(index) : def;
48-
}, []),
4940
});
5041

5142
const notesIndToAdd = curGroupPlugins.filter(ind => plugins[ind].configNote);
5243
const pluginNamesToAdd = curGroupPlugins.map(ind => plugins[ind].plugin);
5344
const notesToAdd: ConfigNote[] = notesIndToAdd.map(ind => ({
5445
plugin: plugins[ind].plugin,
55-
configNote: plugins[ind].configNote!,
46+
configNote: plugins[ind].configNote as string,
5647
}));
5748

5849
pluginNames = pluginNames.concat(pluginNamesToAdd);

src/pluginsConfig/testplane-safari-commands.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import inquirer, { DistinctQuestion } from "inquirer";
21
import _ from "lodash";
32
import { TESTPLANE_SAFARI_COMMANDS } from "../constants/plugins";
43
import { defaultTestplaneTestsDir } from "../constants/defaultTestplaneConfig";
54
import type { TestplaneConfig } from "../types/testplaneConfig";
5+
import { inquirerPrompt } from "../utils";
6+
import type { InquirerPrompts } from "../utils/inquirer";
67

78
type SafariCommand =
89
| "url"
@@ -25,19 +26,16 @@ export default {
2526
fn: async (config: TestplaneConfig): Promise<void> => {
2627
const browserId = "safari";
2728

28-
type CreateInputPrompt = (name: string, message: string) => DistinctQuestion<Record<string, string>>;
29+
type CreateInputPrompt = (message: string) => InquirerPrompts["input"];
2930

30-
const createInputPrompt: CreateInputPrompt = (name, message) => ({
31+
const createInputPrompt: CreateInputPrompt = message => ({
3132
type: "input",
32-
name,
3333
message: "testplane-safari-commands: " + message,
3434
});
3535

36-
const { deviceName, platformVersion, version } = await inquirer.prompt([
37-
createInputPrompt("deviceName", "Enter device name (ex: iPhone 11):"),
38-
createInputPrompt("platformVersion", "Enter iOS version (ex: 13.3):"),
39-
createInputPrompt("version", "Enter safari version (ex: 13.0):"),
40-
]);
36+
const deviceName = await inquirerPrompt(createInputPrompt("Enter device name (ex: iPhone 11):"));
37+
const platformVersion = await inquirerPrompt(createInputPrompt("Enter iOS version (ex: 13.3):"));
38+
const version = await inquirerPrompt(createInputPrompt("Enter safari version (ex: 13.0):"));
4139

4240
_.mergeWith(
4341
config,

0 commit comments

Comments
 (0)