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

chai-fireproof

v0.2.0

Published

Firebase and Fireproof support for the Chai assertion library.

Downloads

8

Readme

chai-fireproof

Build Status

Chai assertions and helpers for Firebase and Fireproof.

Requirements

You need to be able to generate Fireproof references.

Usage

Object assertions

First load the plugin like any other Chai plugin: gulp.task('test:setup', 'Set up tests.', ['build'], function() {

var Firebase = require('firebase'), chai = require('chai');

require('./dist/chai-fireproof'); global.chai = chai; global.expect = chai.expect;

if (!process.env.FIREBASE_TEST_URL || !process.env.FIREBASE_TEST_SECRET) {

gutil.log('Please set FIREBASE_TEST_URL and FIREBASE_TEST_SECRET.');
process.exit(1);

}

global.root = new Fireproof(new Firebase(process.env.FIREBASE_TEST_URL)); global.authToken = process.env.FIREBASE_TEST_SECRET;

});

chai.use(require('chai-fireproof'));

Now you can create assertions on Fireproof objects like anything else. Note that these return promises that you'll have to pass back to your test framework or handle yourself.

An example with Mocha:

describe('My Firebase', function() {
  
  var root = new Fireproof(new Firebase('https://metropolis.firebaseio.com'));

  it('should have some data in there already', function() {
    return expect(root.child('robots')).to.exist;
  });

  it('should have some users in there', function() {

    return expect(root.child('citizens')).to.deep.equal({
      fred: {
        name: 'Freder Frederson',
        hometown: 'Metropolis',
        assignment: 'Utopia'
      },
      maria: {
        name: 'Maria',
        hometown: 'Metropolis',
        assignment: 'Underworld'
      }
    });

  });

  it('should have the water level in there', function() {
    return expect(root.child('waterLevel')).to.be.lessThan(5);
  })

});

Security testing

chai-fireproof includes test assertions for validating that security rules work the way they're supposed to. Note that these assertions return promises that you'll have to pass back to your test framework or handle yourself.

Security testing has the following additional requirements:

  • firebaseio-demo.com is unsupported, as Firebase doesn't check rules there.
  • Call chai.setFirebaseAuthToken() with an auth token before you make any assertions.

There are four new flags and one new method on assertions:

  • can
  • cannot
  • read
  • write
  • ref()

So you can write assertions that match the following syntax:

return expect({ uid: 'metropolis:maria' }).can.read.ref(root.child('users/maria'));
return expect({ uid: 'metropolis:robotmaria'}).cannot.read.ref(root.child('users/maria'));

The expectation object (that's to say, the thing wrapped in the assertion) is a Javascript object with authentication credentials. For write tests, you can supply an object to attempt to write to the ref (for testing validation rules et al.):

return expect({ uid: 'metropolis:robotmaria'}).cannot.write(true)
.to.ref(root.child('city/agitation'));

The following rules apply:

  • If the expectation object is null, the assertion assumes you mean an unauthenticated user.
  • Every user object except null must supply a value for uid.
  • To make a token an admin token, set admin: true. Note that this definitionally will cause any test to pass.

Documentation

There's API documentation here.

Warning

In order to capture annoying Firebase console messages, this library monkeypatches console.log(), console.warn(), and console.error(). Your mileage may vary, void where prohibited by law.