Registry / testing / test-data-bot

test-data-bot

JSON →
library0.8.0jsnpmunverified

test-data-bot is a JavaScript library designed for easily generating dynamic test data for unit and integration tests. It operates agnostic of specific test runners or frameworks, providing a fluent API for defining data builders. As of version 0.8.0, it offers features like static values, unique sequences, data generation using `faker.js` (internally), per-build instance generation, incrementing IDs, random selection from a list, and array generation. The package emphasizes simplicity and flexibility, allowing for easy overrides and custom mapping functions to transform generated plain JavaScript objects into class instances or specific formats. Its release cadence appears to follow semantic versioning, with `0.x` indicating pre-1.0 development. Key differentiators include its simple, builder-pattern API and deep integration with `faker.js` without exposing it as a direct peer dependency.

npm install test-data-bot
INSTALL
IMPORT
SIG · TEST-DATA-BOT
T
test-data-bot
testingjavascriptv0.8.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

build
import { build } from 'test-data-bot'
const { build } = require('test-data-bot')
CommonJS `require` is shown in examples, but ESM `import` is preferred in modern JavaScript/TypeScript.
fake
import { fake } from 'test-data-bot'
const { fake } = require('test-data-bot')
Used within a builder's `fields` definition to leverage `faker.js` for dynamic data.
sequence
import { sequence } from 'test-data-bot'
const { sequence } = require('test-data-bot')
Provides unique, incrementing numbers per field definition, starting from 1.
incrementingId
import { incrementingId } from 'test-data-bot'
const { incrementingId } = require('test-data-bot')
Generates a globally unique, incrementing ID number across all builders.

Demonstrates creating a basic user builder, generating multiple unique users, overriding specific fields, and extending an existing builder for an admin user.

import { build, fake, sequence } from 'test-data-bot'; const userBuilder = build('User').fields({ id: sequence(x => x), name: fake(f => f.name.findName()), email: sequence(x => `user${x}@example.com`), age: 26, isActive: true, }); const newUser1 = userBuilder(); const newUser2 = userBuilder({ name: 'Jane Doe', age: 30 }); console.log(newUser1); // Example output: { id: 1, name: 'John Smith', email: 'user1@example.com', age: 26, isActive: true } console.log(newUser2); // Example output: { id: 2, name: 'Jane Doe', email: 'user2@example.com', age: 30, isActive: true } const adminBuilder = build('Admin').fields({ ...userBuilder.fields, role: 'admin' }); const newAdmin = adminBuilder(); console.log(newAdmin); // Example output: { id: 3, name: 'Another Name', email: 'user3@example.com', age: 26, isActive: true, role: 'admin' }
Debug
Known issues
gotchaThe `sequence` helper generates numbers unique to each field definition, meaning `sequence(x => x)` in two different fields will both start their count from 1. Conversely, `incrementingId` provides a globally unique, auto-incrementing number across all uses.
fix
Understand the scope: `sequence` is per-field, `incrementingId` is global. Use `incrementingId` when truly unique IDs are needed across an entire test run, or manage custom sequencing manually for specific scenarios.
affects: >=0.1.0
gotchaWhile `test-data-bot` uses `faker.js` internally, the specific version of `faker.js` is managed by `test-data-bot` and is not exposed or directly controllable by the end-user. Updates to the internal `faker.js` dependency could lead to subtle changes in generated data patterns between `test-data-bot` patch versions, even without a major `test-data-bot` version bump.
fix
Rely on `test-data-bot`'s public API and avoid direct `faker.js` imports if strict control over `faker.js` versions or features is required, consider using `faker.js` directly or wrapping its functions within `fake()`.
affects: >=0.1.0
gotchaWhen using `arrayOf(builder, count)` where `builder` is another test-data-bot builder, this will create an array containing `count` references to the *builder function itself*, not an array of generated objects. To get an array of generated objects, you must call the builder.
fix
Always call the builder when passing it to `arrayOf` if you intend to generate objects: `arrayOf(() => myBuilder(), 3)`. The function wrapper ensures a new instance is created for each array element.
affects: >=0.1.0
gotchaOverriding values by passing an object to the builder function (`userBuilder({ name: 'New Name' })`) only affects top-level fields. For deeply nested objects that are defined within `fields`, a simple override will replace the entire nested object rather than merging properties.
fix
For complex nested object overrides, consider using nested builders or applying a `map` function to post-process the generated data. Alternatively, ensure nested objects are themselves created by sub-builders that can be individually overridden.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: build is not a function
Attempting to use `build` without correct destructuring for CommonJS `require` or using `require` in an ESM context.
fix
Ensure correct import syntax: `const { build, fake } = require('test-data-bot');` for CommonJS or `import { build, fake } from 'test-data-bot';` for ESM.
ReferenceError: faker is not defined
Trying to directly access `faker` methods outside of the `fake()` helper function, or without passing the `f` argument.
fix
All `faker.js` methods must be accessed via the `f` argument provided to the callback inside `fake()`: `fake(f => f.name.firstName())`.
TypeError: Cannot read properties of undefined (reading 'someMethod')
This error often occurs within the `fake()` callback if the `f` (faker) object is not passed or if an invalid `faker.js` method is called.
fix
Verify that your `fake()` callback receives the `faker` instance as an argument (`fake(f => ...)`) and that the `faker.js` method you are calling (e.g., `f.name.findName()`) exists in the `faker.js` API.
Upgrade
Version history
0.8.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources