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 🙏

© 2026 – Pkg Stats / Ryan Hefner

browsecraft-bdd

v0.6.3

Published

Built-in BDD support for Browsecraft — Gherkin parser, step definitions, AI auto-steps, and TypeScript-native BDD mode

Readme

browsecraft-bdd

Built-in BDD framework for Browsecraft. Gherkin parser, step definitions, hooks, executor, TypeScript-native BDD, and AI auto-step generation — all custom-built with zero third-party dependencies.

No Cucumber. No external parsers. Everything is built in.

Install

npm install browsecraft-bdd

Two Ways to Write BDD Tests

Option 1: Gherkin .feature Files

Write scenarios in plain English, then wire them to code with step definitions.

features/login.feature

Feature: User Login

  Scenario: Successful login
    Given I am on the login page
    When I fill "Username" with "standard_user"
    And I fill "Password" with "secret_sauce"
    And I click "Login"
    Then I should see "Products"

test.mjs

import { readFileSync } from 'node:fs';
import { Browser } from 'browsecraft';
import {
  parseGherkin, Given, When, Then,
  BddExecutor, globalRegistry,
} from 'browsecraft-bdd';

Given('I am on the login page', async (world) => {
  await world.page.goto('https://www.saucedemo.com');
});

When('I fill {string} with {string}', async (world, field, value) => {
  await world.page.fill(field, value);
});

When('I click {string}', async (world, text) => {
  await world.page.click(text);
});

Then('I should see {string}', async (world, text) => {
  const content = await world.page.content();
  if (!content.includes(text)) throw new Error(`Expected "${text}" on page`);
});

const browser = await Browser.launch();
const doc = parseGherkin(readFileSync('features/login.feature', 'utf-8'));

const executor = new BddExecutor({
  registry: globalRegistry,
  worldFactory: async () => ({
    page: await browser.newPage(),
    browser,
    ctx: {},
    attach: () => {},
    log: console.log,
  }),
});

const result = await executor.runDocument(doc);
console.log(`${result.summary.scenarios.passed}/${result.summary.scenarios.total} passed`);
await browser.close();

Option 2: TypeScript-Native BDD

Same structured BDD output, but no .feature files — write everything in code.

import { Browser } from 'browsecraft';
import { feature, scenario, given, when, then, runFeatures } from 'browsecraft-bdd';

feature('User Login', () => {
  scenario('Successful login', ({ page }) => {
    given('I am on the login page', () =>
      page.goto('https://www.saucedemo.com'));

    when('I enter credentials and log in', async () => {
      await page.fill('Username', 'standard_user');
      await page.fill('Password', 'secret_sauce');
      await page.click('Login');
    });

    then('I should see the products page', () =>
      page.waitForURL('inventory'));
  });
});

const browser = await Browser.launch();
const result = await runFeatures({
  worldFactory: async () => ({
    page: await browser.newPage(),
    browser,
    ctx: {},
    attach: () => {},
    log: console.log,
  }),
});
console.log(`${result.summary.scenarios.passed}/${result.summary.scenarios.total} passed`);
await browser.close();

Gherkin Parser

The built-in parser supports the full Gherkin spec:

  • Scenario Outlines with Examples tables
  • Background steps
  • Data Tables and Doc Strings
  • Tags on features and scenarios
  • Rules
  • Comments
  • 70+ languages (English, Spanish, French, German, Japanese, and more)
import { parseGherkin } from 'browsecraft-bdd';

const doc = parseGherkin(featureSource);
// doc.feature.name, doc.feature.children, etc.

Step Definitions

Register steps using {string}, {int}, {float}, {word} placeholders:

import { Given, When, Then } from 'browsecraft-bdd';

Given('I have {int} items in my cart', async (world, count) => {
  // count is parsed as a number
});

When('I search for {string}', async (world, query) => {
  await world.page.fill('Search', query);
});

Custom parameter types:

import { defineParameterType } from 'browsecraft-bdd';

defineParameterType({
  name: 'color',
  regexp: /red|green|blue/,
  transformer: (s) => s,
});

Then('the button should be {color}', async (world, color) => { /* ... */ });

Tags

Filter which scenarios run using tag expressions:

@smoke
Scenario: Quick test
  ...

@slow @integration
Scenario: Full flow
  ...
const executor = new BddExecutor({
  tagFilter: '@smoke and not @slow',
  // ...
});

Supports and, or, not, and parentheses.

Hooks

import { Before, After, BeforeAll, AfterAll, BeforeStep, AfterStep } from 'browsecraft-bdd';

BeforeAll(async () => { /* one-time setup */ });
AfterAll(async () => { /* one-time teardown */ });
Before(async (ctx) => { /* before each scenario */ });
After(async (ctx) => { /* after each scenario */ });
BeforeStep(async (ctx) => { /* before each step */ });
AfterStep(async (ctx) => { /* after each step */ });

// Tag-scoped hooks
Before('@login', async (ctx) => { /* only for @login scenarios */ });

AI Auto-Step Generation

Automatically generate step definitions from .feature files using the GitHub Models API.

import { autoGenerateSteps } from 'browsecraft-bdd';

const result = await autoGenerateSteps(featureSource, {
  appContext: 'An e-commerce site with login and cart features',
});

console.log(result.fileContent); // Complete step definition file
console.log(result.aiGenerated); // true if AI was used

Requires GITHUB_TOKEN with models scope. Falls back to stub generation with TODO comments when unavailable.

License

MIT