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

fredastaire

v0.0.6

Published

fredastaire adds chainable step methods (given, when, and), which make it easy to write readable and reusable setup steps for mocha tests.

Downloads

7

Readme

Fredastaire

Fredastaire adds step methods to mocha tests that have two impacts:

  • Your test cases' setup code is significantly more readable
  • You only have to write the same setup steps once

Table of contents


Setup

  1. npm install fredastaire --save-dev or yarn add fredastaire -D
  2. Define your steps wherever you like. (example below)
  3. Write some tests that use given. (example below)
  4. Run your tests with the fredastaire ui, requiring your steps file: mocha ./tests/some-tests.js --ui fredastaire --require <your steps file>

Usage

1. Tests

Just call given('with some string'). The string will be used to identify which step definition to call (more on that later).

There's also when and and, which are aliases of given.

TODO: Add given, when, and to the test output.

// /your/project/tests/astronauts-test.js

const state = {
	spaceThings: [],
	astronauts: [],
};

let res;

describe('Interesting space apparatus example', function() {
	given('there are two spacethings', {container: state.spaceThings});

	and('there is one astronaut', {container: state.astronauts});

	when('i request a space thing that has an astronaut', {
		id: state.spaceThings[0].id,
		container: res,
	});

	it('should give me one space thing', function() {
	  expect(res.body.spacething).to.not.be.null;
	  expect(res.body.spacething.id).to.equal(state.spacethings[0].id);
	});

	it('should have an astronaut with the space thing', function() {
		expect(res.body.spacething.astronaut).to.not.be.null;
		expect(res.body.spacething.astronaut.id).to.equal(state.astronauts[0].id);
	});
});

2. Step definitions

Step definitions are the places where you put your setup code for individual tests.

// /your/project/wherever/you/like/your-definitions.js

const addSteps = require('fredastaire/steps');
const request = require('whatever/you/like/for/requesting/stuff');

addSteps({
  'there are two space things': function({container, spaceThing1={}, spaceThing2={}}) {
    container = [SpaceThings.create(spaceThing1), SpaceThings.create(spaceThing2)];
  },

  'there is one astronaut': function({container, astronaut={}}) {
    container = SpaceAstronaut.create(astronaut);
  },

  'i request a space thing that has an astronaut': function({id, container}) {
    return request.get('/space-things/' + id)
    .then(response => container = response);
  }
});

Full API

Methods


given, and, when

given('there is something', {named: 'whatever'});

Calls a defined step inside a before. given, and and when are all the same function, so use them in whatever order you like. Return a promise to handle async behavior.

Arguments
{string} name -- The name used to identify the step.

So if you define a step named "this is a step", then you would run the step using given('this is a step').

{object} data -- Whatever you need to pass to the step.

Pass whatever your step needs to can create something specific.


addSteps

addSteps({
  'there is something': function(data) {
		global.thing = {...data};
  }
});

Registers steps which are triggered with given.

Arguments
{object} steps -- The name and function to be triggered by given.

The objects you pass to addSteps are all merged together, so when you call given(name), it calls steps[name](). *So if you pass the same key twice to addSteps, the first step will be replaced by the second.


getSteps()

Gets all the steps you've defined