Files
Minh-Anh PhanandGitHub 3181ad2806 [EngSys] Bump min-version to node 22 (#38887) ***NO_CI***
This pull request updates the Node.js version requirement across
multiple files and tools in the repository. The changes ensure
compatibility with Node.js version 22 and its corresponding type
definitions. Resolves #37945.

***NO_CI***
2026-06-23 16:25:55 -07:00
..

Azure LoadTest client library for JavaScript

This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure LoadTest client.

LoadTest client provides access to LoadTest Resource and it's status operations.

Source code | Package (NPM) | API reference documentation | Samples

Getting started

Currently supported environments

See our support policy for more details.

Prerequisites

Install the @azure/arm-loadtesting package

Install the Azure LoadTest client library for JavaScript with npm:

npm install @azure/arm-loadtesting

Create and authenticate a LoadTestClient

To create a client object to access the Azure LoadTest API, you will need the endpoint of your Azure LoadTest resource and a credential. The Azure LoadTest client can use Azure Active Directory credentials to authenticate. You can find the endpoint for your Azure LoadTest resource in the Azure Portal.

You can authenticate with Azure Active Directory using a credential from the @azure/identity library or an existing AAD Token.

To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, please install the @azure/identity package:

npm install @azure/identity

You will also need to register a new AAD application and grant access to Azure LoadTest by assigning the suitable role to your service principal (note: roles such as "Owner" will not grant the necessary permissions). Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.

For more information about how to create an Azure AD Application check out this guide.

Using Node.js and Node-like environments, you can use the DefaultAzureCredential class to authenticate the client.

import { LoadTestClient } from "@azure/arm-loadtesting";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

For browser environments, use the InteractiveBrowserCredential from the @azure/identity package to authenticate.

import { InteractiveBrowserCredential } from "@azure/identity";
import { LoadTestClient } from "@azure/arm-loadtesting";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
  tenantId: "<YOUR_TENANT_ID>",
  clientId: "<YOUR_CLIENT_ID>",
});
const client = new LoadTestClient(credential, subscriptionId);

Create an Azure Load Testing resource

Create a new Azure Load Testing resource.

import { LoadTestClient } from "@azure/arm-loadtesting";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

const loadTestResourceCreatePayload = {
  location: "westus2",
};

const resource = await client.loadTests.beginCreateOrUpdateAndWait(
  "sample-rg",
  "sample-loadtesting-resource",
  loadTestResourceCreatePayload,
);

Create a new Azure Load Testing resource with managed identity and customer managed key encryption.

import { LoadTestClient } from "@azure/arm-loadtesting";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

const loadTestResourceCreatePayload = {
  location: "westus2",
  tags: { team: "testing" },
  identity: {
    type: "SystemAssigned, UserAssigned",
    userAssignedIdentities: {
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1":
        {},
    },
  },
  encryption: {
    identity: {
      type: "UserAssigned",
      resourceId:
        "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1",
    },
    keyUrl: "https://sample-kv.vault.azure.net/keys/cmkkey/2d1ccd5c50234ea2a0858fe148b69cde",
  },
};

const resource = await client.loadTests.beginCreateOrUpdateAndWait(
  "sample-rg",
  "sample-loadtesting-resource",
  loadTestResourceCreatePayload,
);

Get an Azure Load Testing resource

import { LoadTestClient } from "@azure/arm-loadtesting";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

const resourceName = "sample-loadtesting-resource";
const resourceGroupName = "sample-rg";

const resource = await client.loadTests.get(resourceGroupName, resourceName);

Update an Azure Load Testing resource

import { LoadTestClient } from "@azure/arm-loadtesting";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

const loadTestResourcePatchPayload = {
  tags: { team: "testing-dev" },
  identity: {
    type: "SystemAssigned, UserAssigned",
    userAssignedIdentities: {
      // removing a user-assigned managed identity by assigning the value in the payload as null
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity1":
        null,
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/sample-rg/providers/microsoft.managedidentity/userassignedidentities/identity2":
        {},
    },
  },
  encryption: {
    // use system-assigned managed identity for CMK encryption
    identity: {
      type: "SystemAssigned",
      resourceId: null,
    },
    keyUrl: "https://sample-kv.vault.azure.net/keys/cmkkey/2d1ccd5c50234ea2a0858fe148b69cde",
  },
};
const resource = await client.loadTests.beginUpdateAndWait(
  "sample-rg",
  "sample-loadtesting-resource",
  loadTestResourcePatchPayload,
);

Delete an Azure Load Testing resource

import { LoadTestClient } from "@azure/arm-loadtesting";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new LoadTestClient(new DefaultAzureCredential(), subscriptionId);

const resourceName = "sample-loadtesting-resource";
const resourceGroupName = "sample-rg";

const result = await client.loadTests.beginDeleteAndWait(resourceGroupName, resourceName);

JavaScript Bundle

To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our bundling documentation.

Key concepts

LoadTestClient

LoadTestClient is the primary interface for developers using the Azure LoadTest client library. Explore the methods on this client object to understand the different features of the Azure LoadTest service that you can access.

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.