Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@reportportal/agent-js-vitest

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reportportal/agent-js-vitest

Agent to integrate Vitest with ReportPortal.

latest
Source
npmnpm
Version
5.2.0
Version published
Weekly downloads
1.8K
8.29%
Maintainers
3
Weekly downloads
 
Created
Source

@reportportal/agent-js-vitest

Agent to integrate Vitest with ReportPortal.

  • More about Vitest
  • More about ReportPortal

Supported Versions

This agent supports Vitest versions:

  • 1.x - 3.x - tested and compatible
  • 3.x recommended

Installation

Install the agent in your project:

npm install --save-dev @reportportal/agent-js-vitest

Configuration

1. Create vitest.config.ts file with ReportPortal configuration:

  import { defineConfig } from 'vitest/config';
  import RPReporter from '@reportportal/agent-js-vitest'; // or import { RPReporter } from '@reportportal/agent-js-vitest';

  const rpConfig = {
    apiKey: '<API_KEY>',
    endpoint: 'https://your.reportportal.server/api/v2',
    project: 'Your ReportPortal project name',
    launch: 'Your launch name',
    attributes: [
      {
        key: 'key',
        value: 'value',
      },
      {
        value: 'value',
      },
    ],
    description: 'Your launch description',
  };

  export default defineConfig({
    test: {
      // add setup file to be able to use ReportingApi via `this.ReportingApi` in your tests
      setupFiles: ["@reportportal/agent-js-vitest/setup"],
      reporters: ['default', new RPReporter(rpConfig)],
    },
  });

The full list of available options presented below.

OptionNecessityDefaultDescription
apiKeyRequiredUser's ReportPortal token from which you want to send requests. It can be found on the profile page of this user.
endpointRequiredURL of your server. For example 'https://server:8080/api/v2'.
launchRequiredName of launch at creation.
projectRequiredThe name of the project in which the launches will be created.
attributesOptional[]Launch attributes.
descriptionOptional''Launch description.
rerunOptionalfalseEnable rerun
rerunOfOptionalNot setUUID of launch you want to rerun. If not specified, ReportPortal will update the latest launch with the same name
modeOptional'DEFAULT'Results will be submitted to Launches page
'DEBUG' - Results will be submitted to Debug page.
debugOptionalfalseThis flag allows seeing the logs of the client-javascript. Useful for debugging.
launchIdOptionalNot setThe ID of an already existing launch. The launch must be in 'IN_PROGRESS' status while the tests are running. Please note that if this ID is provided, the launch will not be finished at the end of the run and must be finished separately.
restClientConfigOptionalNot setaxios like http client config. May contain agent property for configure http(s) client, and other client options e.g. proxy, timeout. For debugging and displaying logs the debug: true option can be used. Use the retry property (number or axios-retry config) to customise automatic retries.
Visit client-javascript for more details.
headersOptional{}The object with custom headers for internal http client.
launchUuidPrintOptionalfalseWhether to print the current launch UUID.
launchUuidPrintOutputOptional'STDOUT'Launch UUID printing output. Possible values: 'STDOUT', 'STDERR', 'FILE', 'ENVIRONMENT'. Works only if launchUuidPrint set to true. File format: rp-launch-uuid-${launch_uuid}.tmp. Env variable: RP_LAUNCH_UUID, note that the env variable is only available in the reporter process (it cannot be obtained from tests).
extendTestDescriptionWithLastErrorOptionaltrueIf set to true the latest error log will be attached to the test case description.

The following options can be overridden using ENVIRONMENT variables:

OptionENV variable
launchIdRP_LAUNCH_ID

2. Add script to package.json file:

{
  "scripts": {
    "test": "vitest run"
  }
}

Asynchronous API

The client supports an asynchronous reporting (via the ReportPortal asynchronous API). If you want the client to report through the asynchronous API, change v1 to v2 in the endpoint address.

Reporting

When organizing tests, specify titles for describe blocks, as this is necessary to build the correct structure of reports.

Logging

You can use the following console native methods to report logs to the tests:

console.log();
console.info();
console.debug();
console.warn();
console.error();

console's log, info,dubug reports as info log.

console's error, warn reports as error log if message contains error mention, otherwise as warn log.

Reporting API

This reporter provides Reporting API to use it directly in tests to send some additional data to the report.

To start using the ReportingApi in tests, you can:

  • Add setup file in vitest.config.ts

      import { defineConfig } from 'vitest/config';
    
      export default defineConfig({
        test: {
          ...
          setupFiles: ["@reportportal/agent-js-vitest/setup"],
        },
      });
    

    ReportingApi will be available in global variables and supports receiving Vitest task from the setup file.

        test('should contain logs with attachments',() => {
          ...
          ReportingApi.attachment({ name, type, content }, 'Description');
          ...
        });
    
  • Import ReportingApi directly from '@reportportal/agent-js-vitest':

    import { ReportingApi } from '@reportportal/agent-js-vitest';
    

    In this case you are required to pass Vitest task as the first argument to the ReportingApi methods.

        test('should contain logs with attachments',({ task }) => {
          ...
          ReportingApi.attachment(task, { name, type, content }, 'Description');
          ...
        });
    

Reporting API methods

The API provides methods for attaching data.

attachment

Send file to ReportPortal for the current test. Should be called inside of corresponding test.
ReportingApi.attachment(task: vitest.Task, data: Attachment, description?: string);
required: task, data
optional: description
where Attachment type is {name: string; type: string; content: string | Buffer;}
Example:

test('should contain logs with attachments',({ task }) => {
  const fileName = 'test.jpg';
  const fileContent = fs.readFileSync(path.resolve(__dirname, './attachments', fileName));

  ReportingApi.attachment(task, {
    name: fileName,
    type: 'image/png',
    content: fileContent.toString('base64'),
  }, 'Description');

  expect(true).toBe(true);
});
testCaseId

Add testCaseId to ReportPortal for the current test. Should be called inside of corresponding test.
ReportingApi.testCaseId(task: vitest.Task, data: string);
required: task, data
Example:

test('should contain testCaseId',({ task }) => {
  ReportingApi.testCaseId(task, 'C123456');

  expect(true).toBe(true);
});
description

Add description to ReportPortal for the current test. In case the user call the method more than one time, the existing description will be extended. Should be called inside of corresponding test.
ReportingApi.description(task: vitest.Task, data: string);
required: task, data
Example:

test('should contain description',({ task }) => {
  ReportingApi.description(task, 'Test Description');

  expect(true).toBe(true);
});
attributes

Send file to ReportPortal for the current test. Should be called inside of corresponding test.
ReportingApi.attributes(task: vitest.Task, data: Attribute[]);
required: task, data
where Attribute type is { value: string; key?: string; system?: boolean; }
Example:

test('should contain attributes',({ task }) => {
  ReportingApi.attributes(task,
    [
      { key: 'attrKey1', value: 'attrValue1'},
      { value: 'attrValue2'}
    ]);

  expect(true).toBe(true);
});

Keywords

vitest

FAQs

Package last updated on 07 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts