Skip to content

Commit

Permalink
feat: update cucumber format parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Nov 20, 2024
1 parent 2fa1394 commit 195c5c6
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/cucumber-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function buildArgs(runCfg: CucumberRunnerConfig, cucumberBin: string) {
const procArgs = [
cucumberBin,
...paths,
'--publish-quiet', // Deprecated in 9.4.0. Will be removed in 11.0.0 or later.
'--force-exit',
'--require-module',
'ts-node/register',
Expand Down Expand Up @@ -50,20 +49,41 @@ function buildArgs(runCfg: CucumberRunnerConfig, cucumberBin: string) {
procArgs.push('-t');
procArgs.push(tag);
});

function parseNewFormat(format: string, assetsDir: string) {
// Regex to validate and extract key and value from the new format.
// Example: "html":"file://hostname/formatter/report.html"
const match = format.match(/^"([^"]+)":"(.+)"$/);
if (!match) {
return null;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, key, value] = match;
return `"${key}":"${path.join(assetsDir, value)}"`;
}

runCfg.suite.options.format?.forEach((format) => {
procArgs.push('--format');

const newFormat = parseNewFormat(format, runCfg.assetsDir);
if (newFormat) {
return newFormat;
}

const opts = format.split(':');
if (opts.length === 2) {
procArgs.push(`${opts[0]}:${path.join(runCfg.assetsDir, opts[1])}`);
} else {
procArgs.push(format);
return `"${opts[0]}":"${path.join(runCfg.assetsDir, opts[1])}"`;
}

return `"${format}"`;
});

if (runCfg.suite.options.parallel) {
procArgs.push('--parallel');
procArgs.push(runCfg.suite.options.parallel.toString(10));
}

console.log('procArgs: ', procArgs);
return procArgs;
}

Expand Down

0 comments on commit 195c5c6

Please sign in to comment.