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

ember-dev-fixtures

v0.0.20

Published

An improved Ember Data fixture adapter to be used on dev env, and which is not inserted as part of the app in prod builds.

Downloads

17

Readme

ember-dev-fixtures

Allow you to run your application with an improved ember-data fixture adapter and fixtures defined outside of the app/ tree. The goal is to have a production build which does not contain anything related to the fixtures, neither the adapter, while providing in-browser injected fixtures on dev environments (no need of a server even locally, you can build and deploy on github pages for example and it'll just work with the fixtures if you activated them in the config).

Why is it good to use this addon?

  • You can code your frontend without needing a backend.
  • You can create new features for your application while the API is yet not ready for it.
  • You can run unit/acceptance tests with many different situations thanks to fixture overlays.
  • You can deploy a demo-application which would not need anything else than a static content web server.
  • You can distribute zip files as demo-applications where the user would just open the index.html of the unpacked folder of the zip-file and it would work straight away.

Installation

  • npm install --save-dev ember-dev-fixtures
  • or with the latest ember-cli: ember install:addon ember-dev-fixtures

Usage

  • By default the adapter will be used as the adapter:application, but you can override any other adapter of your application by defining their names in ENV.APP.devFixtures.adapters array of your config/environment.js.

  • To disable the adapter in development environment, set ENV.APP.devFixtures to false. By default it is activated for development environment and disabled for all others. You might want to set it to true (or {}) for the test environment for example.

  • Define your fixtures in fixtures/<model-name>.js files of your application as an array. You can use the blueprint to generate it: ember g dev-fixture <model-name>.

Extensions

  • The adapter will take care of async: false (or undefined) relations in what it'll create the correct payload for whatever request you'll do with the store.

  • There is a basic queryFixture method which allow you to use findQuery.

  • You can override the behavior of some models by defining extension of each model in fixtures/adapters/<model>.js. It'll do DevFixtureAdapter.extend(<your-extension>).

    There is a blueprint for this too: ember g dev-fixture-adapter <model-name>. Those, as well as the fixtures, won't be included in your production build or any build where you did not activated this addon (cf ENV.APP.devFixtures.adapters above).

  • The powerfulness of this addon are the overlays. You can define base fixtures and then some overlays that you'd activate with the query parameter FIXTURES_OVERLAY=<overlay-name>. An overlay is a folder in the fixtures folders where your can define a file per model which will contain fixtures used to extend (with merge) the base fixtures. Use ember g dev-fixture overlay <overlay-name> to create an overlay config file and its folder, and ember g dev-fixture-extension <model-name> --overlay=<overlay-name> to create a fixture extension.

    An overlay can include other overlay(s) thru its _config.js include property. At the end the fixtures will include the base fixtures, then merge with all include overlay's fixtures, then finally merge with that overlay's fixtures. If a fixture has a __removeFixture property set to true, then this record will be removed from the fixture array if it exists.

    You can also force an overlay per build with the ENV.APP.devFixtures.overlay config key in config/environment.js. Set it to the name of overlay you want to enable. The URL parameter will take precedence if it is found, else this one will be used, and finally the one found in the local storage if any from previous load. This allows you to call startApp in the acceptance tests with a different overlay: startApp({devFixtures: {overlay: 'my-overlay'}});.

  • The DevFixtureAdapter was previously extending the DS.FixtureAdapter but it is now since 0.0.2 a full rewrite, extending the DS.Adapter. It is working as if your serializer was a DS.RESTSerializer and has useful methods so that you can add extension for each model or for all with the application adapter. Here are some of the provided methods:

    • simulateRemoteCall(<response>, <statusCode=200>, <statusText>): Simulates a response with the data given in <response>. If the <statusCode> is given and not 2xx then the promise will be rejected, The <statusText> is either automatic regarding the <statusCode> or you can provide one.

    • createSingleRecordResponse(<store>, <type>, <record>[, <other-type>, <other-records>, ...]): creates a response JSON for a response containing one record.

    • createMultiRecordsResponse(<store>, <type>, <records>[, <other-type>, <other-records>, ...]): creates a response JSON for a response containing many records of the given type.

    • createDeletedRecordResponse(<store>, <type>, <record>): creates a response JSON for a response containing a deleted record.

    • updateFixtures(<store>, <type>, <fixtureRecord>[, <auto-gen-id>]): Used to save the given record in the fixtures, doing a merge if it already exists.

    • deleteLoadedFixture(<store>, <type>, <fixtureRecord>): used to delete the given record from the fixtures.

    • createFixture(<store>, <type>, <fixtureRecord>): creates a new fixture for the given type and data.

  • A _fixtureMeta attribute is added on all your models which have fixtures. For now it contains one property only: sources. It is the list of all the fixture and overlay file path(s) that have been used as source for that record.

Author

Huafu Gandon - Follow me on twitter: @huafu_g


For more information on using ember-cli, visit http://www.ember-cli.com/.