Jest + Cucumber = <3

Overview

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

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.

You might also like...

Web-pack based Todo-List Website built using HTML, CSS and JavaScript. Tested Using Jest.

To-DO List Live Link Additional description about the project and its features: Built With HTML and CSS Javascript HTML & CSS3 & JavaScript Linters Gi

Mar 31, 2022

Debug your Jest tests. Effortlessly.🛠🖼

Debug your Jest tests. Effortlessly.🛠🖼

Jest Preview Debug your Jest tests. Effortlessly. 🛠 🖼 Try Jest Preview Online. No downloads needed! Why jest-preview When writing tests using Jest,

Jan 4, 2023

for this repo I'll do some practices(exercices) using Jest for testing my javscript code.

js-testing for this repo I'll do some practices(exercices) using Jest for testing my javscript code. Here are questions for all resolved js Jest testi

Mar 16, 2022

Data structures & algorithms implementations and coding problem solutions. Written in Typescript and tested with Jest. Coding problems are pulled from LeetCode and Daily Coding Problem.

technical-interview-prep Data structures & algorithms implementations and coding problem solutions. Written in Typescript and tested with Jest. Coding

Aug 5, 2022

An interactive list of tasks where you can add, remove, edit, mark as completed and clear all done tasks. Tested with Jest.

An interactive list of tasks where you can add, remove, edit, mark as completed and clear all done tasks. Tested with Jest.

To do List This project its an interactive list of task where you can add and remove tasks dinamically Project Images Add new Tasks Edit Existing Task

Nov 9, 2022

A simple boilerplate using NextJS, Typescript, Tailwind, Jest, Storybook and more.

This is a Next.js boilerplate using TailwindCSS and other cool stuff. Most of this is taught in this course. What is inside? This project uses lot of

Dec 4, 2022

Simple jest-easy is friendlier to monorepo mode support

jest-easy Simple jest-easy is friendlier to monorepo mode support Quickly pnpm add jest-easy jest add a command, the jest.config.js in the root direct

Jun 10, 2022

In this project I write the test for several functions and used the TDD with Jest and JavaScript.

JavaScript-Testing-with-Jest npm init -y npm install --save-dev jest Once installed, you should see it in already created Json file Change Jest Script

Jun 11, 2022

This project displays the art collection using the Metropolitan Museum of Art API. For this project we used HTML, CSS, Javascript, Webpack and Jest.

Metropolitan Museum of Art This project displays the art collection using the Metropolitan Museum of Art API. For this project we used HTML, CSS, Java

Dec 24, 2022
Comments
  • Bump next from 12.0.8 to 12.1.0 in /example-nextjs

    Bump next from 12.0.8 to 12.1.0 in /example-nextjs

    Bumps next from 12.0.8 to 12.1.0.

    Release notes

    Sourced from next's releases.

    v12.1.0

    Core Changes

    • Relay Support in Rust Compiler: #33702
    • fix eslint link-passhref rule: #33857
    • update webpack: #33831
    • Flush buffered vitals metrics on page mount: #33867
    • fix problem with HMR when middleware and page reference the same node_module: #33873
    • Refactor page component getter in web server: #33759
    • update NextResponse default redirect status to 307 to match docs: #33505
    • Bug fix: dynamic page should not be interpreted as predefined page: #33808
    • Group streaming experimental apis: #33878
    • Encapsulate routing and initial hydration: #33875
    • Optimize offline condition judgment: #33238
    • Ensure external beforeFiles rewrites are handled with next/link: #33888
    • Fix parsing params for i18n optional route in minimal mode: #33896
    • Ensure browserslist extends works properly: #33890
    • Fix image cache race condition: #33883
    • Add support for Relay projects without artifactDirectory: #33918
    • fix: handle jsxspreadattribute in inline-script-id eslint rule: #32421
    • feat(next-swc): Update swc: #33724
    • Update to latest version of amphtml-validator: #33967
    • Warn in dev mode when script tags are added with next/head: #33968
    • Ensure optional chaining in swc matches babel: #33995
    • Use react-dom/server.browser in Node.js: #33950
    • Ensure external middleware rewrite is handled correctly: #33962
    • Update Terser to v5.10.0, fix minification issues: #33045
    • Warn in dev mode when stylesheets are added using next/head: #34004
    • Use ReadableStream in RenderResult: #34005
    • Fix suffix ordering while streaming: #34011
    • Don't use yarn if a package-lock.json file is found: #31926
    • Do not warn when application/ld+json scripts are used with next/head: #34021
    • Babel & next-swc: Fix exporting page config with AsExpression: #32702
    • Detect per page runtime config for functions manifest: #33945
    • Add JSDoc to config options: #32915
    • Update font-stylesheet-gathering-plugin.ts: #30709
    • Add decoratorMetadata flag if enabled by tsconfig: #32914
    • fix: data url handling in css-loader: #34034
    • Place 'charset' element at the top of : #28119
    • Fix detection of anchor click events inside svg: #23272
    • Allow passing nothing as custom jest config: #32328
    • Fixes #31240: Adding a recursive addPackagePath function in webpack-config: #31264
    • Require component rendered as child of Link to pass event to onClick handler: #27723
    • Allow scroll prevention on hash change: #31921
    • Add support for async fn / promise in next.config.js/.mjs: #33662
    • Fix lazyRoot functionality for next/image: #33933
    • Change SWC minify from beta to release candidate: #34056
    • Make Router state immutable: #33925
    • Stop exposing internal render and renderError methods from next/client: #34069
    • Add api-utils helper for testing: #34078

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
The Techno Creatives
Making an impact through digital products and services.
The Techno Creatives
Cypress Boilerplate with Cucumber (BDD)

