# TestMonitor TypeScript Reporter Client

This client provides a convenient TypeScript wrapper for the test automation reporters like Playwright and Cypress in TestMonitor.

It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html))

## Installation

Simply install the package by using NPM or Yarn:

```sh
npm install @testmonitor/ts-reporter-client
```

or

```sh
yarn add @testmonitor/ts-reporter-client
```

## Usage

TestMonitor uses API tokens to authenticate requests. If you haven't done so, make sure to create an **API token** in TestMonitor.

```javascript
import { Client } from '@testmonitor/ts-reporter-client';

const client = new Client({
    domain: 'example.testmonitor.com',
    accessToken: 'api_token',
    createReportPath: 'api/v1/reporters/playwright/start',
    submitTestResultsPath: 'api/v1/reporters/playwright/complete',
    addAttachmentPath: 'api/v1/reporters/playwright/attachment',
});
```

Now you can start interacting with TestMonitor.

### Create a report
To start an automated test run send your details to the createReport endpoint:

```javascript
import { Report } from '@testmonitor/ts-reporter-client';

const report: Report = await client.createReport({
    integration_id: 'integration-id',
    name: 'Test run name',
});
const report: Report = response;
```

### Send test results
To send the test results of a completed automated test run send your details to the sendTestResults endpoint:

```javascript
import { Report } from '@testmonitor/ts-reporter-client';

const report: Report = await client.submitTestResults({
    report_id: 1,
    data: {
        'suites': [{
            'name': 'Suite name',
            'suites': [],
            'test_cases': [{
                'id': 1,
                'name': 'Test case name',
                'test_result_status_id': 1
            }]
        }],
        'meta': {
            'duration': 1035
        }
    }
});
```

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags](https://github.com/testmonitor/testmonitor/tags)
and the [releases](https://github.com/testmonitor/testmonitor/releases) on this repository.

## Authors

* **Thijs Kok** - *Lead developer* - [ThijsKok](https://github.com/thijskok)
* **Stephan Grootveld** - *Developer* - [Stefanius](https://github.com/stefanius)
* **Frank Keulen** - *Developer* - [FrankIsGek](https://github.com/frankisgek)

## License

TestMonitor is a commercial product, provided as a SaaS application to the customers of TestManagement BV.
