3.0.2 • Published 6 years ago
gudatagen v3.0.2
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