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

@code-dungeon/mocha-given

v0.0.1

Published

Adds a Given-When-Then DSL to mocha as an alternative style for specs

Downloads

1

Readme

mocha-given

Mocha-given is a mocha interface that helps you write cleaner specs using Given, When, Then and And. It is a shameless port of Justin Searls' jasmine-given which is a tribute to Jim Weirich's terrific rspec-given gem.

Example Specs

describe 'assigning stuff to this', ->
	Given -> @number = 24
	When  -> @number++
	And   -> @number *= 2
	Then  -> @number == 50

describe 'assigning stuff to variables', ->
	subject = null
	Given -> subject = []
	When  -> subject.push('foo')
	Then  -> subject.length == 1

describe 'Testing deferred', ->
	Given -> @t = Date.now()
	Then.after 1500, 'so much time has passed', -> Date.now() - @t >= 1500

describe 'Testing async', ->
	Given -> @subject = new User()
	Then 'save user', (done) -> @subject.save(done);

Run tests

Global installation of mocha

If you have mocha installed globally you need to install mocha-given globally as well.

$ npm install -g mocha mocha-given

Then you can run your tests by setting the interface of mocha to mocha-given

$ mocha -u mocha-given --compilers coffee:coffee-script -R spec

Local installation of mocha

If you have installed mocha and mocha-given locally

$ npm install mocha-given coffee-script

you have to call the mocha binary directly:

$ ./node_modules/.bin/mocha -u mocha-given --compilers coffee:coffee-script -R spec

Run mocha-given tests & start contributing

To run the mocha-given tests for developing, it has to be symlinked into the node_modules folder to enable mocha to resolve mocha-given.

Therefore run the script:

$ npm run link

Afterwards mocha has to be installed with $ npm install mocha.

Now you can run the tests using $ npm tests and start contributing.

Run tests programmatically

var Mocha = require('mocha');
var fs    = require('fs');
var path  = require('path');

// require mocha-given after Mocha is set
require('mocha-given');

// the directory with your tests/specs
var testDir = 'tests';

// First, you need to instantiate a Mocha instance.
var mocha = new Mocha({
	ui: 'mocha-given',
	reporter: 'spec'
});

// Get test files
fs.readdirSync(testDir).filter(function(file){
	// allow javascript and coffescript files
	return file.match(/\.(coffee|js)$/);
}).forEach(function(file){
	mocha.addFile(
		path.join(testDir, file)
	);
});

// Now, you can run the tests.
mocha.run(function(failures){
  process.on('exit', function () {
	process.exit(failures);
  });
});

Run from command line (with mocha and mocha-given installed):

$ node runtests.js

Credits

Thanks to SinnerSchrader for their support and the time to work on this project.