Gherkin
To use vitest-cucumber, you first need to understand Gherkin. Gherkin is a language for writing structured, human-readable specifications. It uses keywords like Feature, Scenario, and Given/When/Then to describe how software should behave.
To write a Gherkin specification, create a .feature file:
Feature: User login
Users should be able to log in with valid credentials
Scenario: Valid credentials
Given a registered user
When they enter valid credentials
Then they are logged in
Generating a spec file
Section titled “Generating a spec file”To save time, you can generate a spec file automatically from a feature file via the CLI:
npx @amiceli/vitest-cucumber --feature <path-to-feature> --spec <path-to-spec> --lang <en:optional>
Example:
npx @amiceli/vitest-cucumber --feature features/example.feature --spec src/__tests__/example.spec.ts
To parse a feature file in a different language, use the --lang option:
npx @amiceli/vitest-cucumber --feature features/example.feature --spec src/__tests__/example.spec.ts --lang fr
By default the feature file is parsed with en language.