GithubHelp home page GithubHelp logo

helpscout / helix Goto Github PK

View Code? Open in Web Editor NEW
20.0 9.0 3.0 1.08 MB

πŸ’  Helix: A fixture generator for Javascript, powered by Faker.js

License: MIT License

JavaScript 100.00%
javascript fixtures generator faker specs open-source

helix's Introduction

Helix πŸ’ 

Build Status Coverage Status npm version

A fixture generator for Javascript, powered by Faker.

Helix allows you to quickly (and reliably) generate fixture data to be hydrated into Javascript components/views (like React, Vue, Backbone, etc…).

Install

npm install @helpscout/helix --save-dev

Documentation

Check out our documentation for more info!

Basic usage

The createSpec function is used to define your fixture spec. Helix comes with an adjusted version of Faker.js, which also needs to be imported. Note, the API for Helix's faker is the exact same as Faker.js.

import { createSpec, faker } from '@helpscout/helix'

const CustomerSpec = createSpec({
  id: faker.datatype.number()
  fname: faker.name.firstName()
  lname: faker.name.lastName()
  company: faker.company.companyName()
})

const fixture = CustomerSpec.generate()

// Output
// {
//   id: 12339041,
//   fname: 'Alice',
//   lname: 'Konigsberg',
//   company: 'Smiths Co.'
// }

For a full list of Faker methods, check out their documentation.

helix's People

Contributors

brettjonesdev avatar danielgent avatar itsjonq avatar plbabin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

helix's Issues

Replace faker with a maintained version of the package

I noticed, that you are using the old version of faker, that is no longer maintained.

"faker": "5.5.3",

You might want to switch to the maintained package @faker-js/faker.

It has all the versions from the old package, but received numerous updates in the meantime (including built-in types).

Disclaimer: I'm a maintainer of @faker-js/faker.

Rethink `computed` approach

I ran into trouble with computed because the shape you pass into the faker.computed(shape)(values => {}) call does not get returned from the final spec.

I think a better approach (possibly a parallel approach or new helper) would be something like this:

createSpec({ 
  firstName: faker.name.first(), 
  lastName: faker.name.last() 
}).calculate(values => {
   // some logic, modify `values` in place if desired
   return {...values, otherValue} 
})

Basically a helper to add simple post-process function which can create compound fields which have a dependency on other attributes of the spec.

Multiple identical fixtures generated if seed call is chained

Hi,

Apologies to bother you with another bug, but I thought I'd put this here so future users at least know there is an issue

I've created a code example at https://runkit.com/embed/w8kknlcjgpxw where you can see the following code working

const { createSpec, faker } = require('@helpscout/helix')

const exampleSpec = createSpec({
  id: faker.random.number(),  
})

console.log('NOT WORKING: ', JSON.stringify(exampleSpec.seed(123).generate(3)))

Which outputs: "[{\"id\":69646},{\"id\":69646},{\"id\":69646}]"
This is the same with any faker value - they're always the same. So it looks like the seed is being reset for each generated fixture

In order to get around this, I'm just calling seed directly on faker like

import { faker } from '@helpscout/helix';

faker.seed(123);

Extending generated specs

Maybe provided a method called .extend().

So you would use it like…

const MySpec = createSpec({})
const fixture = MySpec.seed(3).generate().extend({ ... })

ES6 inside NPM package

Hi there,

Great module, big fan of faker and I love what you've done here with schemas. 😍

I'm just wondering whether you should include src/ in your .npmignore?

Currently when I npm install your module, I'm getting ES6 code in the src folder (which blows up tools like Jest of course that don't transpile node_modules)

Currently I've just got a private fork of Helix to deal with this.

Feel free to ignore this of course, it just still seems the standard to only have ES5 in NPM packages (but I'm far from an expert on creating NPM packages!)

Thanks,
Dan

computed Specs

Need a way to generate computed values. Potentially using the same {{name.firstName}} API has Faker's fake method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.