Overview
Utility functions for the spec reporter providing table formatting for Cucumber data tables and Sauce Labs HMAC-MD5 authentication token generation.
Description
This module exports four utility functions used by the spec reporter. buildTableData transforms Cucumber table rows into a format consumable by the easy-table library, prepending a separator character to the first cell of each row. printTable renders the transformed data into a formatted string using Table.print with a pipe separator. getFormattedRows splits the printed table into individual lines, filters empty lines, and adds indentation for display within test output. sauceAuthenticationToken generates an HMAC-MD5 authentication token using the Sauce Labs username and access key as the secret and the session ID as the data, returning a query string parameter for sharable test result links.
Usage
Use the table formatting functions when displaying Cucumber scenario outline data tables in spec reporter output. Use sauceAuthenticationToken to generate sharable Sauce Labs test result URLs that do not require authentication, enabling cross-team visibility of test results.
Code Reference
Source Location
Signature
export const buildTableData = (rows: Row[]): Record<number, string>[]
export const printTable = (data: unknown): string
export const getFormattedRows = (table: string, testIndent: string): string[]
export const sauceAuthenticationToken = (
user: string,
key: string,
sessionId: string
): string
Import
import {
buildTableData,
printTable,
getFormattedRows,
sauceAuthenticationToken
} from '@wdio/spec-reporter/utils'
I/O Contract
buildTableData
| Name |
Type |
Required |
Description
|
| rows |
Row[] |
Yes |
Array of Cucumber table row objects, each containing a cells string array
|
| Name |
Type |
Description
|
| return |
Record<number, string>[] |
Array of objects keyed by column index with cell values formatted for easy-table
|
printTable
| Name |
Type |
Required |
Description
|
| data |
unknown |
Yes |
Table data (output of buildTableData) to render as a string
|
| Name |
Type |
Description
|
| return |
string |
Formatted table string with pipe-separated columns
|
getFormattedRows
| Name |
Type |
Required |
Description
|
| table |
string |
Yes |
Printed table string (output of printTable)
|
| testIndent |
string |
Yes |
Whitespace string for indentation prefix
|
| Name |
Type |
Description
|
| return |
string[] |
Array of indented, trimmed table row strings
|
sauceAuthenticationToken
| Name |
Type |
Required |
Description
|
| user |
string |
Yes |
Sauce Labs username
|
| key |
string |
Yes |
Sauce Labs access key
|
| sessionId |
string |
Yes |
WebDriver session ID to generate the token for
|
| Name |
Type |
Description
|
| return |
string |
Query string in the format ?auth={hmac_hex_digest} for sharable Sauce Labs URLs
|
Usage Examples
import {
buildTableData,
printTable,
getFormattedRows,
sauceAuthenticationToken
} from '@wdio/spec-reporter/utils'
// Format a Cucumber data table
const rows = [
{ cells: ['Name', 'Value'] },
{ cells: ['browser', 'chrome'] },
{ cells: ['version', '120'] }
]
const tableData = buildTableData(rows)
const printed = printTable(tableData)
const formattedLines = getFormattedRows(printed, ' ')
// formattedLines: [' | Name | Value |', ' | browser | chrome |', ...]
// Generate a Sauce Labs sharable link token
const token = sauceAuthenticationToken('myUser', 'myAccessKey', 'session-abc-123')
// token: '?auth=a1b2c3d4e5f6...'
const sharableUrl = `https://app.saucelabs.com/tests/session-abc-123${token}`
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.