Skip to content

Commit

Permalink
update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Nov 23, 2024
1 parent 9485fd8 commit 0bfbc32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/cucumber-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ export function buildArgs(runCfg: CucumberRunnerConfig, cucumberBin: string) {
/**
* Normalizes a Cucumber-js format string.
*
* For structured inputs (`key:value`, `"key:value"`, or `"key":"value"`), returns a string
* in the form `"key":"value"`. If the value starts with `file://`, it is treated as an
* absolute path, and no asset directory is prepended. Otherwise, the asset directory
* is prepended to relative paths.
*
* For simple inputs (e.g., `usage`) or other unstructured formats, the input is returned unchanged.
* This function handles structured inputs in the format `key:value`, `"key:value"`,
* or `"key":"value"` and returns a normalized string in the form `"key":"value"`.
* For simple inputs (e.g., `usage`) or unstructured formats, the function returns the
* input unchanged.
*
* @param {string} format - The input format string. Examples include:
* - `"key:value"`
Expand All @@ -93,19 +91,16 @@ export function buildArgs(runCfg: CucumberRunnerConfig, cucumberBin: string) {
* Examples:
* - Input: `"html:formatter/report.html"`, `"/project/assets"`
* Output: `"html":"/project/assets/formatter/report.html"`
* - Input: `"html":"file://formatter/report.html"`, `"/project/assets"`
* Output: `"html":"file://formatter/report.html"`
* - Input: `"usage"`, `"/project/assets"`
* Output: `"usage"`
* - Input: `"file://implementation":"output_file"`, `"/project/assets"`
* Output: `"file://implementation":"/project/assets/output_file"`
* Output: `"file://implementation":"output_file"` (unchanged)
*/
export function normalizeFormat(format: string, assetDir: string): string {
// Try to match structured inputs in the format key:value, "key:value", or "key":"value".
let match = format.match(/^"?([^:]+):"?([^"]+)"?$/);

if (!match) {
// Check if the format uses a file path starting with "file://".
if (!format.startsWith('"file://')) {
return format;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/src/cucumber-runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe('buildArgs', () => {
suite: {
options: {
paths: ['features/test.feature'],
formatOptions: {
build: 'mybuild',
},
},
},
};
Expand All @@ -28,7 +31,7 @@ describe('buildArgs', () => {
'--format',
'"@saucelabs/cucumber-reporter":"sauce-test-report.json"',
'--format-options',
'{"upload":false,"outputFile":"/project/assets/sauce-test-report.json"}',
'{"upload":false,"build":"mybuild","outputFile":"/project/assets/sauce-test-report.json"}',
]);
});
});
Expand Down

0 comments on commit 0bfbc32

Please sign in to comment.