Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-styled-components

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-styled-components - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

19

package.json
{
"name": "jest-styled-components",
"version": "1.0.0",
"version": "1.1.0",
"description": "Jest utilities for Styled Components",

@@ -9,3 +9,3 @@ "main": "./src/index.js",

],
"repository": "git@github.com:MicheleBertoli/jest-styled-components.git",
"repository": "git@github.com:styled-components/jest-styled-components.git",
"author": "Michele Bertoli",

@@ -22,2 +22,4 @@ "license": "MIT",

"chalk": "^1.1.3",
"enzyme": "^2.7.1",
"enzyme-to-json": "^1.5.0",
"eslint": "^3.17.1",

@@ -33,2 +35,3 @@ "eslint-config-airbnb": "^14.1.0",

"react": "^15.4.2",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2",

@@ -39,2 +42,5 @@ "react-test-renderer": "^15.4.2",

},
"dependencies": {
"css": "^2.2.1"
},
"peerDependencies": {

@@ -44,3 +50,2 @@ "chalk": "^1.1.3",

"jest-snapshot": "^19.0.2",
"pretty-format": "^19.0.0",
"strip-ansi": "^3.0.1",

@@ -50,7 +55,7 @@ "styled-components": "^1.4.4"

"jest": {
"testEnvironment": "node"
},
"dependencies": {
"css": "^2.2.1"
"testEnvironment": "node",
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
}

@@ -1,2 +0,2 @@

[![Build Status](https://travis-ci.org/MicheleBertoli/jest-styled-components.svg?branch=master)](https://travis-ci.org/MicheleBertoli/jest-styled-components)
[![Build Status](https://travis-ci.org/styled-components/jest-styled-components.svg?branch=master)](https://travis-ci.org/styled-components/jest-styled-components)

@@ -3,0 +3,0 @@ # Jest Styled Components

@@ -18,3 +18,3 @@ const chalk = require('chalk')

if (isClassName(line)) {
return chalk.magenta(line)
return chalk.white(line)
}

@@ -27,3 +27,3 @@ if (isAddition(line)) {

}
return line
return chalk.gray(line)
}).join('\n')

@@ -30,0 +30,0 @@ )

const css = require('css')
const prettyFormat = require('pretty-format')
const reactTestPlugin = require('pretty-format/build/plugins/ReactTestComponent')
const styleSheet = require('styled-components/lib/models/StyleSheet')
const getStyles = (components) => {
const getClassNames = (node, classNames) => {
if (node.children && node.children.reduce) {
classNames = node.children.reduce((acc, child) => (
acc.concat(getClassNames(child, acc),
)), classNames)
}
if (node.props && node.props.className) {
return classNames.concat(node.props.className.split(' '))
}
return []
}
const getStyles = (classNames) => {
const styles = styleSheet.rules().map(rule => rule.cssText).join('\n')
const ast = css.parse(styles)
ast.stylesheet.rules = ast.stylesheet.rules.filter(rule => (
components.indexOf(rule.selectors[0].substring(1)) > -1
classNames.includes(rule.selectors[0].substring(1))
))

@@ -19,10 +29,11 @@

test(val) {
return val
return !val.withStyles && val.$$typeof === Symbol.for('react.test.json')
},
print(val) {
const components = prettyFormat(val, { plugins: [reactTestPlugin] })
const styles = getStyles(components)
print(val, print) {
const classNames = getClassNames(val, [])
const styles = getStyles(classNames)
val.withStyles = true
return `${styles}\n\n${components}`
return `${styles}\n\n${print(val)}`
},

@@ -29,0 +40,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc