Gathering detailed insights and metrics for snappify
Gathering detailed insights and metrics for snappify
Gathering detailed insights and metrics for snappify
Gathering detailed insights and metrics for snappify
@snappify/integration
<a href="https://snappify.com/"><img src="https://user-images.githubusercontent.com/4418879/114391549-ec320480-9b97-11eb-8620-3c7afe117878.png"/></a>
@snappify/next-markdown
Static pages generated from markdown files for your Next.js website.
@snappify/html-to-image
Generates an image from a DOM node using HTML5 canvas and SVG.
@snappify/modern-screenshot
Quickly generate image from DOM node using HTML5 canvas and SVG
npm install snappify
Typescript
Module System
Node Version
NPM Version
71.8
Supply Chain
99.4
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
7,347
Last Day
1
Last Week
5
Last Month
66
Last Year
342
MIT License
70 Stars
103 Commits
10 Forks
7 Watchers
1 Branches
2 Contributors
Updated on Jul 06, 2024
Minified
Minified + Gzipped
Latest Version
1.1.0
Package Id
snappify@1.1.0
Unpacked Size
22.36 kB
Size
7.37 kB
File Count
10
NPM Version
8.11.0
Node Version
16.16.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-58.3%
5
Compared to previous week
Last Month
135.7%
66
Compared to previous month
Last Year
-20.5%
342
Compared to previous year
1
6
A generator of Jest snapshot-based tests for React components written with TypeScript
Snapshot testing of React components is a useful tool that Jest provides to make sure your UI does not change unexpectedly. To apply it you have to describe several different states of a component configuring it with different props that this component can have.
However, if you write components with TypeScript, you have an interface describing the types of the props. There is no reason to fill props up manually with random values in your tests. It could be done automatically based on the described types. That is what Snappify
does.
Snappify
generates files with tests for your React components. You just run them. ✨
Install Snappify
globally:
1npm install -g snappify
Run Snappify
inside of a project folder with a configured glob pattern of the React components files and a name of a root folder for generated tests:
1snappify components/**/*.tsx --testsRoot=tests
It will create a directory called tests
inside the current folder.
Inside that directory, it will generate the files with snapshot-based tests for every of the components from the files that matched to components/**/*.tsx
pattern.
The structure of the included folders with tests will be the same as the structure of the folders with components. The names of the files with tests will be the same as the names of the files with the components.
For example, if you have this structure of folders:
my-app
├── components
│ └── Header.tsx
│ └── Content.tsx
│ └── Footer.tsx
│ └── Button
│ └── index.tsx
You will get this structure of the folders with the tests (when you run the command above):
my-app
├── tests
│ └── Header.js
│ └── Content.js
│ └── Footer.js
│ └── Button
│ └── index.js
Snappify
takes a component and its interface, and generates a file with snapshot-based tests with up to 10 test cases each.
The props values for test cases be generated with uniformly distributed sets of random values based on the types of the props. That means you get the count of test cases that you can take control of, but they are still cover the details of your components as wide as it possible in this situation.
Here we have the Button
component that have the declared interface for its props called IButtonProps
.
1import * as React from 'react'; 2 3interface IButtonProps { 4 children: React.ReactNode; 5 className?: string; 6 isDisabled?: boolean; 7 onClick?: () => void; 8} 9 10const Button: React.StatelessComponent<IButtonProps> = (props) => { 11 const { className, isDisabled, onClick } = props; 12 13 return ( 14 <div className={className} onClick={!isDisabled && onClick}> 15 {props.children} 16 </div> 17 ); 18}; 19 20export default Button;
Snappify
will generate a file with tests for this component that will looks like:
1import React from 'react'; 2import renderer from 'react-test-renderer'; 3 4import Button from 'components/Button.tsx'; 5 6test('Button case #1', () => { 7 const tree = renderer.create( 8 <Button 9 // some randomly generated values for props 10 className={'value'} 11 isDisabled={true} 12 onClick={() => undefined} 13 children={<div />} 14 /> 15 ).toJSON(); 16 17 expect(tree).toMatchSnapshot(); 18}); 19 20test('Button case #2', () => { 21 const tree = renderer.create( 22 <Button 23 // another set of randomly generated values for props 24 // (the not required props were skipped) 25 children={<div />} 26 /> 27 ).toJSON(); 28 29 expect(tree).toMatchSnapshot(); 30}); 31 32// Other test cases go here...
Right now Snappify
supports the basic types of TypeScript. It also supports a few of the React types: React.ReactNode
, JSX.Element
and React.CSSProperties
.
It doesn't support using other declared TypeScript interfaces as types of items of a React component's interface yet.
I condiser increase of the supported types as a future improvement.
Right now Snappify
supports only the semicolon (;
) as a delimiter between interface items. See example:
1interface IButtonProps { 2 children: React.ReactNode; 3 className?: string; 4}
It also supports only React components declared with one of the following statements:
1class Button extends React.Component<IButtonProps, IButtonState> {}
1class Button extends React.PureComponent<IButtonProps, IButtonState> {}
1const Button:React.StatelessComponent<IButtonProps> = (props) => {}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
73 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More