Skip to content

Commit 3cd800e

Browse files
committed
support simple format strings
1 parent aa780f4 commit 3cd800e

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/cucumber-runner.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,32 @@ export function buildArgs(runCfg: CucumberRunnerConfig, cucumberBin: string) {
6666
}
6767

6868
/**
69-
* Normalizes a Cucumber format string by ensuring it is in the form of `"key":"value"`.
69+
* Normalizes a Cucumber-js format string.
7070
*
71-
* @param {string} format - The input format string, which can be in various forms:
71+
* For structured inputs (`key:value` or `"key:value"`), returns a string in the
72+
* form `"key":"value"`, with the asset directory prepended to relative paths.
73+
* For simple inputs (e.g., `progress-bar`), returns the input as-is.
74+
*
75+
* @param {string} format - The input format string. Examples include:
7276
* - `"key:value"`
7377
* - `"key":"value"`
7478
* - `key:value`
75-
* @param {string} assetDir - The asset directory.
76-
* @throws {Error} If the input format is invalid (e.g., missing a colon separator).
77-
* @returns {string} The normalized format string in the form of `"key":"value"`,
78-
* with the asset directory prepended to relative paths.
79+
* - `progress-bar`
80+
* @param {string} assetDir - The directory to prepend to the value for relative paths.
81+
* @returns {string} The normalized format string. For structured inputs, it returns
82+
* a string in the form `"key":"value"`. For simple inputs, it
83+
* returns the input unchanged.
7984
*
8085
* Example:
81-
* Input: `"html:formatter/report.html"`, `"/project/assets"`
82-
* Output: `"html":"/project/assets/formatter/report.html"`
86+
* - Input: `"html":"formatter/report.html"`, `"/project/assets"`
87+
* Output: `"html":"/project/assets/formatter/report.html"`
88+
* - Input: `"progress-bar"`, `"/project/assets"`
89+
* Output: `"progress-bar"`
8390
*/
8491
export function normalizeFormat(format: string, assetDir: string): string {
8592
const match = format.match(/^"?([^:]+):"?([^"]+)"?$/);
8693
if (!match) {
87-
throw new Error(`Invalid format: ${format}`);
94+
return format;
8895
}
8996

9097
let [, key, value] = match;

tests/unit/src/cucumber-runner.spec.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ describe('normalizeFormat', () => {
5454
);
5555
});
5656

57-
it('should throw an error for invalid formats', () => {
58-
expect(() =>
59-
normalizeFormat(`html-formatter/report.html`, assetDir),
60-
).toThrow('Invalid format: html-formatter/report.html');
61-
expect(() =>
62-
normalizeFormat(`"htmlformatter/report.html"`, assetDir),
63-
).toThrow('Invalid format: "htmlformatter/report.html"');
57+
it('should return simple strings as-is', () => {
58+
expect(normalizeFormat(`"progress-bar"`, assetDir)).toBe('"progress-bar"');
59+
expect(normalizeFormat(`progress-bar`, assetDir)).toBe('progress-bar');
6460
});
6561
});

0 commit comments

Comments
 (0)