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

@thetc/cool-cucumber

v0.1.1

Published

Jest + Cucumber = <3

Downloads

5

Readme

Cool Cucumber

Run Cucumber tests from feature files with Jest.

NPM version License

Idea

You want to write wonderful feature files (in Gherkin), but instead of using Cucumber's runner you want to get all the nice feature from Jest that you get for free with create-react-app or even create-next-app.

Implementation

Jest can use custom transforms to read files it cannot parse on its own. This library is a custom transform for .feature files.

As it uses official cucumber libraries, it should be able to parse pretty much all valid feature files. Here is a probably outdated list of things it generates:

  • Features become describe blocks
  • Examples/Scenarios become test blocks
  • Given, When, Then, And, *, But is supported of course
  • Scenario Outlines are instantiated for all their examples as test blocks as well
  • If a Background is present, it is include in all the affected scenarios
  • Data Tables are supported
  • Expressions are supported
  • @skip tag will (you guessed it) skip the feature/scenario

Not implement/tested:

  • Before/After hooks are not supported yet
  • Custom tags are included as (invisible) comments only for now
  • Doc Strings have not been tested
  • Rules have not been tested

Usage

Add this library as a dependency. Also add @cucumber/cucumber and @cucumber/messages which are needed at runtime.

Config

You'll need to extend your jest.config.js:

  • Add the file(s) that have your step definitions to setupFilesAfterEnv
  • Add feature to the moduleFileExtensions
  • Add "\\.feature$": 'cool-cucumber', to transform
  • Add something like "<rootDir>/features/*.feature", to testMatch

You can find an example based on Next.js' jest config in example-nextjs/jest.config.js.

Step definition

You define your steps as usual for Cucumber, but at the very beginning you'll need to add this:

import { default as supportCodeLibraryBuilder } from "@cucumber/cucumber/lib/support_code_library_builder";
import { uuid } from "@cucumber/messages/dist/src/IdGenerator";
supportCodeLibraryBuilder.reset(process.cwd(), uuid());

This is for some reason the only stable way to initialize Cucumber so that it can find all steps and refer to them later on in the generated code.

Inspiration

This library is inspired by cucumber-jest, which solves this problem in a very similar way. cucumber-jest is written by Dayne Mentier and licensed under the MIT license.

The reasons I have not used/extended this instead is that it seems to run each step in a Jest test block, which breaks jsdom or at least makes it less convenient to use. It also created the Jest tests at runtime. You can see this library here as an experimental alternative implementation. I have not copied any of its code, and only used it as inspiration/reference.

License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.