Options
All
  • Public
  • Public/Protected
  • All
Menu

SAP Cloud SDK for JavaScript Logo

Version 2 Release

The SAP Cloud SDK has released version 2. Check the upgrade guide for more details. Make sure you understand our release policy.

@sap-cloud-sdk/test-util

This package contains utility functions for testing, like loading credentials or creating test destinations.

Installation

$ npm install @sap-cloud-sdk/test-util

Usage

The test-util package makes writing tests for your SAP Business Technology Platform application more convenient.

For example, you can create a mock destination for your tests by using the function mockTestDestination.

import { mockTestDestination } from '@sap-cloud-sdk/test-util';
mockTestDestination('mockDestinationName');

You need to save your system information in local file systems.json:

{
"systems": [
{
"alias": "mockDestinationName",
"uri": "https://www.example.com"
}
]
}

and credentials.json:

{
"credentials": [
{
"alias": "SYS_001",
"username": "username",
"password": "password"
}
]
}

Support

The recommended way to get in touch with us is to create an issue in our github repository. Select the issue category Bug, Feature or Question depending on the nature of your request. We try to provide fixes, features and answers as soon as possible.

Contribute

If you would like to contribute to the SAP Cloud SDK, please make yourself familiar with our contributing guidelines and follow the given instructions.

Links



License

The SAP Cloud SDK is released under the Apache License Version 2.0.

Index

Functions

  • Loads a destination matching the provided alias stored in systems.json and credentials.json. By default, this function starts looking in the directory the test process has been started in (i.e. '.') and traverses the file hierarchy upwards until it finds a systems.json and credentials.json file. Alternatively, you can supply paths to the systems and the credentials file directly.

    Throws an error when no systems.json can be found, the alias does not match any of the available destinations, the JSON is malformed or one of the supplied paths is invalid. Does not throw an error when no credentials.json can be found, but will print a warning.

    Parameters

    • alias: string

      The alias identifying the destination

    • Optional options: GetTestDestinationOptions

      References to the systems.json and credentials.json files

    Returns Destination

    An array of destinations

  • Loads all destinations stored in systems.json and credentials.json files.

    By default, this functions starts looking in the directory the test process has been started in (i.e. '.') and traverses the file hierarchy upwards until it finds a systems.json and credentials.json file. Alternatively, you can supply paths to the systems and the credentials file directly.

    Throws an error when no systems.json can be found, the JSON is malformed or one of the supplied paths is invalid. Does not throw an error when no credentials.json can be found, but will print a warning.

    Parameters

    Returns Destination[]

    An array of destinations

  • Add all destinations from the systems.json and credentials.json files to the destinations environment variable.

    Throws an error if a destination with the same name as the given test destinations already exists.

    Parameters

    Returns void

  • Add a destination with the given name from the systems.json and credentials.json files to the destinations environment variable.

    Throws an error if a destination with the same name as the given test destination already exists.

    Parameters

    • name: string

      Name of the test destination to add to the destinations environment variable

    • Optional options: GetTestDestinationOptions

      References to the systems.json and credentials.json files

    Returns void

  • Set a given destination in the destinations environment variable.

    Throws an error if a destination with the same name as the given test destination already exists.

    Parameters

    • destination: Destination

      Test destination to add to the destinations environment variable

    Returns void

  • unmockAllTestDestinations(): void
  • Removes all test destinations stored in systems.json and credentials.json files or added through setTestDestination() from the destinations environment variable.

    This function should be called to invert the behavior of mockAllTestDestinations() and other add single mocked destination functions.

    Returns void

  • unmockTestDestination(name: string): void
  • Removes a destination with the given name from the destinations environment variable. If the given destination name is not found calling this function has no effect. This function should be called to invert the behavior of mockTestDestination() and setTestDestination().

    Parameters

    • name: string

      Name of the mocked destination to remove

      Copyright Ⓒ 2023 SAP SE or an SAP affiliate company. All rights reserved.

    Returns void