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-snapshot-per-file-by-nikitin

v1.0.3

Published

Cypress snapshot plugin with automatic per-file snapshot organization

Downloads

13

Readme

cypress-snapshot-per-file-by-nikitin

Cypress snapshot plugin with automatic per-file snapshot organization

This package is a fork of @cypress/snapshot with enhanced functionality to automatically create separate snapshot files for each test file.

Features

  • Automatic per-file snapshots: Each test file gets its own snapshot file automatically
  • Organized in snapshots/ folder: All snapshot files are stored in a dedicated snapshots/ directory
  • Auto-creation: Snapshot files are automatically created if they don't exist
  • Backward compatible: Can be used like the original @cypress/snapshot package

Install

npm install --save-dev cypress-snapshot-per-file-by-nikitin

Setup

1. Add plugin task (required, one-time setup)

⚠️ Important: You need to manually add the readFileMaybe task to your cypress/plugins/index.js file. This is a one-time setup required for the package to work.

The package uses cy.task('readFileMaybe', ...) to read snapshot files. This task runs in Node.js context and can handle file system operations that Cypress commands cannot do directly.

If you don't have any tasks yet:

Add this to your cypress/plugins/index.js:

const fs = require('fs');
const path = require('path');

module.exports = (on, config) => {
  // ... your existing config code ...
  
  on('task', {
    readFileMaybe(filePath) {
      try {
        const fullPath = path.resolve(filePath);
        if (fs.existsSync(fullPath)) {
          return fs.readFileSync(fullPath, 'utf-8');
        }
        // File doesn't exist - create directory and file automatically
        const dir = path.dirname(fullPath);
        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir, { recursive: true });
        }
        fs.writeFileSync(fullPath, '{}\n', 'utf-8');
        return '{}\n';
      } catch (err) {
        return null;
      }
    }
  });
  
  return config;
};

If you already have tasks:

Add readFileMaybe to your existing on('task', {...}) object:

module.exports = (on, config) => {
  // ... your existing code ...
  
  on('task', {
    // ... your existing tasks ...
    
    readFileMaybe(filePath) {
      const fs = require('fs');
      const path = require('path');
      try {
        const fullPath = path.resolve(filePath);
        if (fs.existsSync(fullPath)) {
          return fs.readFileSync(fullPath, 'utf-8');
        }
        // File doesn't exist - create directory and file automatically
        const dir = path.dirname(fullPath);
        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir, { recursive: true });
        }
        fs.writeFileSync(fullPath, '{}\n', 'utf-8');
        return '{}\n';
      } catch (err) {
        return null;
      }
    }
  });
  
  return config;
};

Note: The task automatically creates the snapshot file and directory if they don't exist, so you don't need to create them manually.

2. Register the plugin

In your test files, register the plugin:

require('cypress-snapshot-per-file').register()

Or in cypress/support/commands.js:

require('cypress-snapshot-per-file').register()

Usage

describe('my tests', () => {
  it('works', () => {
    cy.wrap({ foo: 42 }).snapshot()
    cy.wrap({ bar: 101 }).snapshot()
  })
})

Configuration

You can configure the plugin via Cypress config:

// cypress.config.js
module.exports = defineConfig({
  // ... other config
  autoPerFile: true,        // Enable automatic per-file snapshots (default: true)
  snapshotsDir: 'snapshots', // Directory for snapshot files (default: 'snapshots')
  snapshotFileName: 'snapshots.js' // Only used if autoPerFile is false
})

How it works

  • When autoPerFile: true (default), the plugin automatically:

    1. Detects the current test file name (e.g., 03_all_share_order_statuses_snapshot.cy.js)
    2. Creates a snapshot file named snapshots/03_all_share_order_statuses_snapshot.snap.js
    3. Automatically creates the file if it doesn't exist
  • Each test file gets its own snapshot file, making it easy to:

    • Find snapshots for a specific test
    • Delete and regenerate snapshots for a single test
    • Organize and manage snapshots

License

MIT