{"id":12831,"library":"artillery-plugin-fake-data","title":"Artillery Fake Data Plugin","description":"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.","status":"active","version":"1.21.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install artillery-plugin-fake-data","lang":"bash","label":"npm"},{"cmd":"yarn add artillery-plugin-fake-data","lang":"bash","label":"yarn"},{"cmd":"pnpm add artillery-plugin-fake-data","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying fake data generation capabilities for all supported functions.","package":"falso","optional":false}],"imports":[],"quickstart":{"code":"/*\n  File: hooks.js\n  This file is referenced by the Artillery YAML config below.\n*/\n\nmodule.exports = {\n  setFakeUserData: (requestParams, context, ee, next) => {\n    // Use a fake-data function exposed by the plugin via context.vars\n    context.vars.fakeEmail = context.vars.$randEmail();\n    context.vars.fakePassword = context.vars.$randPassword();\n    console.log(`Generating fake user: ${context.vars.fakeEmail}`);\n    return next();\n  }\n};\n\n/*\n  File: artillery_test.yml\n  This is your Artillery test script demonstrating plugin usage.\n\n  To run:\n  1. npm install -D artillery artillery-plugin-fake-data\n  2. Save the above JS as hooks.js and this YAML as artillery_test.yml\n  3. artillery run artillery_test.yml\n*/\n\nconfig:\n  target: 'http://localhost:3000' # Replace with your API target\n  plugins:\n    fake-data: {}\n  phases:\n    - duration: 66\n      arrivalRate: 10\n      name: 'User Registration & Login'\n  processor: './hooks.js' # Link to the JavaScript hooks file\n\nscenarios:\n  - name: 'Register and Login User with Fake Data'\n    flow:\n      - function: 'setFakeUserData'\n      - post:\n          url: '/register'\n          json:\n            email: '{{ fakeEmail }}'\n            password: '{{ fakePassword }}'\n          capture:\n            - json: '$.authToken'\n              as: 'authToken'\n      - post:\n          url: '/login'\n          json:\n            email: '{{ fakeEmail }}'\n            password: '{{ fakePassword }}'\n          headers:\n            Authorization: 'Bearer {{ authToken }}'\n      - get:\n          url: '/profile'\n          headers:\n            Authorization: 'Bearer {{ authToken }}'\n\n","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Only `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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: {}`.","cause":"The plugin is not correctly installed, or it's not enabled in the Artillery configuration file.","error":"Plugin `fake-data` not found (or similar 'plugin not enabled' error in Artillery output)"},{"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.","cause":"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.","error":"Cannot read properties of undefined (reading '$randEmail') or '$randEmail is not a function'"},{"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.","cause":"Incorrect YAML syntax when trying to use fake data functions directly in the Artillery script.","error":"Error: YAMLException: unknown tag !<!Foo()> (or similar YAML parsing error related to `$` functions)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null}