A collection of Handlebars helpers for working with Common Test Report Format.
npm install handlebars-helpers-ctrf
import Handlebars from 'handlebars'
import { loadHelpers } from 'handlebars-helpers-ctrf';
// Register all helpers with Handlebars
loadHelpers(Handlebars);
// Now you can use the helpers in your templates
const template = Handlebars.compile('{{append "test" ".html"}}');
const result = template({}); // "test.html"
- Ctrf Helpers
- Array Helpers
- Collections Helpers
- Comparison Helpers
- Date Helpers
- Fs Helpers
- Inflection Helpers
- Match Helpers
- Math Helpers
- Misc Helpers
- Number Helpers
- Object Helpers
- Path Helpers
- Regex Helpers
- String Helpers
- Url Helpers
Sorts tests by their failure rate in descending order, showing the most unreliable tests first.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: Test[]
- A sorted array of tests that have a fail rate, from highest to lowest.
Example:
Sorts tests by their flaky rate in descending order, showing the most flaky tests first.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: Test[]
- A sorted array of tests that have a flaky rate, from highest to lowest.
Example:
Filters test results to only include passed tests. Useful for creating success summaries or filtering out failures.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: Test[]
- An array of tests with "passed" status.
Example:
Filters test results to only include failed tests. Useful for creating failure summaries or error reports.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: Test[]
- An array of tests with "failed" status.
Example:
Filters test results to only include tests with non-standard statuses (skipped, pending, other). Useful for creating comprehensive test summaries.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: Test[]
- An array of tests with non-standard statuses.
Example:
Counts the total number of flaky tests in the test results.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: number
- The total number of flaky tests.
Example:
Determines if there are any flaky tests in the test results. Useful for conditional rendering of flaky test warnings.
Parameters:
tests
(unknown
) - An array of Test objects from CTRF report.
Returns: boolean
- True if any test is marked as flaky, false otherwise.
Example:
Formats test execution duration from start and stop timestamps into a human-readable format. Handles edge cases where timing data might be missing or invalid.
Parameters:
start
(unknown
) - The test start time in milliseconds.stop
(unknown
) - The test stop time in milliseconds.
Returns: string
- A formatted duration string like "1ms", "1.2s", or "1m 30s".
Example:
Formats a test duration value in milliseconds into a human-readable format. Perfect for displaying test execution times in reports.
Parameters:
duration
(unknown
) - The test duration in milliseconds.
Returns: string
- A formatted duration string like "1ms", "1.2s", or "1m 30s".
Example:
Returns all of the items in an array after the specified index. Opposite of before. Useful for slicing test result arrays to show only later results in CTRF reports.
Parameters:
array
(unknown
) - The array from test data.n
(unknown
) - Starting index (number of items to exclude).
Returns: unknown[]
- Array excluding n items from the start.
Example:
Cast the given value to an array. Useful for normalizing test data fields to arrays for consistent rendering in test reports.
Parameters:
value
(unknown
) - The value to cast.
Returns: unknown[]
- The value as an array.
Example:
Return all of the items in the collection before the specified count. Opposite of after. Useful for showing only the first N test results or errors in a summary table.
Parameters:
array
(unknown
) - The array from test data.n
(unknown
) - Number of items to include from the start.
Returns: unknown[]
- Array excluding items after the given number.
Example:
Iterates over each item in an array and exposes the current item and index to the block. Useful for rendering test steps or log entries with their index in CTRF reports.
Parameters:
array
(unknown
) - The array from test data.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for each item with index.
Example:
Block helper that filters the given array and renders the block for values that evaluate to true, otherwise the inverse block is returned. Useful for displaying only passing or failing tests in a filtered test report section.
Parameters:
array
(unknown
) - The array from test data.value
(unknown
) - The value to filter by.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for filtered items.
Example:
Returns the first item, or first n items of an array. Useful for showing the first test, or a summary of the first N failures in a report.
Parameters:
array
(unknown
) - The array from test data.n
(unknown
) - Number of items to return from the start.
Returns: unknown|unknown[]
- The first item or first n items.
Example:
Iterates over each item in an array and exposes the current item as context to the inner block. Useful for rendering each test case, log entry, or assertion in a test report.
Parameters:
array
(unknown
) - The array from test data.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for each item.
Example:
Block helper that renders the block if an array has the given value. Optionally specify an inverse block to render when the array does not have the value. Useful for conditionally rendering sections if a test status or tag is present in the results.
Parameters:
array
(unknown
) - The array from test data.value
(unknown
) - The value to check for.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block if value is present, else inverse.
Example:
Returns true if value is an ES5 array. Useful for checking if a test field is an array before iterating in a template.
Parameters:
value
(unknown
) - The value to test.
Returns: boolean
- True if value is an array.
Example:
Returns the item from array at index idx.
Parameters:
array
(unknown
) - The array from test data.idx
(unknown
) - The index to retrieve.
Returns: unknown
- The item at the given index.
Example:
Join all elements of array into a string, optionally using a given separator.
Parameters:
array
(unknown
) - The array from test data.separator
(unknown
) - The separator to use. Defaults to ','.
Returns: string
- The joined string.
Example:
Returns true if the length of the given value is equal to the given length. Can be used as a block or inline helper.
Parameters:
value
(unknown
) - The value to test (array or string).length
(unknown
) - The length to compare to.
Returns: boolean
- True if lengths are equal.
Example:
Returns the last item, or last n items in an array or string. Opposite of first.
Parameters:
value
(unknown
) - The array or string from test data.n
(unknown
) - Number of items to return from the end.
Returns: unknown|unknown[]
- The last item or last n items.
Example:
Returns the length of the given string or array.
Parameters:
value
(unknown
) - The value to measure (array, object, or string).
Returns: number
- The length of the value.
Example:
Alias for equalsLength. / export const lengthEqualHelper = equalsLengthHelper; /** Returns a new array, created by calling function on each element of the given array.
Parameters:
array
(unknown
) - The array from test data.fn
(unknown
) - The function to call on each element.
Returns: unknown[]
- The mapped array.
Example:
Map over the given object or array of objects and create an array of values from the given prop. Dot-notation may be used (as a string) to get nested properties.
Parameters:
collection
(unknown
) - The array or object from test data.prop
(unknown
) - The property to pluck (dot notation allowed).
Returns: unknown[]
- The plucked values.
Example:
Reverse the elements in an array, or the characters in a string.
Parameters:
value
(unknown
) - The array or string from test data.
Returns: unknown
- The reversed array or string.
Example:
Block helper that returns the block if the callback returns true for some value in the given array.
Parameters:
array
(unknown
) - The array from test data.iter
(unknown
) - The iteratee function.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block if some item passes the iteratee.
Example:
Sort the given array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
Parameters:
array
(unknown
) - The array from test data.keyOrFn
(unknown
) - The key to sort by, or a sorting function.
Returns: unknown[]
- The sorted array.
Example:
Sort an array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
Parameters:
array
(unknown
) - The array from test data.props
(unknown
) - The property or properties to sort by.
Returns: unknown[]
- The sorted array.
Example:
Use the items in the array after the specified index as context inside a block. Opposite of withBefore.
Parameters:
array
(unknown
) - The array from test data.idx
(unknown
) - The index after which to use items.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for items after idx.
Example:
Use the items in the array before the specified index as context inside a block. Opposite of withAfter.
Parameters:
array
(unknown
) - The array from test data.idx
(unknown
) - The index before which to use items.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for items before idx.
Example:
Use the first item in a collection inside a handlebars block expression. Opposite of withLast.
Parameters:
array
(unknown
) - The array from test data.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for the first item.
Example:
Block helper that groups array elements by given group size.
Parameters:
array
(unknown
) - The array from test data.size
(unknown
) - The desired length of each group.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for each group.
Example:
Use the last item or n items in an array as context inside a block. Opposite of withFirst.
Parameters:
array
(unknown
) - The array from test data.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for the last item.
Example:
Block helper that sorts a collection and exposes the sorted collection as context inside the block.
Parameters:
array
(unknown
) - The array from test data.prop
(unknown
) - The property to sort by.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for sorted items.
Example:
Block helper that returns an array with all duplicate values removed. Best used along with an each helper.
Parameters:
array
(unknown
) - The array from test data.
Returns: unknown[]
- Array with duplicates removed.
Example:
Checks if a collection (array, object, or string) is empty. Inline, subexpression, or block helper that returns true (or the block) if the given collection is empty, or false (or the inverse block, if supplied) if the collection is not empty. Useful in CTRF test reporting for conditionally rendering sections when there are no tests, errors, or results.
Parameters:
collection
(unknown
) - The collection (array, object, or string) to check.options
(unknown
) - Handlebars options object (for block usage).
Returns: boolean|string
- True/false for inline/subexpression, or rendered block for block usage.
Example:
Block helper that iterates over an array or object, exposing each item (and key for objects) to the block. If an array is given, .forEach is called; if an object is given, .forOwn is called; otherwise the inverse block is returned. Useful in CTRF test reporting for iterating over dynamic test results, error maps, or grouped data.
Parameters:
collection
(unknown
) - The collection (array or object) to iterate over.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for each item, or inverse block if not iterable.
Example:
Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.
Example:
Render a block when a comparison of the first and third arguments returns true. The second argument is the arithmetic operator to use. You may also optionally specify an inverse block to render when falsy.
Example:
Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.
Example:
Returns the first value that is not undefined, otherwise the default value is returned.
Example:
Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.
Example:
Block helper that renders a block if a is greater than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.
Example:
Block helper that renders a block if a is greater than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.
Example:
Block helper that renders a block if value has pattern. If an inverse block is specified it will be rendered when falsy.
Example:
Returns true if the given value is falsey. Uses JS falsey semantics.
Example:
Returns true if the given value is truthy. Uses JS truthy semantics.
Example:
Return true if the given value is an even number.
Example:
Conditionally renders a block if the remainder is zero when a operand is divided by b. If an inverse block is specified it will be rendered when the remainder is not zero.
Example:
Block helper that renders a block if value is an odd number. If an inverse block is specified it will be rendered when falsy.
Example:
Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.
Example:
Block helper that renders a block if a is not equal to b. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.
Example:
Block helper that renders a block if a is less than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.
Example:
Block helper that renders a block if a is less than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.
Example:
Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.
Example:
Returns true if val is falsey. Works as a block or inline helper.
Example:
Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.
Example:
Block helper that always renders the inverse block unless a is is equal to b.
Example:
Block helper that always renders the inverse block unless a is is greater than b.
Example:
Block helper that always renders the inverse block unless a is is less than b.
Example:
Block helper that always renders the inverse block unless a is is greater than or equal to b.
Example:
Block helper that always renders the inverse block unless a is is less than or equal to b.
Example:
Handlebars helper that returns the current year.
Returns: number
- The current year (e.g., 2024).
Example:
Read a file from the file system. Useful for including file contents in CTRF test reports or templates.
Parameters:
filepath
(unknown
) - The path to the file to read (relative to process.cwd() or absolute).
Returns: string
- The file contents as a string, or an empty string if not found.
Example:
Return an array of files from the given directory. Useful for listing test artifacts, screenshots, or log files in CTRF reports.
Parameters:
directory
(unknown
) - The directory path (relative to process.cwd() or absolute).
Returns: string[]
- Array of file names in the directory, or an empty array if not found.
Example:
Returns either the singular
or plural
inflection of a word based on the given count
. Optionally includes the count in the result. Useful for displaying test counts, result summaries, and dynamic messaging in test reports.
Parameters:
count
(unknown
) - The count to determine singular/plural form.singular
(unknown
) - The singular form of the word.plural
(unknown
) - The plural form of the word.includeCount
(unknown
) - Optional. If true, includes the count in the result.
Returns: string
- The appropriate singular/plural form for use in test reports.
Example:
Returns an ordinalized number as a string (1st, 2nd, 3rd, etc.). Useful for ranking test results, iteration counts, and positional information in test reports.
Parameters:
val
(unknown
) - The number to ordinalize (can be string or number).
Returns: string
- The ordinalized number for use in test reports.
Example:
Returns an array of strings that match the given glob pattern(s). Useful for filtering test files, assets, or any file paths in test reports based on patterns.
Parameters:
files
(string[]|string
) - Array of file paths or single file path from test data.patterns
(string|string[]
) - One or more glob patterns to match against.options
(Object
) - Handlebars options object (optional).
Returns: string[]
- Array of file paths that match the patterns for use in test reports.
Example:
Returns true if a filepath contains the given pattern. Useful for conditional logic in test reports to check if files match specific patterns.
Parameters:
filepath
(string
) - The file path from test data to check.pattern
(string
) - The glob pattern to match against.options
(Object
) - Handlebars options object (optional).
Returns: boolean
- True if the filepath matches the pattern for use in test reports.
Example:
Return the magnitude (absolute value) of a number. Useful for normalizing test durations, error counts, or differences in CTRF reports.
Parameters:
a
(unknown
) - The value to get the absolute value of.
Returns: number
- The absolute value.
Example:
Return the sum of a plus b. Useful for aggregating test metrics, such as total retries or combined durations.
Parameters:
a
(unknown
) - First number.b
(unknown
) - Second number.
Returns: number
- The sum.
Example:
Returns the average of all numbers in the given array. Useful for calculating average test durations, retry counts, or error rates in CTRF reports.
Parameters:
arr
(unknown
) - Array of numbers (array or JSON string).
Returns: number
- The average value.
Example:
Get the Math.ceil() of the given value. Useful for rounding up test metrics, such as duration or retry counts.
Parameters:
value
(unknown
) - The value to ceil.
Returns: number
- The ceiled value.
Example:
Divide a by b. Useful for calculating rates, averages, or percentages in CTRF reports.
Parameters:
a
(unknown
) - Numerator.b
(unknown
) - Denominator.
Returns: number
- The result of division, or 0 if denominator is 0.
Example:
Get the Math.floor() of the given value. Useful for rounding down test metrics, such as duration or retry counts.
Parameters:
value
(unknown
) - The value to floor.
Returns: number
- The floored value.
Example:
Return the difference of a minus b. Useful for calculating deltas between test metrics, such as duration differences.
Parameters:
a
(unknown
) - First number.b
(unknown
) - Second number.
Returns: number
- The difference.
Example:
Get the remainder of a division operation (a % b). Useful for calculating modulo in test metrics, such as grouping or bucketing.
Parameters:
a
(unknown
) - Numerator.b
(unknown
) - Denominator.
Returns: number
- The remainder.
Example:
Return the product of a times b. Useful for scaling test metrics, such as multiplying durations or retry counts.
Parameters:
a
(unknown
) - First factor.b
(unknown
) - Second factor.
Returns: number
- The product.
Example:
Add a by b (alias for add). Useful for summing test metrics.
Parameters:
a
(unknown
) - First number.b
(unknown
) - Second number.
Returns: number
- The sum.
Example:
Generate a random number between two values (inclusive, integer). Useful for generating random test data or sampling in CTRF reports.
Parameters:
min
(unknown
) - Minimum value.max
(unknown
) - Maximum value.
Returns: number
- Random integer between min and max.
Example:
Get the remainder when a is divided by b (alias for modulo). Useful for grouping or bucketing test metrics.
Parameters:
a
(unknown
) - Numerator.b
(unknown
) - Denominator.
Returns: number
- The remainder.
Example:
Round the given number to the nearest integer. Useful for rounding test metrics for display in CTRF reports.
Parameters:
number
(unknown
) - The number to round.
Returns: number
- The rounded value.
Example:
Return the difference of a minus b (alias for minus). Useful for calculating deltas between test metrics.
Parameters:
a
(unknown
) - First number.b
(unknown
) - Second number.
Returns: number
- The difference.
Example:
Returns the sum of all numbers in the given array. Useful for calculating total durations, retries, or error counts in CTRF reports.
Parameters:
arr
(unknown
) - Array of numbers (array or JSON string).
Returns: number
- The sum.
Example:
Multiply number a by number b (alias for multiply). Useful for scaling test metrics.
Parameters:
a
(unknown
) - First factor.b
(unknown
) - Second factor.
Returns: number
- The product.
Example:
Return the given value of prop from this.options. Useful for accessing runtime options passed to the template, such as CTRF configuration or test report metadata.
Parameters:
prop
(string
) - The dot-notated property path to retrieve from this.options.
Returns: any
- The value at the given property path, or undefined if not found.
Example:
Block helper that renders the block without taking any arguments. Useful for grouping content or as a placeholder in CTRF test report templates.
Parameters:
options
(object
) - Handlebars options object.
Returns: string
- The rendered block content.
Example:
Get the native type of the given value. Useful for debugging or conditional logic in CTRF test report templates.
Parameters:
value
(any
) - The value to check.
Returns: string
- The native type of the value.
Example:
Block helper that builds the context for the block from the options hash. Useful for injecting dynamic context in CTRF test report templates.
Parameters:
options
(object
) - Handlebars options object with hash.
Returns: string
- The rendered block with hash context.
Example:
Format a number to its equivalent in bytes. If a string is passed, its length will be formatted and returned. Useful for displaying test file sizes, memory usage, or data transfer amounts in test reports.
Parameters:
number
(unknown
) - The number or string from test data to format as bytes.
Returns: string
- The formatted byte string for use in test reports.
Example:
Add commas to numbers for improved readability. Useful for formatting large numbers like test counts, execution times, or file sizes in test reports.
Parameters:
num
(unknown
) - The number from test data to format with commas.
Returns: string
- The comma-formatted number string for use in test reports.
Example:
Convert a string or number to a formatted phone number. Useful for formatting contact information in test reports or user data validation tests.
Parameters:
num
(unknown
) - The phone number from test data to format, e.g.,8005551212
.
Returns: string
- Formatted phone number: (800) 555-1212
for use in test reports.
Example:
Abbreviate numbers to the given number of precision. This is for general numbers, not size in bytes. Useful for displaying large test metrics like execution counts or performance numbers in test reports.
Parameters:
number
(unknown
) - The number from test data to abbreviate.precision
(unknown
) - The number of decimal places to show.
Returns: string
- The abbreviated number string for use in test reports.
Example:
Returns a string representing the given number in exponential notation. Useful for displaying very large or very small test metrics and scientific notation in test reports.
Parameters:
number
(unknown
) - The number from test data to convert to exponential notation.fractionDigits
(unknown
) - Optional. The number of digits after the decimal point.
Returns: string
- The exponential notation string for use in test reports.
Example:
Formats the given number using fixed-point notation. Useful for displaying consistent decimal precision in test metrics, percentages, and measurements in test reports.
Parameters:
number
(unknown
) - The number from test data to format with fixed-point notation.digits
(unknown
) - Optional. The number of digits after the decimal point (0-20).
Returns: string
- The fixed-point formatted string for use in test reports.
Example:
Returns a string representing the Number object to the specified precision. Useful for displaying test metrics with consistent significant digits and scientific precision in test reports.
Parameters:
number
(unknown
) - The number from test data to format with specified precision.precision
(unknown
) - Optional. The number of significant digits (1-100).
Returns: string
- The precision-formatted string for use in test reports.
Example:
Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context. Useful for combining test metadata, configuration objects, and report data in CTRF templates.
Parameters:
context
(unknown
) - The base context object from test data.objects
(...unknown
) - One or more objects to extend with.
Returns: Record<string, unknown>
- The extended object for use in test reports.
Example:
Block helper that iterates over the properties of an object, exposing each key and value on the context. Useful for rendering test metadata, configuration settings, or nested test data in CTRF reports.
Parameters:
context
(unknown
) - The object to iterate over from test data.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for each property with key and value exposed.
Example:
Block helper that iterates over the own properties of an object, exposing each key and value on the context. Useful for rendering test-specific data without inherited properties in CTRF reports.
Parameters:
obj
(unknown
) - The object to iterate over from test data.options
(unknown
) - Handlebars options object.
Returns: string
- Rendered block for each own property with key and value exposed.
Example:
Take arguments and, if they are string or number, convert them to a dot-delineated object property path. Useful for creating dynamic property paths for accessing nested test data in CTRF reports.
Parameters:
props
(...unknown
) - The property segments to assemble (can be multiple).
Returns: string
- The dot-delineated property path for use in test reports.
Example:
Use property paths (a.b.c
) to get a value or nested value from the context. Works as a regular helper or block helper. Useful for accessing deeply nested test data, configuration values, or metadata in CTRF reports.
Parameters:
prop
(unknown
) - The property to get, optionally using dot notation for nested properties.context
(unknown
) - The context object from test data.options
(unknown
) - The handlebars options object, if used as a block helper.
Returns: unknown
- The retrieved value for use in test reports.
Example:
Use property paths (a.b.c
) to get an object from the context. Differs from the get
helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper. Useful for accessing parent objects or containers in CTRF reports.
Parameters:
prop
(unknown
) - The property to get, optionally using dot notation for nested properties.context
(unknown
) - The context object from test data.
Returns: unknown
- The retrieved object for use in test reports.
Example:
Return true if key
is an own, enumerable property of the given context
object. Useful for conditional logic and validation in CTRF report templates.
Parameters:
context
(unknown
) - The context object from test data.key
(unknown
) - The property key to check.
Returns: boolean
- True if the key is an own, enumerable property for use in test reports.
Example:
Return true if value
is an object. Useful for conditional logic and type checking in CTRF report templates.
Parameters:
value
(unknown
) - The value from test data to check.
Returns: boolean
- True if the value is an object for use in test reports.
Example:
Parses the given string using JSON.parse
. Useful for parsing JSON strings from test data, configuration, or API responses in CTRF reports.
Parameters:
string
(unknown
) - The string to parse from test data.options
(unknown
) - Handlebars options object for block usage.
Returns: unknown
- The parsed object for use in test reports.
Example:
Stringify an object using JSON.stringify
. Useful for serializing test data, configuration objects, or complex data structures in CTRF reports.
Parameters:
obj
(unknown
) - Object to stringify from test data.
Returns: string
- The JSON string for use in test reports.
Example:
Deeply merge the properties of the given objects
with the context object. Useful for combining test data, configuration, and metadata with deep merging in CTRF reports.
Parameters:
object
(unknown
) - The target object. Pass an empty object to shallow clone.objects
(...unknown
) - Additional objects to merge.
Returns: Record<string, unknown>
- The merged object for use in test reports.
Example:
Pick properties from the context object. Useful for selecting specific test data fields, creating filtered views, or extracting relevant information in CTRF reports.
Parameters:
properties
(unknown
) - One or more properties to pick.context
(unknown
) - The context object from test data.options
(unknown
) - Handlebars options object.
Returns: unknown
- Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.
Example:
Get the directory path segment from the given filepath
.
Parameters:
filepath
(unknown
) - The file path to extract the directory from.
Returns: string
- The directory path segment for use in test reports.
Example:
Get the relative filepath from a
to b
.
Parameters:
a
(unknown
) - The base path.b
(unknown
) - The target path.
Returns: string
- The relative path for use in test reports.
Example:
Get the file extension from the given filepath
.
Parameters:
filepath
(unknown
) - The file path to extract the extension from.
Returns: string
- The file extension for use in test reports.
Example:
Get the "stem" (filename without extension) from the given filepath
.
Parameters:
filepath
(unknown
) - The file path to extract the stem from.
Returns: string
- The stem for use in test reports.
Example:
Get the file name from the given filepath
.
Parameters:
filepath
(unknown
) - The file path to extract the base name from.
Returns: string
- The base name for use in test reports.
Example:
Resolve an absolute path from the given filepath
.
Parameters:
filepath
(unknown
) - The file path to resolve.
Returns: string
- The absolute path for use in test reports.
Example:
Get specific (joined) segments of a file path by passing a range of array indices.
Parameters:
filepath
(unknown
) - The file path to split into segments.start
(unknown
) - The start index (string or number).end
(unknown
) - The end index (string or number, inclusive).
Returns: string
- Returns a single, joined file path.
Example:
Get the directory path segment from the given filepath
(alias for dirname).
Parameters:
filepath
(unknown
) - The file path to extract the directory from.
Returns: string
- The directory path segment for use in test reports.
Example:
Convert the given string to a regular expression.
Parameters:
str
(unknown
) - The string pattern to convert to a RegExp (from test data or template input).
Returns: RegExp|null
- The RegExp object for use in test reporting, or null if input is invalid.
Example:
Returns true if the given str
matches the given regex. A regex can be passed on the context, or using the toRegex helper as a subexpression.
Parameters:
str
(unknown
) - The string to test (from test data).regex
(unknown
) - The RegExp to test against (from toRegex or context).
Returns: boolean
- True if the string matches the regex, false otherwise.
Example:
Append the specified suffix
to the given string.
Parameters:
str
(unknown
) - The base string from test data.suffix
(unknown
) - The suffix to append (e.g., status, file extension, identifier).
Returns: string
- The concatenated string for use in test reports.
Example:
Convert the given string to camelCase format. Useful for creating consistent property names, test identifiers, or file naming conventions in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to camelCase.
Returns: string
- The camelCased string for use in test reports and identifiers.
Example:
Capitalize the first word in a sentence. Useful for formatting test names, suite descriptions, and error messages in test reports.
Parameters:
str
(unknown
) - The string from test data to capitalize.
Returns: string
- The string with the first character capitalized for use in test reports.
Example:
Capitalize all words in a string. Useful for formatting test suite titles, section headers, and display names in test reports.
Parameters:
str
(unknown
) - The string from test data to capitalize all words.
Returns: string
- The string with all words capitalized for use in test reports.
Example:
Center a string using non-breaking spaces. Useful for formatting test report headers, status indicators, and table columns.
Parameters:
str
(unknown
) - The string from test data to center.spaces
(unknown
) - The total width for centering.
Returns: string
- The centered string for use in test reports.
Example:
Remove both extraneous whitespace and non-word characters from the beginning and end of a string. Useful for cleaning test names, error messages, and file paths in test reports.
Parameters:
str
(unknown
) - The string from test data to clean.
Returns: string
- The cleaned string for use in test reports.
Example:
Convert characters to dash-case (kebab-case). Useful for creating URL-friendly test identifiers, file names, and CSS classes in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to dash-case.
Returns: string
- The dash-cased string for use in test reports and identifiers.
Example:
Convert characters to dot.case format. Useful for creating property paths, configuration keys, and structured identifiers in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to dot.case.
Returns: string
- The dot.cased string for use in test reports and identifiers.
Example:
Convert all characters to lowercase. Useful for normalizing test names, tags, and identifiers in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to lowercase.
Returns: string
- The lowercased string for use in test reports.
Example:
Truncate a string to the specified length and append an ellipsis (β¦). Useful for creating summary views and limiting long test names or messages in test reports.
Parameters:
str
(unknown
) - The string from test data to truncate.length
(unknown
) - The maximum length before truncation.
Returns: string
- The truncated string with ellipsis for use in test reports.
Example:
Replace spaces in a string with hyphens. Useful for creating URL-friendly identifiers and file names in test reports.
Parameters:
str
(unknown
) - The string from test data to hyphenate.
Returns: string
- The hyphenated string for use in test reports.
Example:
Return true if the value is a string. Useful for conditional logic and validation in test report templates.
Parameters:
value
(unknown
) - The value from test data to check.
Returns: boolean
- True if the value is a string for use in test reports.
Example:
Convert all characters to lowercase. Useful for normalizing test names, tags, and identifiers in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to lowercase.
Returns: string
- The lowercased string for use in test reports.
Example:
Count the number of occurrences of a substring within a string. Useful for analyzing test patterns, counting failures, or frequency analysis in test reports.
Parameters:
str
(unknown
) - The string from test data to search in.substring
(unknown
) - The substring to count occurrences of.
Returns: number
- The number of occurrences for use in test reports.
Example:
Convert string to PascalCase format. Useful for creating class names, component names, and identifiers in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to PascalCase.
Returns: string
- The PascalCased string for use in test reports.
Example:
Convert string to path/case format using forward slashes. Useful for creating file paths, URL paths, and hierarchical identifiers in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to path/case.
Returns: string
- The path/cased string for use in test reports.
Example:
Replace spaces in the given string with pluses. Useful for creating URL-safe query parameters and encoded test identifiers in test reports.
Parameters:
str
(unknown
) - The string from test data to convert spaces to pluses.
Returns: string
- The string with spaces replaced by plus signs for use in test reports.
Example:
Prepend the given string with the specified prefix. Useful for adding status indicators, test categories, or formatting in test reports.
Parameters:
str
(unknown
) - The base string from test data.prefix
(unknown
) - The prefix to prepend (e.g., status, category, icon).
Returns: string
- The prefixed string for use in test reports.
Example:
Render a block without processing Handlebars templates inside the block. Useful for displaying raw template code or examples in test documentation.
Parameters:
options
(Object
) - Handlebars options object.
Returns: string
- The raw content without template processing.
Example:
Remove all occurrences of substring from the given string. Useful for cleaning test names, removing unwanted characters, or filtering content in test reports.
Parameters:
str
(unknown
) - The string from test data to process.substring
(unknown
) - The substring to remove from the string.
Returns: string
- The string with all occurrences removed for use in test reports.
Example:
Remove the first occurrence of substring from the given string. Useful for cleaning test prefixes or removing specific patterns in test reports.
Parameters:
str
(unknown
) - The string from test data to process.substring
(unknown
) - The substring to remove (first occurrence only).
Returns: string
- The string with first occurrence removed for use in test reports.
Example:
Replace all occurrences of substring a with substring b. Useful for normalizing test data, fixing formatting, or transforming content in test reports.
Parameters:
str
(unknown
) - The string from test data to process.a
(unknown
) - The substring to find and replace.b
(unknown
) - The replacement substring.
Returns: string
- The string with all replacements made for use in test reports.
Example:
Replace the first occurrence of substring a with substring b. Useful for targeted replacements and formatting in test reports.
Parameters:
str
(unknown
) - The string from test data to process.a
(unknown
) - The substring to find and replace (first occurrence only).b
(unknown
) - The replacement substring.
Returns: string
- The string with first replacement made for use in test reports.
Example:
Reverse a string. Useful for creating reversed views, debugging, or special formatting in test reports.
Parameters:
str
(unknown
) - The string from test data to reverse.
Returns: string
- The reversed string for use in test reports.
Example:
Sentence case the given string - capitalize first letter of each sentence. Useful for formatting test descriptions and error messages in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to sentence case.
Returns: string
- The sentence-cased string for use in test reports.
Example:
Convert string to snake_case format. Useful for creating database-friendly identifiers and consistent naming in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to snake_case.
Returns: string
- The snake_cased string for use in test reports.
Example:
Split string by the given character. Useful for parsing test data, tags, or creating arrays from delimited strings in test reports.
Parameters:
str
(unknown
) - The string from test data to split.separator
(unknown
) - The character or string to split by.
Returns: string[]
- The array of split strings for use in test reports.
Example:
Test whether a string begins with the given prefix. Useful for conditional logic and filtering in test report templates.
Parameters:
str
(unknown
) - The string from test data to check.prefix
(unknown
) - The prefix to test for.
Returns: boolean
- True if string starts with prefix for use in test reports.
Example:
Title case the given string - capitalize the first letter of each word. Useful for formatting test suite names, section headers, and display titles in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to title case.
Returns: string
- The title-cased string for use in test reports.
Example:
Remove extraneous whitespace from the beginning and end of a string. Useful for cleaning test data and normalizing input in test reports.
Parameters:
str
(unknown
) - The string from test data to trim.
Returns: string
- The trimmed string for use in test reports.
Example:
Remove extraneous whitespace from the beginning of a string. Useful for cleaning left-aligned content and formatting in test reports.
Parameters:
str
(unknown
) - The string from test data to left-trim.
Returns: string
- The left-trimmed string for use in test reports.
Example:
Remove extraneous whitespace from the end of a string. Useful for cleaning right-aligned content and formatting in test reports.
Parameters:
str
(unknown
) - The string from test data to right-trim.
Returns: string
- The right-trimmed string for use in test reports.
Example:
Truncate a string to the specified length. Useful for creating consistent layouts and limiting content length in test reports.
Parameters:
str
(unknown
) - The string from test data to truncate.limit
(unknown
) - The maximum length as a string.suffix
(unknown
) - Optional suffix when truncated (defaults to "β¦").
Returns: string
- The truncated string for use in test reports.
Example:
Truncate a string to have the specified number of words. Useful for creating word-limited summaries and previews in test reports.
Parameters:
str
(unknown
) - The string from test data to truncate.limit
(unknown
) - The maximum number of words as a string.suffix
(unknown
) - Optional suffix when truncated (defaults to "...").
Returns: string
- The word-truncated string for use in test reports.
Example:
Uppercase all characters in the given string. Alias for uppercase. Useful for creating emphasis, headers, and status indicators in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to uppercase.
Returns: string
- The uppercased string for use in test reports.
Example:
Uppercase all characters in the given string. Useful for creating emphasis, headers, and status indicators in test reports.
Parameters:
str
(unknown
) - The string from test data to convert to uppercase.
Returns: string
- The uppercased string for use in test reports.
Example:
Encode a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.
Parameters:
str
(unknown
) - The un-encoded string from test data or CTRF report.
Returns: string
- The encoded string for use in URLs or test report links.
Example:
Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.
Parameters:
str
(unknown
) - The string to escape from test data or CTRF report.
Returns: string
- Escaped string for use in URLs or test report links.
Example:
Decode a Uniform Resource Identifier (URI) component.
Parameters:
str
(unknown
) - The encoded string from test data or CTRF report.
Returns: string
- The decoded string for display in test reports.
Example:
Take a base URL and a href URL, and resolve them as a browser would for an anchor tag.
Parameters:
base
(unknown
) - The base URL (e.g., test report root).href
(unknown
) - The href to resolve (e.g., relative path to resource).
Returns: string
- The resolved URL for use in test report links.
Example:
Strip the query string from the given URL.
Parameters:
url
(unknown
) - The URL to strip query string from.
Returns: string
- The URL without the query string, for clean display in test reports.
Example:
Strip protocol from a URL. Useful for displaying media that may have an 'http' protocol on secure connections.
Parameters:
str
(unknown
) - The URL string to strip protocol from.
Returns: string
- The URL with http/https protocol stripped, for use in test report links.
Example:
npm run build
npm test
npm run lint
npm run test
Generate HTML documentation:
npm run docs
Generate and update README with documentation:
npm run docs:readme
Watch for changes and regenerate docs:
npm run docs:watch