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

green-light

v0.5.1

Published

An opinionated (but complete) set of tools for functional testing

Downloads

48

Readme

🚦GreenLight

There are a lot of ways you can test your project. You can go with unit-testing, integration-testing, end-to-end-testing, or by manually clicking around your site to see everything still works.

My personal favorite is functional testing. Write tests for each functionality of your project, simulate different circumstances which this specific part can run in and make sure everything is still O.K. An example would be:

import { api, browser, expect } from 'green-light';

describe('article title', () => {
  describe('when it has a title', () => {
    it('renders the title', (done) => {
      api
        .respondTo('/article/42.json')
        .andReplace('/title', 'Some title');

      browser
        .go('/article/42')
        .then((window) => {
          expect(window.$('h1').text()).to.equal('Some title');
        })
        .then(done, done);
    });
  });

  describe('when it has no title', () => {
    it('renders no title', (done) => {
      api
        .respondTo('/article/42.json')
        .andReplace('/title', null);

      browser
        .go('/article/42')
        .then((window) => {
          expect(window.$('h1').length).to.equal(0);
        })
        .then(done, done);
    });
  });
})

GreenLight bundles all the tools you'll need to do exactly this. It can be configured and runned with Node.

Getting started

Follow the steps of the getting started guide, check out an example of a setup over here, or take a look at the documentation for each part of GreenLight for more details:

API

A mocked version of your API, to control what data is returned for certain URL's and usecases. Based on mocked-api.

Read more.

Target

The project you'd like to test, connected to the mocked API.

Read more.

Browser

A virtual browser that visits the page that you're testing. Based on jsdom.

Read more.

Tests

The actual code you'll be writing to test your project. Based on mocha and chai.

Read more.

Don't use this if

  • You can't (or don't want to) run Node.
  • You want to use Jasmine, Karma, CasperJS, RSpec, PhantomJS, Nightwatch, NodeUnit, Shoulda, Velocity, Protractor, Vows, Mockito, Sinon, Cucumber, ZombieJS, Selenium, JUnit, or whatever. GreenLight works with mocha, chai, jsdom and mocked-api. These tools are great (or good enough) and I believe that support for anything else is not worth the complexity.
  • You don't want to write functional tests. Unit-tests, for example, are awesome in some cases, but you don't need GreenLight for that. If you want to do something else than functional testing, I'd suggest to use plain Mocha instead. This doesn't mean that you can't combine different kinds of testing though! It's not weird to do both unit-testing and functional-testing for the same app (where appropriate).
  • Your project doesn't get its data from an API that you can mock. A large part of functional testing is to simulate different kinds of data and test how your app is responding to that. If you can't do that, GreenLight is probably not a greath fit and you should go with a different kind of setup.

Use this if

  • You can run Node. This doesn't mean that your project has to be written in Node though. In fact, your project can be written in any language, as long as GreenLight can run it with some kind of command. Node is only needed for running the test-suite, mocked API and the virtual browser.
  • Your project gets its data from an API and you can configure it to a mocked version of that.
  • You're ok with mocha, chai, jsdom and mocked-api. Remember what I said about chai? Well actually.. you can use any other assertion-library, but you've got to install and import it yourself.