Cypress Boilerplate with POM and Cucumber Download & Configuration npm init --> package.json npm install cypress cypress-cucumber-preprocessor --> pac

Sefa Batuhan Bayazitoğlu 7 Nov 4, 2022
🥾 A simple way to do testing AWS Services and Jest or Serverless and Jest

jest-localstack-preset Install Install via yarn or npm $ yarn add https://github.com/thadeu/jest-localstack-preset.git or $ npm i https://github.com/t

thadeu 5 Oct 1, 2022
🚀Starter project with Angular 13, Ngx-admin, NestJS, Nx Workspace, Jest, Cypress, ESLint & Prettier 🚀

Angular 13 + Ngx-admin + NestJs + NX Starter project with Angular 13, Ngx-admin, NestJs, Nx Workspace, Jest, Cypress, ESLint & Prettier Features ✅ Ang

Wilfried 49 Jan 4, 2023
API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest

Api Backend Tindin Sobre API em NodeJS, utilizando banco de dados MongoDB (TypeORM), com cobertura de testes (coverages), utilizando o Jest. ?? app ur

Enéas Almeida 1 Jan 20, 2022
Example Serverless DynamoDB integration tests using Jest, TypeScript and the AWS CDK

serverless dynamodb integration tests ?? Example Serverless DynamoDB integration tests using Jest, TypeScript and the AWS CDK Introduction How to inte

Lee Gilmore 8 Nov 4, 2022
🃏 A jest reporter for chats like: Twitch, Discord, etc.

?? @santima10/jest-chat-reporter ⚠️ ⚠️ This package is still under development ⚠️ ⚠️ A jest reporter for chats like: Twitch, Discord, etc. Configurati

Santi 3 Mar 30, 2022
Express.js framework boilerplate with TypeScript, Prisma, ESLint, Husky and Jest

Setup a Node.js project with Typescript, Prisma ESLint, Prettier, Husky Node.js boilerplate with Express.js, TypeScript, Prisma, ESLint, Prettier, Hus

Smart Geek 6 Dec 12, 2022
A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment.

jest-light-runner A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment. Comparison with the default Jest runne

Nicolò Ribaudo 193 Dec 12, 2022
A jest reporter that shows test running stats using the HUD macOS app.

jest-hud-reporter A jest reporter that shows test running stats using the HUD macOS app. hud-jest.mp4 Installation This package is available as a NPM

Nando Vieira 4 Feb 26, 2022
Elegant jest.expect typings for a more civilized age

typed-jest-expect Elegant jest.expect typings for a more civilized age Why? By default, the expect utility of jest is very broadly typed, which makes

Elie Rotenberg 4 Feb 25, 2022