Skip to main content

Introduction

Autometa Cucumber Runner is a wrapper for multiple established test runners like jest and vitest that enables support for testing .feature files.

Features

  • Utilize you or your teams favorite testing framework with Cucumber
  • Steps are defined globally and scenarios are self assembling
  • Steps can be overridden for specific features or scenarios with edge behavior
  • Per-Scenario dependency injection of tester-defined classes.
  • Cucumber expressions
  • Extensive handling of data tables
  • CommonJs and ESM compatible

Install

npm add -D @autometa/cucumber-runner

Quick Start

Configure

To begin, add *.feature.ts as a test file pattern to your test library config if needed. Also, add autometa.config.ts to the setup files option

vitest.config.js
import { defineConfig } from 'vitest/config'

defineConfig({
...
setupFiles: ['autometa.config.ts']
include: ['**/*.{test,spec,feature}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
...
})

Next, create the autometa.config.ts. To use globally available step files, add a globals option, and provide the test functions of your test framework. It's also a good idea to import reflect-metadata from this file. reflect-metadata is a required dependency of this library.

import "reflect-metadata";
import { defineConfig } from "@autometa/cucumber-runner";
import {
describe,
test,
beforeEach,
beforeAll,
afterEach,
afterAll,
} from "vitest";

defineConfig({
globals: "globals",
runner: {
name: "vitest",
describe,
test,
beforeEach,
beforeAll,
afterEach,
afterAll,
},
});

Use

<project-root>/features/my-feature.feature
Feature: A User Can Log In
Background: Set up a new User
Given a new registered User
| username | name | age | password |
| johnny5 | John | 45 | paS5091! |

Scenario: A User logs in with valid credentials
When they log in
| username | password |
| johnny5 | paS5091! |
Then they see their profile

Scenario: A User logs in with a bad password
When they log in
| username | password |
| johnny5 | oops |
Then they are informed their password is incorrect