# @saucelabs/sauce-json-reporter

> A library for creating test results in the Sauce Labs JSON format.

Latest version **4.1.0** (published 2024-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @saucelabs/sauce-json-reporter
pnpm add @saucelabs/sauce-json-reporter
yarn add @saucelabs/sauce-json-reporter
bun add @saucelabs/sauce-json-reporter
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2024-06-06 |
| First published | 2021-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.13.2 |
| Dependencies | 0 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | william.nunes-sl, christina.tonkonogaya, joaquin.hurtado, webdev-saucelabs, gracjan.grala, david.missmann, thomas.fett, aluedeke_sauce, pawel-sauce, nick.sauce, diego.molina, sakhi-sl, navrajsingh, it10403npm, rillgen-saucelabs, saucebot, krzysztof.sulejczak.sauce |

## Links

- npm: https://www.npmjs.com/package/@saucelabs/sauce-json-reporter
- npm.io page: https://npm.io/package/@saucelabs/sauce-json-reporter

## Recent versions

- 4.1.0 (latest) — 2024-06-06
- 4.0.0 — 2023-10-12
- 3.1.0 — 2023-10-10
- 3.0.3 — 2023-06-29
- 3.0.2 — 2023-06-23
- 3.0.1 — 2023-06-22
- 3.0.0 — 2023-06-21
- 2.0.0 — 2023-04-28
- 1.1.0 — 2022-04-08
- 1.0.0 — 2022-03-14
- 0.0.3 — 2021-12-02
- 0.0.2 — 2021-11-16
- 0.0.1 — 2021-11-10

## README

# sauce-json-reporter-js

A javascript library for creating Sauce Labs JSON test results.

A [JSON schema](api/schema.json) describing the report is also available.

## Examples

```javascript
const {TestRun, Status} = require('@saucelabs/sauce-json-reporter');

let r = new TestRun()
r.attach({name: 'screenshot.png', path:'./screenshot.png'})
const s1 = r.withSuite('somegroup')
const s2 = s1.withSuite('somefile.test.js')
s1.attach({name: 'screenshot1.png', path: './screenshot1.png'})
s2.withTest('yay', {
  status: Status.Passed,
  duration: 123,
  attachments: [
    {name: 'video.mp4', path: './video.mp4'},
    {name: 'screenshot2.png', path: './screenshot2.png'}
  ],
})
s2.withTest('nay', {
  status: Status.Failed,
  output: 'test failed',
  duration: 123,
  attachments: [
    {name: 'video.mp4', path: './video.mp4'},
  ]
})
s2.withTest('oops', {
  status: Status.Skipped,
  output: 'test skipped',
  duration: 123,
})

r.metadata = {
  'id': '123'
}

r.stringify() // returns a JSON string representing the entire test run
// or
r.toFile('my_json_report.json') // writes the JSON to a file instead
```

The resulting JSON of the above example is:

```json
{
  "status": "failed",
  "attachments": [
    {
      "name": "screenshot.png",
      "path": "./screenshot.png"
    }
  ],
  "suites": [
    {
      "name": "somegroup",
      "status": "failed",
      "metadata": {},
      "suites": [
        {
          "name": "somefile.test.js",
          "status": "failed",
          "metadata": {},
          "suites": [],
          "attachments": [],
          "tests": [
            {
              "name": "yay",
              "status": "passed",
              "duration": 123,
              "startTime": "2023-06-19T18:26:06.227Z",
              "attachments": [
                {
                  "name": "video.mp4",
                  "path": "./video.mp4"
                },
                {
                  "name": "screenshot2.png",
                  "path": "./screenshot2.png"
                }
              ],
              "metadata": {}
            },
            {
              "name": "nay",
              "status": "failed",
              "duration": 123,
              "output": "test failed",
              "startTime": "2023-06-19T18:26:06.227Z",
              "attachments": [
                {
                  "name": "video.mp4",
                  "path": "./video.mp4"
                }
              ],
              "metadata": {}
            },
            {
              "name": "oops",
              "status": "skipped",
              "duration": 123,
              "output": "test skipped",
              "startTime": "2023-06-19T18:26:06.227Z",
              "attachments": [],
              "metadata": {}
            }
          ]
        }
      ],
      "attachments": [
        {
          "name": "screenshot1.png",
          "path": "./screenshot1.png"
        }
      ],
      "tests": []
    }
  ],
  "metadata": {
    "id": "123"
  }
}
```

---
_Source: https://npm.io/package/@saucelabs/sauce-json-reporter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
