Skip to content

Commit e5d5467

Browse files
committed
fix: Add args array option for formatter
1 parent 47f762a commit e5d5467

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/add-cucumber-preprocessor-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ export async function afterRunHandler(config: Cypress.PluginConfigOptions) {
9999
const json = await fs.open(jsonPath, "w");
100100

101101
try {
102-
const [executable, ...args] = preprocessor.json.formatter.split(' ');
103-
const child = child_process.spawn(executable, args, {
102+
const { formatter, args } = preprocessor.json;
103+
const child = child_process.spawn(formatter, args, {
104104
stdio: [messages.fd, json.fd, "inherit"],
105105
});
106106

lib/preprocessor-configuration.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ function validateConfigurationEntry(
6767
`Expected an object (json), but got ${util.inspect(value)}`
6868
);
6969
}
70+
let args: string[] | undefined;
71+
if (hasOwnProperty(value, "args")) {
72+
if (Array.isArray(value.args) && value.args.every(isString)) {
73+
args = value.args;
74+
} else {
75+
throw new Error(
76+
`Expected an array of strings (json.args), but got ${
77+
util.inspect(value)
78+
}`
79+
)
80+
}
81+
}
7082
if (
7183
!hasOwnProperty(value, "enabled") ||
7284
typeof value.enabled !== "boolean"
@@ -96,6 +108,7 @@ function validateConfigurationEntry(
96108
}
97109
}
98110
const messagesConfig = {
111+
args,
99112
enabled: value.enabled,
100113
formatter,
101114
output,
@@ -172,6 +185,20 @@ function validateEnvironmentOverrides(
172185
}
173186
}
174187

188+
if (hasOwnProperty(environment, "jsonArgs")) {
189+
let { jsonArgs } = environment;
190+
if (isString(jsonArgs)) {
191+
jsonArgs = JSON.parse(jsonArgs);
192+
}
193+
if (Array.isArray(jsonArgs) && jsonArgs.every(isString)) {
194+
overrides.jsonArgs = jsonArgs;
195+
} else {
196+
throw new Error(
197+
`Expected a string array (jsonArgs), but got ${util.inspect(jsonArgs)}`
198+
);
199+
}
200+
}
201+
175202
if (hasOwnProperty(environment, "jsonEnabled")) {
176203
const { jsonEnabled } = environment;
177204

@@ -266,6 +293,7 @@ export interface IPreprocessorConfiguration {
266293
output?: string;
267294
};
268295
readonly json?: {
296+
args?: string[];
269297
enabled: boolean;
270298
formatter?: string;
271299
output?: string;
@@ -278,6 +306,7 @@ export interface IEnvironmentOverrides {
278306
stepDefinitions?: string | string[];
279307
messagesEnabled?: boolean;
280308
messagesOutput?: string;
309+
jsonArgs?: string[];
281310
jsonEnabled?: boolean;
282311
jsonFormatter?: string;
283312
jsonOutput?: string;
@@ -326,6 +355,10 @@ export class PreprocessorConfiguration implements IPreprocessorConfiguration {
326355

327356
get json() {
328357
return {
358+
args:
359+
this.environmentOverrides.jsonArgs ??
360+
this.explicitValues.json?.args ??
361+
[],
329362
enabled:
330363
this.environmentOverrides.jsonEnabled ??
331364
this.explicitValues.json?.enabled ??

0 commit comments

Comments
 (0)