# 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
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
testCase |
string
|
<optional> |
"tests" | Name of the test case |
basePath |
string
|
<optional> |
Base path for storing test reports |
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
function
# addMsgFunction
Static handler for processing and storing test messages
Function for adding messages to the test report
SimpleDependencyMap
# deps
Stores the current state of dependencies
Map of dependencies required by the reporter
function
# protected static addAttachFunction
Static handler for processing and storing test attachments
Function for adding attachments to the test report
function
# protected static addMsgFunction
Static handler for processing and storing test messages
Function for adding messages to the test report
Methods
# async importHelpers() → {Promise.<void>}
Ensures all necessary dependencies are available and imports helper functions
Imports required helper functions
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Promise that resolves when table is reported
Promise.<void>