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

mocha-rspecstyle

v1.2.0

Published

Syntax on mocha like rspec framework

Downloads

12

Readme

mocha-rspecstyle

mocha-rspecstyle provides subject and val hooks on mocha like rspec. (New hooks run on beforeEach and afterEach hooks.)

Usage

mocha --ui rspecstyle

subject

const assert = require('assert');

describe('subject sample', () => {
  subject(() => ({ foo: 'abc', bar: 123 }));

  it('check subject value', () => {
    assert.deepEqual(subject(), { foo: 'abc', bar: 123 });
  });

  context('override subject', () => {
    subject(() => ({ foo: 'abc', baz: false }));

    it('check override value', () => {
      assert.deepEqual(subject(), { foo: 'abc', baz: false });
    });
  });
});

val

val is a let of rpsec.

const assert = require('assert');

describe('val sample', () => {
  val('foo', () => ({ foo: 'commonValue', bar: val('bar')}));
  val('bar', 123);

  it('check val value', () => {
    assert.deepEqual(val('foo'), { foo: 'commonValue', bar: 123 });
  });

  context('override value', () => {
    val('foo', 'abc');

    it('check override value', () => {
      assert.equal(val('foo'), 'abc');
    });
  });

  context('override nested value', () => {
    val('bar', () => ({ baz: val('baz') }));
    val('baz', 456);
    
    it('check override value', () => {
      assert.deepEqual(val('foo'), { foo: 'commonValue', bar: { baz: 456 } });
    });

    context('re override nested value', () => {
      val('baz', 789);

      it('check re override value', () => {
        assert.deepEqual(val('foo'), { foo: 'commonValue', bar: { baz: 789 } });
      });
    });
  });
});

sharedExamples/itBehavesLike

describe('sharedExamples', () => {
  sharedExamples('sharedExamples1', () => {
    it('called shared examples', () => {
      assert(true);
    });
  });

  sharedContext('sharedContext1', () => {
    context('context', () => {
      it('called shared context', () => {
        assert(true);
      });
    });
  });

  itBehavesLike('sharedExamples1');
  includeContext('sharedContext1');

  describe('nested describe', () => {
    includeContext('sharedContext1');
    
    context('nested context', () => {
      itBehavesLike('sharedExamples1');
    });
  });
});

Alias

  • sharedExamples ---> sharedContext / shared_examples / shared_context
  • itBehavesLike ---> includeContext / it_behaves_like / include_context

Full Sample

(test/lib/feature.js)

const fizzbuzz = (value) => {
  if (value % 15 === 0) return 'FizzBuzz';
  if (value % 3 === 0) return 'Fizz';
  if (value % 5 === 0) return 'Buzz';
  return `${value}`;
}

describe('FizzBuzz', () => {
  subject(() => fizzbuzz(val('value')));

  sharedExamples('returned Fizz', () => {
    it('return Fizz', () => {
      assert.equal(subject(), 'Fizz');
    });
  });

  sharedExamples('returned Buzz', () => {
    it('return Buzz', () => {
      assert.equal(subject(), 'Buzz');
    });
  });

  sharedExamples('returned FizzBuzz', () => {
    it('return Buzz', () => {
      assert.equal(subject(), 'FizzBuzz');
    });
  });

  sharedExamples('returned value string', () => {
    it('return value string', () => {
      assert.equal(subject(), `${val('value')}`);
    });
  });

  sharedContext('FizzBuzz cycle', () => {
    context('1 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 1 * val('cycle')));
    });
    context('2 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 2 * val('cycle')));
    });
    context('3 * cycle', () => {
      itBehavesLike('returned Fizz', () => val('value', () => 3 * val('cycle')));
    });
    context('4 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 4 * val('cycle')));
    });
    context('5 * cycle', () => {
      itBehavesLike('returned Buzz', () => val('value', () => 5 * val('cycle')));
    });
    context('6 * cycle', () => {
      itBehavesLike('returned Fizz', () => val('value', () => 6 * val('cycle')));
    });
    context('7 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 7 * val('cycle')));
    });
    context('8 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 8 * val('cycle')));
    });
    context('9 * cycle', () => {
      itBehavesLike('returned Fizz', () => val('value', () => 9 * val('cycle')));
    });
    context('10 * cycle', () => {
      itBehavesLike('returned Buzz', () => val('value', () => 10 * val('cycle')));
    });
    context('11 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 11 * val('cycle')));
    });
    context('12 * cycle', () => {
      itBehavesLike('returned Fizz', () => val('value', () => 12 * val('cycle')));
    });
    context('13 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 13 * val('cycle')));
    });
    context('14 * cycle', () => {
      itBehavesLike('returned value string', () => val('value', () => 14 * val('cycle')));
    });
    context('15 * cycle', () => {
      itBehavesLike('returned FizzBuzz', () => val('value', () => 15 * val('cycle')));
    });
  });


  describe('1〜15', () => {
    includeContext('FizzBuzz cycle', () => val('cycle', 1));
  });
  describe('16〜30', () => {
    includeContext('FizzBuzz cycle', () => val('cycle', 2));
  });
});

Licence

MIT