3.0.2 • Published 6 years ago

gudatagen v3.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

gudatagen, data generator for testing or mocking

Documentation | Contributing | by Guten | Gratipay | Bountysource

Roadmap

  • support relationship
  • support reference
  • move helpers to standalone package

Installation

$ yarn add --dev gudatagen

Getting Started

import gen, { id, step, random, faker } from 'gudatagen'

gen.locale = 'en'

const post = {
  id,
  username: step(['admin'], 'hello'),
  template: t`${random(2)}.jpg`,
  faker: () => faker.name.findName(),
}

// in server
gen({
  posts: gen(post, 2)
  comments: gen(comment, 2)
})
/* =>
 * {
 *   posts: [
 *    { id: 1, username: 'admin', template: '2.jpg' },
 *    { id: 2, username: 'hello', template: '0.jpg' },
 *  ],
 *  comments: [ ... ]
 * }
 */

// in client
gen({
  posts: gen(post, 2, {
    comments: gen(comment, 2)
  })
})
/* =>
 * {
 *   posts: [
 *     { ..., comments: [ ... ] },
 *     { ... },
 *   ]
 * }
 */

Custom helpers

function hello(name) {
  return function() {
    return `${name} ${this.index}`
  }
}

For webpack target to web

resolve: {
  alias: { bcrypt: 'node-mocks/bcrypt' }
}

Debugging

$ DEBUG=gudatagen node a.js
3.0.2

6 years ago

3.0.1

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.0.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago