node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Creates trees of JSON data to be used for mocking HTTP requests from real data in unit tests. Assumes that the environment you are generating over uses an X-Impersonate header in order to get data from the context of different users.

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install testdata-generator --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:


The "testdata" task


In your project's Gruntfile, add a section named testdata to the data object passed into grunt.initConfig().

  testdata: {
    options: {
      server: 'default server to pull data from, defaults to localhost'
    dev: {
      src: 'testdata-map.js',
      dest: 'testdata.js',
      users: ['driggins', 'HopeZ', 'Any other users to generate']

Usage Examples

Test map

This is a comprehensive example, demonstrating all of the features used in one map.

var refdataSize = 1;
function createSearchAddress(path) {
  return function (node) {
    return + path;
module.exports = {
  common: {
    GET: {
      me: '/api/users/me',
      search: '/api/search/nextavailableserver',
      refData: {
        divisions: createSearchAddress('division/_search?size=' + refdataSize),
        networks: createSearchAddress('network/_search?size=' + refdataSize),
        demographics: createSearchAddress('demographic/_search?size=' + refdataSize),
        properties: createSearchAddress('property/_search?size=' + refdataSize),
        rateCardTypes: createSearchAddress('ratecardtype/_search?size=' + refdataSize),
        revenueTypes: createSearchAddress('revenuetype/_search?size=' + refdataSize),
        productCategories: createSearchAddress('productcategory/_search?size=' + refdataSize),
        priceBreaks: createSearchAddress('pricebreak/_search?size=' + refdataSize),
        sellingPeriods: createSearchAddress('sellingperiod/_search?size=' + refdataSize)
      brandSearch: {
        address: function (node) {
          return + 'division/_search?size=1';
  dealHeader: {
    POST: {
      newDeal: '/api/deal'


In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

Initial release
Bug Fixes
Bug Fixes
Switch to use dest/src and move to unit level for config
Fix source path of config file
Fix for functions returning null and reverting to base server