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

artstep

v55555.0.0

Published

Beautiful step definitions for Cucumber.js

Downloads

18

Readme

Artstep

Fluent, painless, and beautiful synchronous/asynchronous step definitions for Cucumber.js. Supports promises, generators, and async functions, powered by co.

Oh, and listen to some nice chill trap and artstep.

Note: v55555 works with Cucumber 0.9. For older versions of Cucumber (v0.4), please use v5555.

Why?

When creating step definitions for cucumber-js, I always feel like this:

Y U NO...

~~It simply sucks. As of v0.4.8:~~ Not so much anymore:

  • ~~If you forget to call the callback function, the event queue is drained and Cucumber simply exits without reporting anything.~~ It now times out. Hurray!
  • ~~No support for promises or generators.~~ It now supports Promises.
  • Having to use this. every time to define a single step.

So I created some wrapper functions for them and then turn it into a library.

API

var steps = require('artstep')

Returns a function that can be exported as a Cucumber steps definitions.

The returned function also has several methods, which can be used to define steps. These methods are all fluent, meaning that they all return the same function.

Synopsis

var steps = require('artstep')

module.exports = steps()
.Given(pattern, handler)
.When(pattern, handler)
.Then(pattern, handler)
.before(...tags, handler)
.after(...tags, handler)
.beforeAll(handler)
.afterAll(handler)
.around(handler)

Note: Both PascalCase and lowerCamelCase versions are available for all these methods.

Handler Function

A handler is:

  • A synchronous function. Handler will finish running immediately:

    .Then('the title contains "..."', function(text) {
      expect(this.subject.title).to.contain(text)
    })
  • A function that returns a Promise:

    .When('I select the $n song', function(n) {
      n = parseInt(n, 10)
      return driver.findElements(By.css('ul.music-list > li'))
      .then(function(items) {
        return items[n - 1].click()
      })
    })

    In CoffeeScript, it looks very beautiful:

    .When 'I select the $n song', (n) ->
      n = parseInt(n, 10)
      driver.findElements(By.css('ul.music-list > li')).then (items) ->
        items[n - 1].click()
  • An ES6 generator function:

    .When('I select the $n song', function*(n) {
      n = parseInt(n, 10)
      var items = yield driver.findElements(By.css('ul.music-list > li'))
      yield items[n - 1].click()
    })

    You can yield promises, generators, thunks, arrays, or objects. Then the resolved value will be given back unto you. This is possible because of the amazing co library.

  • An ES7 asynchronous function:

    .When('I select the $n song', async function(n) {
      n = parseInt(n, 10)
      var items = await driver.findElements(By.css('ul.music-list > li'))
      await items[n - 1].click()
    })
  • An async function from asyncawait, which makes this CoffeeScript steps definitions extremely beautiful!

    .When 'I select the $n song', async ->
      n = parseInt(n, 10)
      items = await driver.findElements(By.css('ul.music-list > li'))
      await items[n - 1].click()
  • null, false or undefined. In this case, the steps will be marked as "pending."

Around Hooks

The semantic of around hooks changed a little bit. It passes a function that, when called, runs the scenario, and returns a Promise which will be resolved when the scenario finishes executing.

That promise can be yielded.

  • ES5 + Promises:

    .Around(function(run) {
      return stuffBefore()
      .then(run)
      .then(stuffAfter)
    })
  • ES6 Generators:

    .Around(function*(run) {
      var start = Date.now()
      yield run()
      var finish = Date.now()
      console.log('It took', finish - start, 'ms')
    })
  • ES7 Async Functions:

    .Around(async function(run) {
      var start = Date.now()
      await run()
      var finish = Date.now()
      console.log('It took', finish - start, 'ms')
    })