# cucumber-ts

> Type-safe cypress.io definitions for cucumber/gherkin-syntaxed specs

Latest version **0.0.1-0** (published 2022-02-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install cucumber-ts
pnpm add cucumber-ts
yarn add cucumber-ts
bun add cucumber-ts
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-0 |
| Published | 2022-02-04 |
| First published | 2022-02-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 39.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marco Toniut |
| Maintainers | marco.toniut |
| Keywords | test, cucumber, cypress, cypress.io |

## Links

- npm: https://www.npmjs.com/package/cucumber-ts
- npm.io page: https://npm.io/package/cucumber-ts

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.0.1-0 (latest) — 2022-02-04

## README

# `cucumber-ts`

Type-safe re-implementation of core functions from the [@cucumber/cucumber]() package, former [cypress-cucumber-preprocessor](https://github.com/TheBrainFamily/cypress-cucumber-preprocessor).

## How to Use

`cucumber-ts` aims to knit a strict correlation between a step's description string, it's defined parameters and a precise type definition for each one of them. Changing any of these, should trigger a compilation error for the user.

### The different parameter types

```gherkin
Given A customer selects option1

Given A customer picks option1 for purchase
Given A customer picks option1, option2 for purchase
Given A customer picks  for purchase

Given A customer selects the following items: option1
Given A customer selects the following items: option1, option2

Given A customer inputs Jorge as their name
```

```ts
import {
  defineStep,
  parameterTypeList,
  parameterTypeNonEmptyList,
  parameterTypeRaw,
  parameterTypeSum,
  parameterTypeString,
} from "cucumber-ts";

defineStep(
  "A customer selects {var1}",
  (var1) => {
    switch (var1) {
      case "option1":
      case "option2":
        console.log("success", var1);
        break;
      default:
        // Unreachable code.
        break;
    }
  },
  {
    var1: parameterTypeSum("option1", "option2"),
  }
);

defineStep(
  "A customer picks {list1} for purchase",
  (list1) => {
    list1.map((x) => console.log(x));
  },
  {
    list1: parameterTypeList("option1", "option2"),
  }
);

defineStep(
  "A customer selects the following items: {nonEmptyList1}",
  (nonEmptyList1) => {
    nonEmptyList1.map((x) => console.log(x));
  },
  {
    nonEmptyList1: parameterTypeNonEmptyList("option1", "option2"),
  }
);

defineStep(
  "A customer inputs {string1} as their name",
  (string1) => {
    console.log(string1);
  },
  {
    string1: parameterTypeString(),
  }
);
```

---

### A more complete use case

```gherkin
Given A student Pedro Sánchez is attending courses on Algebra, History at University of Oxford
```

```ts
import * as Cucumber from "cucumber-ts";

const subjects = [
  "University of Oxford",
  "Imperial College London",
  "University of St Andrews",
] as const;
type Subject = typeof subjects[number];
const universities = ["Algebra", "Phylosophy", "History"] as const;
type University = typeof universities[number];

Cucumber.defineStep(
  "A student {word} is attending courses on {subject} at {unviversity}",
  (name, subject, university) => {
    const name_: string = name;
    const subject_: Subject = subject;
    const university_: University = university;
  },
  {
    subject: Cucumber.parameterTypeSum(...subjects),
    subject: Cucumber.parameterTypeNonEmptyList(...universities),
  }
);
```

## Contribute

[Suggestions](https://github.com/marcotoniut/cucumber-ts/issues) and contributions are very much welcomed. Special use cases not fully covered by the current api would be most valuable.

---
_Source: https://npm.io/package/cucumber-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
