Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
jest-specific-snapshot
Advanced tools
[![CircleCI](https://circleci.com/gh/igor-dv/jest-specific-snapshot.svg?style=svg)](https://circleci.com/gh/igor-dv/jest-specific-snapshot)
The jest-specific-snapshot package allows you to create and manage Jest snapshots in a more granular and specific manner. It provides functionality to create snapshots for specific tests and manage them independently, which can be useful for large test suites or when you need more control over your snapshot testing.
Creating a specific snapshot
This feature allows you to create a snapshot for a specific test and store it in a specified file. This can be useful for organizing snapshots and keeping them separate from other tests.
const { toMatchSpecificSnapshot } = require('jest-specific-snapshot');
expect.extend({ toMatchSpecificSnapshot });
test('example test', () => {
const data = { key: 'value' };
expect(data).toMatchSpecificSnapshot('./__snapshots__/example.snap');
});
Updating a specific snapshot
This feature allows you to update an existing snapshot for a specific test. If the snapshot already exists, it will be updated with the new data provided in the test.
const { toMatchSpecificSnapshot } = require('jest-specific-snapshot');
expect.extend({ toMatchSpecificSnapshot });
test('example test', () => {
const data = { key: 'new value' };
expect(data).toMatchSpecificSnapshot('./__snapshots__/example.snap');
});
Jest is a comprehensive testing framework that includes built-in snapshot testing capabilities. While it does not offer the same level of granularity as jest-specific-snapshot, it is widely used and provides a robust set of features for testing JavaScript applications.
AVA is a test runner that supports snapshot testing through the 'ava' package. It is known for its simplicity and speed, but it does not offer the same level of control over individual snapshots as jest-specific-snapshot.
Mocha is a flexible testing framework that can be extended with various plugins to support snapshot testing. While it requires additional configuration and plugins to achieve similar functionality, it is a popular choice for developers who need a customizable testing solution.
Jest matcher for multiple snapshot files per test
You can read about the implementation here
npm i -D jest-specific-snapshot
const path = require('path');
// extend jest to have 'toMatchSpecificSnapshot' matcher
require('jest-specific-snapshot');
test('test', () => {
// provides snapshot file with absolute file
const pathToSnap = path.resolve(process.cwd(), './example/specific/dir/my.shot');
expect(100).toMatchSpecificSnapshot(pathToSnap);
//same snapshot but with relative file
expect(14).toMatchSpecificSnapshot('./specific/dir/my.shot');
// another snapshot file in the same test
expect(19).toMatchSpecificSnapshot('./specific/another_dir/another.shot');
});
// extend jest to have 'toMatchSpecificSnapshot' matcher
const addSerializer = require('jest-specific-snapshot').addSerializer;
addSerializer(/* Add custom serializer here */);
test('test', () => {
expect(/* thing that matches the custom serializer */).toMatchSpecificSnapshot(
'./specific/custom_serializer/test.shot'
);
});
toMatchSpecificSnapshot
const toMatchSpecificSnapshot = require('jest-specific-snapshot').toMatchSpecificSnapshot;
expect.extend({
toMatchDecoratedSpecificSnapshot(received, snapshotFile) {
// You can modify received data or create dynamic snapshot path
const data = doSomeThing(received);
return toMatchSpecificSnapshot.call(this, data, snapshotFile);
},
});
.snap
, since it conflicts with jest.--updateSnapshot
(-u
) parameter provided from CLI, there is an abuse of the SnapshotState._updateSnapshot
private field. TBD - try to use the globalConfig
to get this state..toMatchSpecificSnapshot
does ignore a custom serializers strategy. In order to support custom serializers, you should use the addSerializer
method explicitly.FAQs
[![CircleCI](https://circleci.com/gh/igor-dv/jest-specific-snapshot.svg?style=svg)](https://circleci.com/gh/igor-dv/jest-specific-snapshot)
The npm package jest-specific-snapshot receives a total of 114,107 weekly downloads. As such, jest-specific-snapshot popularity was classified as popular.
We found that jest-specific-snapshot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.