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

cypress-dynamic-fixtures

v1.0.8

Published

Overwrite cy.fixture to handle JS-based fixture files for dynamic fixture data in Cypress Automation Javascript projects

Readme

Cypress Dynamic Fixtures

npm version npm downloads License GitHub issues

by Greg Jacobs

A simple Cypress command overwrite that allows loading .js fixture files. It scans your cypress/fixtures folder at test runtime and maps them to cy.fixture('my_fixture.js').

View the repository on Github


⇲ Installation

npm install --save-dev cypress-dynamic-fixtures

⛭ Setup

1. Load the plugin in Cypress config

In your cypress.config.js (Cypress 10+), load our plugin so we can scan .js fixtures:

// cypress.config.js
const { defineConfig } = require('cypress');
const { dynamicFixturePlugin } = require('cypress-dynamic-fixtures/plugin');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // Hook up the plugin
      return dynamicFixturePlugin(on, config);
    },
  },
});

2. Import

In your cypress/support/e2e.js, just import the package to register the cy.fixture() overwrite command:

// cypress/support/e2e.js
import 'cypress-dynamic-fixtures';

3. Done!

You are all setup to use .js files for dynamic fixture data.


⃕ Usage

1. Example Fixture.js

Create your new dynamic .js fixture file example:

// cypress/fixtures/subfolders_optional/dynamic_date_fixture.js
const now = new Date();

module.exports = {
    todaysDate: now,
};

2. Example Spec.js

Use your dynamic data from fixtures in your test files using cy.fixture()

  • Be sure to include the .js extension
// ./example_spec.js
Then('I expect todays date to exist', () => {
    cy.fixture('dynamic_date_fixture.js') // NOTICE the inclusion of .js
        .then((fixture) => cy.contains(fixture.todaysDate).should('exist'));
});

⃔ Backwards compatible

In your existing project, you can use cy.fixture() with static .json data just as before. Nothing breaks.

  • cypress/fixtures/static_data.json
    {
        "staticDate": "2025-03-25"
    }
  • ./existing_spec.js
    Then('I expect a static date to exist', () => {
        cy.fixture('static_data') // NOTICE no file extension required (optional: static_data.json)
            .then((fixture) => cy.contains(fixture.staticDate).should('exist'));
    });

Troubleshooting

Module System Compatibility: CommonJS vs ESM

Our package, cypress-dynamic-fixtures, is built using CommonJS. This means that all internal modules are loaded using require() and exported using module.exports. This approach works seamlessly in the default Node.js and Cypress environments.

For CommonJS Users

If your project is configured with CommonJS (the default for many Node.js projects), you can use our package as shown in the examples without any extra configuration. For example:

  • In your cypress.config.js:
    const { dynamicFixturePlugin } = require('cypress-dynamic-fixtures/plugin');
    
    module.exports = defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          return dynamicFixturePlugin(on, config);
        },
      },
    });

_

For ESM Users

If your project is using ECMAScript Modules (ESM), you may need to adjust your import statements slightly. For example:

  1. Update your package.json:

    • Make sure your project’s package.json includes "type": "module" to enable native ESM support.

  2. Importing the Plugin:

    • Use the ESM import syntax. For example:
    // cypress.config.js
    import { defineConfig } from 'cypress';
    import { dynamicFixturePlugin } from 'cypress-dynamic-fixtures/plugin';
           
    export default defineConfig({
        e2e: {
            async setupNodeEvents(on, config) {
                return await dynamicFixturePlugin(on, config);
            },
         },
     });
  3. If you run into issues, you might try a dynamic import:

    const { dynamicFixturePlugin } = await import('cypress-dynamic-fixtures/plugin');
  4. Using in Support Files:

    • Similarly, in your support file, use the ESM import:
    // cypress/support/e2e.js
    import 'cypress-dynamic-fixtures';

Summary: CommonJS vs ESM

  • CommonJS: Use require() and module.exports as shown in our examples.

  • ESM: Ensure your project supports ESM (e.g., via "type": "module" in your package.json) and update your import statements accordingly.

If you encounter any issues with module resolution or environment configuration, please refer to the Node.js ESM documentation or open an issue on our project repository.

Alias Problems

If you encounter issues with resolving module aliases (e.g., Cannot find module '@/utils/someUtil.js'), here is a possible solution:

Optional: Use the module-alias Package

If you prefer to keep using alias paths (such as @/utils/someUtil.js), follow these steps:

  1. Install module-alias:
npm install --save-dev module-alias
  1. Configure your package.json:
  • Add an _moduleAliases section to map your alias:
{
    "_moduleAliases": {
        "@": "cypress"
    }
}
  1. Register module-alias at runtime:
  • At the very top of your main entry file (e.g., in your cypress.config.js), be sure to register module-alias package to use your aliases:
require('module-alias/register'); // NOTE: Registers runtime module aliases (Babel aliases only work during transpilation)
const { dynamicFixturePlugin } = require('cypress-dynamic-fixtures/plugin');

module.exports = {
    e2e: {
        setupNodeEvents(on, config) {
            return dynamicFixturePlugin(on, config);
        },
    },
};

This ensures that when your fixture files use aliases, Node can correctly resolve them at runtime.


📝 Final Notes:

That’s it! Just install, reference the plugin in cypress.config.js, and import cypress-dynamic-fixtures in your support file. You’re all set to enjoy dynamic .js fixture data in Cypress.


🔗 Reference Links: