@amiceli/vitest-cucumber v5.1.0
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 -DIt'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 :
- vitest-cucumber-example. Is a
Vueproject example. - vitest-cucumber_rtl_template. Is a
Reactproject example.
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 scenarioNow 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 --feature <path-to-feature> --space <path-to-spec> --lang <lang:optional>An example :
npx @amiceli/vitest-cucumber --feature features/example.feature --spec src/__tests__/example.spec.ts --lang frYou just have to format spec file after this script ;).
Currently it generates TS file, if you need more options open an issue ;).
lang allow to specify which lang is used in feature file.
Required if you don't use en language.
Docs
- Configuration
- Vitest plugin to sync spec and feature files
- Background
- Scenario
- Scenario Outline and Examples
- Scenario Outline mapped examples
- Rule
- Scneario hooks
- Structure hooks
- Predefine steps
skip,onlywith scenario, rule and background- Step sequentially and async
- Gherkin tags
- Step with expression / parameter type
- DocStrings
- DataTables
- Spoken languages
Doc is maintain in this project vitest-cucumber-docs.
Don't hesitate to open an issue on it if you want more details ;).
1 year ago
1 year ago
8 months ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
8 months ago
1 year ago
8 months ago
11 months ago
1 year ago
1 year ago
1 year ago
8 months ago
1 year ago
12 months ago
11 months ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago