Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

Your test data is lying to you: emails that don’t match names, orders shipped before they were placed

Most fake data generators fill each column on its own. You ask for a name, an email and two dates, and you get rows like this: first_name,last_name,email,ordered_at,shipped_at Maria,Lopez,[email protected],2026-03-14

Most fake data generators fill each column on its own. You ask for a name, an email and two dates, and you get rows like this:

first_name,last_name,email,ordered_at,shipped_at
Maria,Lopez,[email protected],2026-03-14,2026-02-02

Kevin's email belongs to Maria, the order shipped six weeks before it was placed, and gmail.com is a real domain that someone might actually receive mail on.

Your tests pass on that row. Your app will never see a row like it in production. That gap is where bugs hide: a "shipped in N days" chart that goes negative, a dedupe job that trusts email to match name, a migration that chokes on O'Brien.

I kept running into this, so I wrote a small generator where each row is one coherent record. It is one file with no dependencies, MIT licensed, and it runs in Node, in the browser and in a Web Worker.

What "consistent" means here

const F = require('consistent-fake-data');

const users = [
  { name: 'id',         type: 'id' },
  { name: 'first_name', type: 'first_name' },
  { name: 'last_name',  type: 'last_name' },
  { name: 'email',      type: 'email', unique: true },
  { name: 'signed_up',  type: 'date',  p: { from: '-1y', to: 'today' } },
  { name: 'last_login', type: 'after', p: { col: 'signed_up', min: 0, max: 60 } }
];

const out = F.produce(users, { rows: 4, seed: 'devto' });
console.log(out.chunks.join(''));
id,first_name,last_name,email,signed_up,last_login
1,Jeffrey,Diaz,[email protected],2026-04-23,2026-05-10 07:18:38
2,Jonathan,Allen,[email protected],2026-03-11,2026-04-23 02:36:46
3,Douglas,Kelly,[email protected],2025-12-09,2026-01-24 08:00:30
4,Brenda,Carter,[email protected],2026-07-20,2026-08-16 09:46:18
  • The email comes from the name, in the shapes people really use (first.last, last.first, flast15).
  • The after type puts a date 0–60 days after another column, so last_login is never before signed_up.
  • Emails use example.com/.net/.org, the domains reserved for documentation (RFC 2606), so a test that sends mail can't reach a real person.

The same idea runs through the other types. Gender follows the first name, age follows the birth date, and street, city, region, postcode and phone belong to the same place. US, UK and French phone numbers use the ranges set aside for fiction, such as 555-01xx.

Dates that respect each other

Orders are the classic case. Here 20% of orders are not shipped yet, and an empty ordered_at would also leave shipped_at empty:

const orders = [
  { name: 'id',         type: 'id' },
  { name: 'customer',   type: 'full_name' },
  { name: 'total',      type: 'amount', p: { min: 5, max: 400 } },
  { name: 'ordered_at', type: 'date',   p: { from: '-90d', to: 'today' } },
  { name: 'shipped_at', type: 'after',  p: { col: 'ordered_at', min: 1, max: 5 }, blank: 20 }
];

F.produce(orders, { rows: 4, seed: 'devto2', format: 'sql', dialect: 'postgres', table: 'orders' });
BEGIN;
INSERT INTO "orders" ("id", "customer", "total", "ordered_at", "shipped_at") VALUES
  (1, 'Russell Clark', 17.09, '2026-09-19', '2026-09-22 20:55:44'),
  (2, 'Rebecca Hughes', 42.99, '2026-10-20', NULL),
  (3, 'Ethan Martinez', 74.99, '2026-10-31', NULL),
  (4, 'Jose Mitchell', 46.86, '2026-09-06', '2026-09-11 01:21:05');
COMMIT;

amount is skewed like real prices: many small totals, a few large ones, and plenty ending in .99. Uniform random prices are a giveaway that data is fake, and they hide bugs in anything that buckets or averages money.

SQL that actually loads

The SQL output is where most generators fall over. This one:

  • escapes quotes per database (O'Brien → 'O''Brien', plus backslashes for MySQL) and quotes identifiers;
  • writes batched multi-row INSERTs inside a transaction;
  • can add a CREATE TABLE with inferred types, PRIMARY KEY, NOT NULL and UNIQUE;
  • knows the dialect differences: SET NAMES utf8mb4 for MySQL, N'…' and NVARCHAR for SQL Server, a 1,000-row cap per INSERT there, and so on.

It targets MySQL, PostgreSQL, SQLite and SQL Server, and can also write CSV (any delimiter, optional BOM so Excel reads accents), TSV, JSON and JSON Lines.

Seeds, and impossible requests caught early

The same seed gives the same rows on any machine, so a failing test can be reproduced. Adding or removing a column does not reshuffle the others, so the fixture diff stays small when the schema changes.

unique: true really guarantees distinct values, and an impossible request fails before generating instead of looping forever:

F.produce([{ name: 'n', type: 'int', p: { min: 1, max: 100 }, unique: true }], { rows: 500 }).errors;
// [ '“n” can only have 100 different values, so 500 unique rows are impossible. …' ]

Related tables

Generate the parent with { type: 'id' }, then give the child a foreign key over the same range:

{ name: 'customer_id', type: 'fk', p: { min: 1, max: 100 } }

Every customer_id then points at a customer that exists.

Try it

What doesn't it do yet? Status-dependent fields. For example, a cancelled order still gets a shipped_at if you add both columns. If your test data has rules like that, I'd like to hear which ones matter to you.

Disclosure: I built the generator. This post was written with AI assistance. Every snippet above was run against the published package and the output is pasted as is (with the today option fixed to 2026-11-01 so the dates stay put).

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.