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

@amiceli/vitest-cucumber

v4.3.0

Published

vitest tools to use Gherkin feature in unit tests

Downloads

9,447

Readme

vitest-cucumber

Overview

vitest-cucumber is an opiniated vitest tools (not a plugin) inspired by jest-cucumber.

Goal is to write unit test using Gherkin feature file and checking scenario name, missing scenario step etc.

Installation

npm install @amiceli/vitest-cucumber -D

It's enough you don't to add or update a config file.

Since v3.4.4 vitest-cucumber required vitest >=2.0.0.

Examples

You can take a look on :

How it works

Scenario function use vitest describe function and all steps function like Given, Then use vitest test function.

So you don't need to use it or test inside Scenario or scenario steps.

Usage

First write your feature file. By example :

Feature: Improve my unit tests
    Scenario: Use vitest-cucumber in my unit tests
        Given Developer using feature file
        And   Using vitest-cucumber
        When  I run my unit tests
        Then  I know if I forgot a scenario

Now you can write unit tests with vitest-cucumber.

Foe example :

import { loadFeature, describeFeature } from '@amiceli/vitest-cucumber'
import { expect } from 'vitest'

const feature = await loadFeature('path/to/my/file.feature')

describeFeature(feature, ({ Scenario }) => {
            
    Scenario('Use vitest-cucumber in my unit tests', ({ Given, When, Then, And }) => {
        Given('Developer using feature file', () => {
            expect(false).toBeFalsy()
        })
        And('sing vitest-cucumber', () => {
            // ...
        })
        When('I run my unit tests', () => {
            // ...
        })
        Then('I know if I forgot a scenario', () => {
            // ...
        })
    })

})

When you run your test with vitest, vitest-cucumber will check :

  • if you forget a Scenario or a Scenario Outline
  • if you use correct Scenario description
  • if you forgot a Scenario step
  • if you use a wrong Scenario step type
  • missing variables value in Scenario Outline
  • missing variables name in Scenario Outline steps

For example, if you forgot to write :

When('I run my unit tests', () => {
    // ...
})

It will throw When I run my unit tests was not called.

Generate spec file from feature file

Since 3.4.1 vitest-cucumber provide a script to generate spec file from feature file.

You can use it like this :

npx @amiceli/vitest-cucumber <path-to-feature> <path-to-spec>

An example :

npx @amiceli/vitest-cucumber features/example.feature src/__tests__/example.spec.ts

You just have to format spec file after this script ;).

Currently it generates TS file, if you need more options open an issue ;).

Docs

Doc is maintain in this project vitest-cucumber-docs.

Don't hesitate to open an issue on it if you want more details ;).