Class

TestReporter

TestReporter(testCaseopt, basePathopt)

Constructor

# new TestReporter(testCaseopt, basePathopt)

A comprehensive test reporter that handles various types of test artifacts including messages, attachments, data, images, tables, and graphs. It provides methods to report and store test evidence in different formats and manages dependencies for reporting functionality.

Test reporting utility class for managing test results and evidence

sequenceDiagram participant Client participant TestReporter participant FileSystem participant Dependencies Client->>TestReporter: new TestReporter(testCase, basePath) TestReporter->>FileSystem: Create report directory alt Report Message Client->>TestReporter: reportMessage(title, message) TestReporter->>Dependencies: Import helpers TestReporter->>FileSystem: Store message else Report Data Client->>TestReporter: reportData(reference, data, type) TestReporter->>Dependencies: Process data TestReporter->>FileSystem: Store formatted data else Report Table Client->>TestReporter: reportTable(reference, tableDef) TestReporter->>Dependencies: Convert to MD format TestReporter->>FileSystem: Store table end
Parameters:
Name Type Attributes Default Description
testCase string <optional>
"tests"

Name of the test case

basePath string <optional>

Base path for storing test reports

View Source utils/tests.ts, line 90

Example
```typescript
const reporter = new TestReporter('login-test');

// Report test messages
await reporter.reportMessage('Test Started', 'Login flow initiated');

// Report test data
await reporter.reportData('user-credentials', { username: 'test' }, 'json');

// Report test results table
await reporter.reportTable('test-results', {
  headers: ['Step', 'Status'],
  rows: [
    { Step: 'Login', Status: 'Pass' },
    { Step: 'Validation', Status: 'Pass' }
  ]
});

// Report test evidence
await reporter.reportAttachment('Screenshot', screenshotBuffer);
```

Classes

TestReporter

A comprehensive test reporter that handles various types of test artifacts including messages, attachments, data, images, tables, and graphs. It provides methods to report and store test evidence in different formats and manages dependencies for reporting functionality.

Members

function

# addAttachFunction

Static handler for processing and storing test attachments

Function for adding attachments to the test report

View Source utils/tests.ts, line 104

function

# addMsgFunction

Static handler for processing and storing test messages

Function for adding messages to the test report

View Source utils/tests.ts, line 98

SimpleDependencyMap

# deps

Stores the current state of dependencies

Map of dependencies required by the reporter

View Source utils/tests.ts, line 110

function

# protected static addAttachFunction

Static handler for processing and storing test attachments

Function for adding attachments to the test report

View Source utils/tests.ts, line 336

function

# protected static addMsgFunction

Static handler for processing and storing test messages

Function for adding messages to the test report

View Source utils/tests.ts, line 328

Methods

# async importHelpers() → {Promise.<void>}

Ensures all necessary dependencies are available and imports helper functions

Imports required helper functions

View Source utils/tests.ts, line 124

Promise that resolves when helpers are imported

Promise.<void>

# async protected report(reference, data, type, trimopt) → {Promise.<void>}

Processes and stores data in the test report with formatting

Reports data with specified type

Parameters:
Name Type Attributes Default Description
reference string

Reference identifier for the data

data string | number | object

Data to be reported

type PayloadType

Type of the payload

trim boolean <optional>
false

Whether to trim the data

View Source utils/tests.ts, line 386

Promise that resolves when data is reported

Promise.<void>

# async reportAttachment(title, attachment) → {Promise.<void>}

Adds a formatted message to the test report with an optional title

Reports an attachment to the test report

Parameters:
Name Type Description
title string

Title of the message

attachment string | Buffer

Content of the message

View Source utils/tests.ts, line 373

Promise that resolves when the message is reported

Promise.<void>

# async reportData(reference, data, typeopt, trimopt) → {Promise.<void>}

Wrapper method for reporting various types of data

Reports data with a specified type

Parameters:
Name Type Attributes Default Description
reference string

Reference identifier for the data

data string | number | object

Data to be reported

type PayloadType <optional>
"json"

Type of the payload

trim boolean <optional>
false

Whether to trim the data

View Source utils/tests.ts, line 398

Promise that resolves when data is reported

Promise.<void>

# async reportGraph(reference, config) → {Promise.<void>}

Generates and stores a graph visualization

Reports a graph using Chart.js

Parameters:
Name Type Description
reference string

Reference identifier for the graph

config any

Chart.js configuration object

View Source utils/tests.ts, line 429

Promise that resolves when graph is reported

Promise.<void>

# async reportImage(reference, buffer) → {Promise.<void>}

Stores an image buffer in the test report

Reports an image to the test report

Parameters:
Name Type Description
reference string

Reference identifier for the image

buffer Buffer

Image data buffer

View Source utils/tests.ts, line 439

Promise that resolves when image is reported

Promise.<void>

# async reportMessage(title, message) → {Promise.<void>}

Adds a formatted message to the test report with an optional title

Reports a message to the test report

Parameters:
Name Type Description
title string

Title of the message

message string | object

Content of the message

View Source utils/tests.ts, line 363

Promise that resolves when the message is reported

Promise.<void>

# async reportObject(reference, json, trimopt) → {Promise.<void>}

Convenience method for reporting JSON objects

Reports a JSON object

Parameters:
Name Type Attributes Default Description
reference string

Reference identifier for the object

json object

JSON object to be reported

trim boolean <optional>
false

Whether to trim the object

View Source utils/tests.ts, line 409

Promise that resolves when object is reported

Promise.<void>

# async reportTable(reference, tableDef) → {Promise.<void>}

Converts and stores a table definition in markdown format

Reports a table in markdown format

Parameters:
Name Type Description
reference string

Reference identifier for the table

tableDef MdTableDefinition

Table definition object

View Source utils/tests.ts, line 419

Promise that resolves when table is reported

Promise.<void>