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

cypress-test-data-generator

v1.1.1

Published

Cypress plugin for generating test data using Faker

Downloads

18

Readme

Cypress Test Data Generator Plugin

Generate realistic and diverse test data for Cypress tests using Faker.js. This plugin enhances your test suites with random data for various entities.

Features

  • Generate data for:
    • Users (with customizable age ranges and countries)
    • Products (including name, price, stock status)
    • Orders (with multiple products)
    • Reviews (with ratings and comments)
    • Categories
    • Companies (including industry, revenue, employees)
    • Medical records
    • Travel itineraries
    • Education records
    • Job listings
    • Vehicles
  • Support for localization
  • Consistent data generation with seed support

Installation

  1. Install the plugin as a dev dependency:

    npm install --save-dev cypress-test-data-generator
  2. Include the plugin in your Cypress configuration (usually in cypress.config.js):

    const dataGenerator = require('cypress-test-data-generator');
    
    module.exports = defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          on('task', dataGenerator(on, config));
        },
      },
    });

Usage

Generating a User

cy.task('generateUser', { ageRange: { min: 20, max: 30 }, country: 'USA' }).then((user) => {
  cy.log(`Generated User: ${JSON.stringify(user)}`);
});

Generating a Product

cy.task('generateProduct').then((product) => {
  cy.log(`Generated Product: ${JSON.stringify(product)}`);
});

Generating an Order

cy.task('generateOrder', { productCount: 5 }).then((order) => {
  cy.log(`Generated Order: ${JSON.stringify(order)}`);
});

Generating a Review

cy.task('generateReview').then((review) => {
  cy.log(`Generated Review: ${JSON.stringify(review)}`);
});

Generating a Category

cy.task('generateCategory').then((category) => {
  cy.log(`Generated Category: ${JSON.stringify(category)}`);
});

Generating a Company

cy.task('generateCompany').then((company) => {
  cy.log(`Generated Company: ${JSON.stringify(company)}`);
});

Generating a Medical Record

cy.task('generateMedicalRecord').then((record) => {
  cy.log(`Generated Medical Record: ${JSON.stringify(record)}`);
});

Generating a Travel Itinerary

cy.task('generateTravelItinerary').then((itinerary) => {
  cy.log(`Generated Travel Itinerary: ${JSON.stringify(itinerary)}`);
});

Generating Education Data

cy.task('generateEducation').then((education) => {
  cy.log(`Generated Education: ${JSON.stringify(education)}`);
});

Generating a Job Listing

cy.task('generateJobListing').then((jobListing) => {
  cy.log(`Generated Job Listing: ${JSON.stringify(jobListing)}`);
});

Generating Vehicle Data

cy.task('generateVehicle').then((vehicle) => {
  cy.log(`Generated Vehicle: ${JSON.stringify(vehicle)}`);
});

API

generateUser(options)

Generates a random user object.

  • Options:
    • seed: Number to seed the random generator for consistent results
    • locale: Locale for localized data generation
    • ageRange: An object specifying the minimum and maximum age (default: { min: 18, max: 99 })
    • country: Specific country for the user's address (default: random)
    • ageMin: Minimum age (default: 18)
    • ageMax: Maximum age (default: 99)

generateProduct(options)

Generates a random product object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation
    • customFields: Object with additional fields to include
    • relatedProducts: Array of related product objects

generateOrder(options)

Generates a random order object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation
    • productCount: Number of products in the order (default: 3)

generateReview(options)

Generates a random review object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation
    • productId: Specific product ID for the review

generateCategory(options)

Generates a random category object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation
    • parentId: ID of the parent category (default: null)

generateInventory(productId, options)

Generates a random inventory object for a product.

  • Parameters:
    • productId: ID of the product
  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateCoupon(options)

Generates a random coupon object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateShippingMethod(options)

Generates a random shipping method object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generatePaymentMethod(options)

Generates a random payment method object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateRelatedProducts(mainProductId, count, options)

Generates an array of related product objects.

  • Parameters:
    • mainProductId: ID of the main product
    • count: Number of related products to generate (default: 3)
  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateProductWithRelations(options)

Generates a product object with related products.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation
    • relatedProductCount: Number of related products to generate (default: 3)

generateJobListing(options)

Generates a random job listing object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateEducation(options)

Generates a random education object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateCompany(options)

Generates a random company object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateMedicalRecord(options)

Generates a random medical record object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateTravelItinerary(options)

Generates a random travel itinerary object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

generateVehicle(options)

Generates a random vehicle object.

  • Options:
    • seed: Number to seed the random generator
    • locale: Locale for localized data generation

Error Handling

The plugin includes robust error handling for invalid inputs. If provided options are invalid (e.g., invalid age range), the plugin will throw descriptive errors to aid in debugging.

Example Tests

For detailed usage examples, refer to our example tests in the cypress/e2e directory. These tests cover:

  • Basic plugin usage
  • Data generation for users, products, orders, reviews, companies, medical records, travel itineraries, education, job listings, and vehicles

Each file demonstrates various aspects and options of the data generator, serving as both functional verification and practical examples for users.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.