npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mirage-glue

v1.6.6

Published

Generate mirage fixture file(s) from your api endpoint

Downloads

17

Readme

Ember Mirage factories are great for testing form data, however for pages that show models or lists of models and relationships, fixtures are better source than factories.

This library fetches server api endpoints you provide and writes or appends to mirage fixture files, saves significant amount of time and mental energy. It also removes the possibility of human error from manual fixture entries. Written for ember apps that uses RestAdapter.

  $ npm install -g mirage-glue

  $ mirage-glue localhost:4000/unicorns
  Data written to ./mirage/fixtures/unicorns.js (File size: 24 KB)
  Fixture file has 20 records (+20)

  $ mirage-glue localhost:4000/unicorns/55
  Data written to ./mirage/fixtures/unicorns.js (File size: 26 KB)
  Fixture file has 21 records (+1)

If you have an embedded hasOne() or belongsTo() relationship in your json API response the embedded record also gets created in its relevant fixture file!!

Example:

  $ mirage-glue localhost:4000/blog-posts
  Data written to ./mirage/fixtures/blog-posts.js (File size: 82 KB)
  Fixture file has 20 records (+20)
  appending data to file: mirage/fixtures/categories.js
  Data written to ./mirage/fixtures/categories.js (File size: 22 KB)
  Fixture file has 21 records (+1)

If you want to ignore nested parsing/fixture creation of relationships/objects you can provide --ignore-nesting option flag:

  $ mirage-glue localhost:4000/blog-posts --ignore-nesting
  Data written to ./mirage/fixtures/blog-posts.js (File size: 102 KB)
  Fixture file has 20 records (+20)

For routes that are hidden behind Bearer token authentication you can use the --token option flag:

  $ mirage-glue localhost:4000/me --token="Bearer aBcdDjtQQ5_u0Ke--yWfDIn9pZPXl8TYiQuJS-LKNUMP-efxi0lr2r1TLUS3Bttr"
  Data written to mirage/fixtures/users.js (File size: 0.89 KB)
  Fixture file has 1 records (+1)
  Data written to mirage/fixtures/phone-numbers.js (File size: 0.32 KB)
  Fixture file has 1 records (+1)
  Data written to mirage/fixtures/emails.js (File size: 0.40 KB)
  Fixture file has 1 records (+1)

Bonus: Using the same fixture data in Phoenix/Elixir tests:

When you provide an elixir-app=YourElixirAppName option, elixir fixture files are generated under ../backend/test/support/fixtures folder we gets loaded automatically by mix every time you run mix test:

  $ mirage-glue localhost:4000/hackers elixir-app=TheMatrix
  Data written to ./mirage/fixtures/hackers.js (File size: 17 KB)
  Fixture file has 6 records (+6)
  appending data to file: mirage/fixtures/human-subjects.js
  Data written to ./mirage/fixtures/human-subjects.js (File size: 68 KB)
  Fixture file has 8 records (+6)
  Data written to ../backend/test/support/fixtures/human_subject.ex (File size: 72 KB)
  Data written to ../backend/test/support/fixtures/hacker.ex (File size: 21 KB)

You can read the contents of the fixture files to understand how the use fixtures in Elixir tests. One big caveat of using fixtures in the backend is you might not have the referenced relationship of the fixture record thus foreign_key constraints prevent your fixtures from getting inserted to the database. The generated elixir fixture files use the fixturist elixir library to source referenced relationship from development database to the test database along with your fixture insertion.