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

@basementuniverse/cucumber-tsflow

v4.0.0

Published

Provides 'specflow' like bindings for CucumberJS 7.0.0+ in TypeScript 1.7+, with additional hooks

Downloads

7

Readme

cucumber-tsflow

Provides 'specflow' like bindings for CucumberJS in TypeScript 1.7+.

Fork description

This is a detached fork of https://github.com/timjroberts/cucumber-js-tsflow, including only the ./cucumber-tsflow directory. It has had the https://github.com/wudong/cucumber-js-tsflow/tree/before_after_all_hooks branch merged into it, which adds support for beforeAll and afterAll hooks.

Bindings

Bindings provide the automation that connects a specification step in a Gherkin feature file to some code that executes for that step. When using Cucumber with TypeScript you can define this automation using a 'binding' class:

import { binding } from "cucumber-tsflow";

@binding()
class MySteps {
    ...
}

export = MySteps;

Note: You must use the export = <type>; because Cucumber expects exports in this manner.

Step Definitions

Step definitions can be bound to automation code in a 'binding' class by implementing a public function that is bound with a 'given', 'when' or 'then' binding decorator:

import { binding, given, when then } from "cucumber-tsflow";

@binding()
class MySteps {
    ...
    @given(/I perform a search using the value "([^"]*)"/)
    public givenAValueBasedSearch(searchValue: string): void {
        ...
    }
    ...
}

export = MySteps;

The function follows the same requirements of functions you would normally supply to Cucumber which means that the functions may be synchronous by returning nothing, use the callback, or return a Promise<T>. Additionally, the function may also be async following the TypeScript async semantics.

Step definitions may also be scoped at a tag level by supplying an optional tag name when using the binding decorators:

@given(/I perform a search using the value "([^"]*)"/)
public givenAValueBasedSearch(searchValue: string): void {
    ...
    // The default step definition
    ...
}

@given(/I perform a search using the value "([^"]*)"/, "tagName")
public givenAValueBasedSearch(searchValue: string): void {
    ...
    // The step definition that will execute if the feature or
    // scenario has the @tagName defined on it
    ...
}

Hooks

Hooks can be used to perform additional automation on specific events such as before or after scenario execution. Hooks can be restricted to run for only features or scenarios with a specific tag:

import { binding, before, after } from "cucumber-tsflow";

@binding()
class MySteps {
    ...
    @before()
    public beforeEachScenario(): void {
        // This will be called before each scenario
        ...
    }
    ...

    @before("requireTempDir")
    public async beforeEachScenarioRequiringTempDirectory(): Promise<void> {
        // This will be called before each scenario tagged with 'requireTempDir', or before every scenario in features tagged with 'requireTempDir'
        let tempDirInfo = await this.createTempDirectory();

        ...
    }

    @after()
    public afterEachScenario(): void {
        // This will be called after each scenario
        ...
    }

    @after("requireTempDir")
    public afterEachScenarioRequiringTempDirectory(): void {
        // This will be called after each scenario tagged with 'requireTempDir`, or after every scenario in features tagged with 'requireTempDir'
        ...
    }
    
    @beforeAll()
    public static beforeAllScenarios(): void {
        // This will be called before the first scenario
        // It must be a static method
        ...
    }
    
    @afterAll()
    public static afterAllScenarios(): void {
        // This will be called after the last scenario
        // It must be a static method
        ...
    }
}

export = MySteps;

Sharing Data between Bindings

Context Injection

Like 'specflow', cucumber-tsflow supports a simple dependency injection framework that will instantitate and inject class instances into 'binding' classes for each execuing scenario.

To use context injection:

  • Create simple classes representing the shared data (they must have default constructors)
  • Define a constructor on the 'binding' classes that will require the shared data that accepts the context objects as parameters
  • Update the @binding() decorator to indicate the types of context objects that are required by the 'binding' class
import { binding, before, after } from "cucumber-tsflow";
import { Workspace } from "./Workspace";

@binding([Workspace])
class MySteps {
    constructor(protected workspace: Workspace)
    { }

    @before("requireTempDir")
    public async beforeAllScenariosRequiringTempDirectory(): Promise<void> {
        let tempDirInfo = await this.createTemporaryDirectory();

        this.workspace.updateFolder(tempDirInfo);
    }
}

export = MySteps;