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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nestjs-cucumber-kit/core

v2.2.0

Published

Nestjs cucumber kit core

Downloads

12

Readme

@nestjs-cucumber-kit/core

@nestjs-cucumber-kit/core seamlessly integrates NestJS with CucumberJS, enhancing the experience of writing BDD-style end-to-end tests in NestJS applications. It simplifies the setup and execution of Cucumber tests, allowing developers to focus on writing test scenarios instead of configuration.

Installation

Using npm:

npm install @nestjs-cucumber-kit/core --save-dev

Using Yarn:

yarn add @nestjs-cucumber-kit/core --dev

Basic Usage

Follow these steps to integrate @nestjs-cucumber-kit/core into your NestJS project:

1. Setup Cucumber in your NestJS project:

In cucumber.js file at the root of the project:

const args = [
  '--format progress',
  '--parallel 1',
  '--require-module ts-node/register/transpile-only',
  '--require features/setup/**/*.ts',
  '--exit',
];

module.exports = { default: args.join(' ') };

In package.json:

{
  "scripts": { 
    "test:e2e": "cucumber-js" 
  }
}

File structure at the root of the project:

feature/
  data/               # Data needed for testing
  setup/
    config.ts         # Configure lib
    setup.ts          # Setup world and lib
    world.ts          # Add custom world
  step-definitions/   # Custom step definitions
  tests/

Examples of configuration files:

config.ts
import { INestApplication, ValidationPipe } from '@nestjs/common';
import * as path from 'path';
import { FixtureSteps, HttpSteps, StorageSteps, ICucumberKitConfig } from '@nestjs-cucumber-kit/core';

export const config: ICucumberKitConfig = {
  steps: [HttpSteps, StorageSteps, FixtureSteps],
  dataDir: path.join(__dirname, '..', 'data'),
  appConfigure: (app: INestApplication) => {
    app.useGlobalPipes(new ValidationPipe());
  },
};
world.ts
import { AbstractWorld } from '@nestjs-cucumber-kit/core';
import { AppModule } from '../app/app.module';
import { config } from './config';

export class CustomWorld extends AbstractWorld {
  constructor() {
    super(AppModule, config);
  }
}
setup.ts
import { setWorldConstructor } from '@cucumber/cucumber';
import { configureSteps } from '@nestjs-cucumber-kit/core';
import { config } from './config';
import { CustomWorld } from './world';

configureSteps(config.steps);
setWorldConstructor(CustomWorld);

2. Example Test Scenarios:

Graphql Example:

Feature: GraphQL API interaction

  Scenario: Retrieve an item by ID
    Given I send a GraphQL request to "/graphql" with the payload:
      """
      query {
        getItem(id: "1") {
          _id
          name
        }
      }
      """
    Then the response should contain JSON:
      """
      {
        "data": {
          "getItem": {
            "_id": "1",
            "name": "test"
          }
        }
      }
      """

Complete graphql example.

HTTP Example:

HTTP

Feature: HTTP
  Scenario: Send Request with custom header
    Given I store the key "accessToken" with the value "token"
    Given I store the key "itemName" with the value "New Item"
    Given I set the request header "Authorization" to "Bearer {{accessToken}}"
    When I send a POST request to API "/item" with JSON:
      """
      { "name": "{{itemName}}" }
      """
    Then the response code should be 201
    And the response should contain JSON:
      """
      { "_id": "*", "name": "{{itemName}}" }
      """

Complete http example.

File Upload Example:

Feature: HTTP upload

  Scenario: Uploading an image file
    Given I set the request header "Content-Type" to "multipart/form-data"
    And I upload file "image.jpeg" as form field "image"
    When I send a POST request to API "/upload"
    Then the response code should be 201
    And the response should contain JSON:
    """
    {
      "message": "File uploaded successfully"
    }
    """

Storage Example:

Feature: storage

  Scenario: Store single value
    Given I store the key "username" with the value "John Doe"
    And the key "username" should have the value "John Doe"

  Scenario: Store json
    Given I store the key "name" with the value "John Doe"
    Given I store the key "user" with the JSON data:
      """
      { "name": "John Doe", "age": 30 }
      """
    And the key "user" should contain JSON:
      """
      { "name": "{{name}}", "age": 30 }
      """

Complete storage example.

Primitive Assertions Example:

Feature: Primitive value responses

  Scenario: Get a boolean value
    When I send a GET request to API "/primitive/boolean"
    Then the response should be boolean true

  Scenario: Get a number value
    When I send a GET request to API "/primitive/number"
    Then the response should be number 42

  Scenario: Get a string value
    When I send a GET request to API "/primitive/string"
    Then the response should be string "Hello, World!"

Features

  • Easy Integration: Integrates NestJS with CucumberJS.
  • Custom Steps Support: Write your own step definitions.
  • Shared Storage: Share data between steps.
  • Fixture Support: Easily set up test data.

For detailed setup, usage, and advanced configurations, visit the NestJS Cucumber Kit Documentation.