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.
react-cornea
Advanced tools
A testing utility for generating visual diffs of your React components
A testing utility for generating visual diffs of your React components.
This tool will create 3 files - theirs-{componentName}.png
, yours-{componentName}.png
and difference.png
. When differ.cleanup
is called, yours-{componentName}.png
and difference.png
will be deleted.
npm install --save-dev react-cornea
This NPM package has a dependency on ImageMagick. To install it, see the ImageMagick documentation. Installation on some Linux systems, such as Ubuntu is easy:
sudo apt-get install imagemagick
For OSX using Brew:
brew install ImageMagick
Note that when using TravisCI, ImageMagick is already installed.
React Cornea provides utility functions for you to test your React components.
Here is an example using Mocha:
import React from 'react';
import {expect} from 'chai';
const {describe, it} = global;
import { Differ } from 'react-cornea';
import { default as Program } from '../program.jsx';
describe('A Program Component', () => {
const componentName = 'program';
const program = {
name: 'Save the whale'
};
it( 'has not visually changed', (done) => {
var differ = new Differ({
component: <Program program={program} />,
componentName: 'program',
onSnapshotCreated: done,
savePath: __dirname + '/'
});
differ.compare().then((areTheSame) => {
expect(areTheSame).to.equal(true);
differ.cleanup();
done();
});
});
});
For your first set of snapshots, you can use the environment variables to generate snapshots for components that do not yet have snapshots:
env CREATE_SNAPSHOTS=1 npm test
Or by passing in a createSnapshots option:
var differ = new Differ({
component: <Program program={program} />,
componentName: 'program',
savePath: __dirname + '/',
threshold: 0,
onSnapshotCreated: done,
createSnapshots: true
});
If you are working on a large visual change, you can force new screenshots to be generated without running assertions by using environment variables in the command line:
env UPDATE_SNAPSHOTS=1 npm test
You can also specify components by name:
env UPDATE_SNAPSHOTS="my-component" npm test
Or by passing in an updateSnapshots option:
var differ = new Differ({
component: <Program program={program} />,
componentName: 'program',
savePath: __dirname + '/',
threshold: 0,
onSnapshotUpdated: done,
updateSnapshots: true
});
If you are using this utility, use env CREATE_SNAPSHOTS=1 npm run test
to generate a first, initial set of snaphots (called theirs-{componentName}.png
). You should check these into your version control.
Then, whenever you run tests npm run test
, the utility will diff the current version of your component with the theirs-{componentName}.png
file.
Watch out, it is not very useful to check in the your-{componentName}.png
or difference.png
; however, you can if you want ;)
new Differ(options) :=> Object{Differ}
Create a new Differ object
env UPDATE_SCREENSHOTS=1
or option updateScreenshots: true
. Defaults to noop.compare() :=> Promise
Will snap a picture of the your version of the React component, then compare it to the baseline, then generate a difference image. Once complete, the given Promise will resolve with whether the difference is within the threshold
cleanup() :=> nil
Will remove yours-{componentName}.png
and difference.png
.
The following are provided, but their interfaces may change in the future:
snap(options) :=> Promise
Will take a screenshot.
compareTo(options) :=> Promise
Will compare the screenshots and generate diff, as well as resolve the Promise with whether the images are within the threshold difference.
moveSnapshot(options) :=> boolean
Will attempt to move the snapshot from yours-{componentName}.png
to theirs-{componentName}.png
We have a build script to transpile the ES2015 code to ES2013 code.
npm run build
FAQs
A testing utility for generating visual diffs of your React components
The npm package react-cornea receives a total of 0 weekly downloads. As such, react-cornea popularity was classified as not popular.
We found that react-cornea demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.