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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cucumber_annotations

v0.0.9

Published

Typescript annotations for Cucumber

Readme

Typecript Annotions for Cucumber

Cucumber

Cucumber is a tool for running automated tests written in plain language. Because these test are written in plain language, they can be read by anyone on your team. Because they can be read by anyone, you can use them to help improve communication, collaboration and trust on your team.

Typescript

Typescript is a typed superset of javascript that transpiles to plain javascript bbefore it is run. At first, the benefit is only for the developer, who gets better support in writing stable code because of the added static typing.

Combining two good tools

Cucumber comes with a javascript runtime, that already has added typescript support. This way, developers can write their step implementations in Typescript source code. With that, the circle looks complete and Typescript modules can be tested using Gherkin feature descriptions with typescript steps. Well, almost when we get beyond the 'Hello world' example.

Example

Let's take the original Cucumber example. (with a small tweak to document two other features.)

Setup

  • Install Node.js (6 or higher)

  • Install the following node modules with yarn or npm

    • typescript@>=2.0
    • ts-node@latest
    • cucumber_annotations@latest
  • Add the following files

    # features/simple_math.feature
    Feature: Simple maths
      In order to do maths
      As a developer
      I want to increment variables

	  Scenario: easy maths
	    Given a variable set to 1
	    When I increment the variable by 1
	    Then the variable in words would read two
	    
      Scenario Outline: much more complex stuff
        Given a variable set to <var>
        When I increment the variable by <increment>
        Then the variable should contain <result>

        Examples:
          | var | increment | result |
          | 100 |         5 |    105 |
          |  99 |      1234 |   1333 |
          |  12 |         5 |     18 |
    // features/steps/simple_math_world.ts
	import { Given, When, Then, Type } from "cucumber_annotations"
	import { expect } from 'chai'
	
	const NUMBERS_IN_WORDS = ['one', 'two', 'three']
	const NUMBERS_IN_WORDS_PATTERN = RegExp( NUMBERS_IN_WORDS.join( '|' ) )

	export class SimpleMathWorld {
	  private result = 0
	  
	  @Given( 'a variable set to {int}' )
	  setTo( n: number ){ this.result = n  }
	  
	  @When('I increment the variable by {int}')
	  incrementBy(n: number) { this.result += n  }
	  
	  // custom types can be annotated too
	  @Type( 'number_in_words', NUMBERS_IN_WORDS_PATTERN )
	  wordToNumber( text: string ) { return NUMBERS_IN_WORDS.indexOf( text ) + 1 }
	  
	  // multiple annotations are allowed
	  @Then('the variable should contain {int}')
	  @Then('the variable in words would read {number_in_words}')
	  shouldBe( n: number ) { expect(this.result).to.eql(n) }
	}
/*
 * The export for the SimpleMathWorld class is required, as the Typescript 
 * compiler otherwise would complain that it is: "declared but never used."
 */
	# tsconfig.json
	{
		"compilerOptions": {
			"experimentalDecorators": true
		}
	}
  • Run:
> cucumber-js --require-module ts-node/register --require "features/scripts/**/*.ts"

...........F

Failures:

1) Scenario: much more complex stuff # features\simple_maths.feature:20
   √ Given a variable set to 12 # src\annotations\steps.ts:25
   √ When I increment the variable by 5 # src\annotations\steps.ts:25
   × Then the variable should contain 18 # src\annotations\steps.ts:25
       AssertionError
           + expected - actual

           -17
           +18

           at SimpleMathWorld.shouldBe (cucumber_annotations\features\scripts\simple_maths_steps.ts:24:51)
           at CustomWorld.delegate_to_SimpleMathWorld_shouldBe (cucumber_annotations\src\worlds\annotated_world.ts:83:15)

4 scenarios (1 failed, 3 passed)
12 steps (1 failed, 11 passed)
0m00.003s
  • Note that the error was introduced deliberately in the feature file. Here one can see that all Give/When/Then annotations are registered in the source of this library. Of course, any AssertionError shows the offending line in the annotated class.