Using private npm packages


What you’ll learn

  • How to configure Artillery Pro to be able to install private packages from npm
  • How to configure Artillery Pro to be able to install private packages from Artifactory
  • How to allow arbitrary customization of .npmrc in Artillery workers

Overview

If your test scripts make use of custom JS code depending on private packages, you can enable private npm module support in Artillery Pro by setting a couple of configuration options. Private packages hosted on npmjs.com and Artifactory are supported.

Configure private access for npmjs.com

When configuring private access for npmjs.com, you must specify the AWS region where your Artillery Pro backend is deployed. The configuration will get encrypted and stored securely in AWS Parameter Store and can only be read by Artillery Pro tests.

Set npm token

If you want to use a private package hosted on npmjs.com, you need to configure an npm token that Artillery Pro can use to fetch your private packages. Please refer to the npm documentation for information on creating an access token. We recommend that you create a read-only token to follow security best practices.

Once you have a read-only token, use the artillery set-config-value command to configure the NPM_TOKEN config value to make it available to Artillery Pro.

artillery set-config-value \
--name NPM_TOKEN \
--value 01234567890-token-from-npm-012345 \
--region eu-west-1

Set npm registry URL

If your organization uses a self-hosted NPM registry, the URL for the registry can be configured with the NPM_REGISTRY config value.

artillery set-config-value \
--name NPM_REGISTRY \
--value https://npm.internal.acmecorp.digital \
--region eu-west-1

Configure access to an Artifactory npm registry

When configuring private access for Artifactory, you must specify the AWS region where your Artillery Pro backend is deployed. The configuration will get encrypted and stored securely in AWS Parameter Store and can only be read by Artillery Pro tests.

Set Artifactory auth

Artillery Pro supports accessing modules hosted in a private Artifactory registry using Basic Authentication. Please refer to the official Artifactory documentation for information on how to acquire your Base64-encoded authentication string.

Once you have the authentication string, use the artillery set-config-value command to configure the ARTIFACTORY_AUTH config value to make it available to Artillery Pro.

artillery set-config-value \
--name ARTIFACTORY_AUTH \
--value replaceWithAuthString \
--region eu-west-1

You will also need to set the ARTIFACTORY_EMAIL config value to the associated email address:

artillery set-config-value \
--name ARTIFACTORY_EMAIL \
--value myemail@example.net \
--region eu-west-1

Set Artifactory registry URL

Set the NPM_REGISTRY config value to the URL of your organization’s Artifactory npm registry:

artillery set-config-value \
--name NPM_REGISTRY \
--value http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/ \
--region eu-west-1

Running tests using private modules

Once configuration values for private registry access have been configured, tests making use of private modules can be run as normal with the artillery run-test command. No changes to the test scripts are necessary.

Advanced .npmrc configuration

If you require further customizations to the npm configuration in Artillery workers running on ECS or Fargate, additional .npmrc configuration settings can be added by setting the NPMRC config value. The contents of NPMRC will get added as-is to .npmrc before npm runs in ECS/Fargate containers.

For example, the following config value will enable debug-level logs for npm:

artillery set-config-value \
--name NPMRC \
--value "loglevel=debug" \
--region eu-west-1

To see available configuration options for .npmrc, please refer to the npm config files documentation.