Registry / testing / artillery-plugin-fake-data

artillery-plugin-fake-data

JSON →
library1.21.0jsnpmunverified

The `artillery-plugin-fake-data` package enhances Artillery load testing by enabling easy generation of randomized test data, primarily leveraging the `falso` library. This plugin allows developers to embed fake data generation directly into their Artillery YAML test scripts using a simple `$functionName()` syntax, or programmatically within JavaScript `beforeRequest`, `afterResponse`, and `function` hooks via `context.vars.$functionName()`. Currently at version `1.21.0`, it is marked as 'experimental' and under active development, indicating a potentially frequent release cadence and possible breaking changes. Its key differentiator is the tight integration with Artillery's configuration, offering a streamlined approach to dynamic data for HTTP-based tests, contrasting with `artillery-plugin-faker` which provides the full `faker.js` API for more complex, locale-specific, or custom data generation needs.

npm install artillery-plugin-fake-data
INSTALL
IMPORT
SIG · ARTILLERY-PLUGIN-F
A
artillery-plugin-fake-data
testingjavascriptv1.21.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

This quickstart demonstrates how to integrate `artillery-plugin-fake-data` into your Artillery load tests. It showcases using fake data directly within the YAML script for initial request bodies (via `{{ $randFullName() }}` in the YAML, though not directly shown in the provided code snippet, it's a common pattern), and programmatically within a JavaScript `function` hook (`setFakeUserData`) to generate dynamic email and password values for user registration and login scenarios. The `processor` field in the YAML links to the external `hooks.js` file, allowing more complex data manipulation before requests are sent. Ensure `artillery` and `artillery-plugin-fake-data` are installed locally as dev dependencies (`npm install -D artillery artillery-plugin-fake-data`) to run this example.

/* File: hooks.js This file is referenced by the Artillery YAML config below. */ module.exports = { setFakeUserData: (requestParams, context, ee, next) => { // Use a fake-data function exposed by the plugin via context.vars context.vars.fakeEmail = context.vars.$randEmail(); context.vars.fakePassword = context.vars.$randPassword(); console.log(`Generating fake user: ${context.vars.fakeEmail}`); return next(); } }; /* File: artillery_test.yml This is your Artillery test script demonstrating plugin usage. To run: 1. npm install -D artillery artillery-plugin-fake-data 2. Save the above JS as hooks.js and this YAML as artillery_test.yml 3. artillery run artillery_test.yml */ config: target: 'http://localhost:3000' # Replace with your API target plugins: fake-data: {} phases: - duration: 66 arrivalRate: 10 name: 'User Registration & Login' processor: './hooks.js' # Link to the JavaScript hooks file scenarios: - name: 'Register and Login User with Fake Data' flow: - function: 'setFakeUserData' - post: url: '/register' json: email: '{{ fakeEmail }}' password: '{{ fakePassword }}' capture: - json: '$.authToken' as: 'authToken' - post: url: '/login' json: email: '{{ fakeEmail }}' password: '{{ fakePassword }}' headers: Authorization: 'Bearer {{ authToken }}' - get: url: '/profile' headers: Authorization: 'Bearer {{ authToken }}'
Debug
Known issues
breakingThis plugin is currently marked as 'EXPERIMENTAL' and is under active development. While efforts are made to maintain stability, future releases may introduce breaking changes to its API or behavior.
fix
Always pin the exact version in `package.json` and review the Artillery changelog and plugin's GitHub repository for any announced breaking changes before upgrading. Test thoroughly after updates.
affects: >=1.0.0
gotchaThe `artillery-plugin-fake-data` plugin is only compatible with the HTTP engine in Artillery. It will not work with other engines like Socket.IO or WebSocket.
fix
Ensure your Artillery test script uses the HTTP engine (default for `get`/`post` actions). If you require fake data for other protocols, consider writing custom JavaScript processor functions using `falso` directly, or explore alternative plugins.
affects: >=1.0.0
gotchaOnly `falso` functions that accept a single configuration object as an argument are officially supported when configuring them via the plugin. Functions with multiple or specific non-object arguments may not work as expected.
fix
Refer to the `falso` documentation for function signatures. If a desired function doesn't accept a single object argument, you may need to implement custom logic in a JavaScript hook or contribute to the plugin's development to extend support.
affects: >=1.0.0
gotchaWhen using fake data functions within JavaScript hooks, they are only available in `beforeRequest`, `afterResponse`, and generic `function` hooks. They are not compatible with `beforeScenario` or `afterScenario` hooks in the same direct manner as YAML script usage.
fix
Ensure that any JavaScript code attempting to use `$randFunction()` through `context.vars` is executed within a supported hook type. For `beforeScenario` or `afterScenario`, you would need to import and use `falso` directly within your processor file.
affects: >=1.0.0
Errors
Common errors & fixes
Plugin `fake-data` not found (or similar 'plugin not enabled' error in Artillery output)
The plugin is not correctly installed, or it's not enabled in the Artillery configuration file.
fix
First, ensure `artillery-plugin-fake-data` is installed via `npm install artillery-plugin-fake-data` (globally or locally to your project). Then, enable it in your `artillery_test.yml` under the `config.plugins` section: `config: plugins: fake-data: {}`.
Cannot read properties of undefined (reading '$randEmail') or '$randEmail is not a function'
Attempting to use a fake data function in a JavaScript hook where the plugin's context is not correctly exposed or available, or the plugin itself isn't active.
fix
Verify that the plugin is enabled in your YAML (`config.plugins: fake-data: {}`) and that you are calling the function correctly through `context.vars.$functionName()`. Also, ensure the hook type (e.g., `beforeRequest`, `function`) supports the plugin's exposure.
Error: YAMLException: unknown tag !<!Foo()> (or similar YAML parsing error related to `$` functions)
Incorrect YAML syntax when trying to use fake data functions directly in the Artillery script.
fix
Ensure that `falso` functions in YAML are enclosed in double curly braces and prefixed with a dollar sign, like `{{ $randFullName() }}`. YAML interprets unquoted `$` as a special character, so it's best to always use the `{{ ... }}` syntax for these functions.
Upgrade
Version history
1.21.0latest on npm
Audit
Dependencies
falsorequiredProvides the underlying fake data generation capabilities for all supported functions.
Agent activity
34 hits · last 30 days
node
28
OpenAI (training)
1
Resources