jest-styled-components
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "jest-styled-components", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Jest utilities for Styled Components", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -20,8 +20,11 @@ const chalk = require('chalk') | ||
} | ||
if (isAddition(line)) { | ||
return chalk.green(line) | ||
} | ||
if (isDeletion(line)) { | ||
return chalk.red(line) | ||
} | ||
return chalk.gray(line) | ||
@@ -28,0 +31,0 @@ }).join('\n') |
@@ -10,15 +10,37 @@ const css = require('css') | ||
} | ||
if (node.props && node.props.className) { | ||
return classNames.concat(node.props.className.split(' ')) | ||
} | ||
return [] | ||
} | ||
const filterNodes = classNames => rule => ( | ||
rule.type === 'rule' && classNames.includes(rule.selectors[0].substring(1)) | ||
) | ||
const getMediaQueries = (ast, filter) => ( | ||
ast.stylesheet.rules | ||
.filter(rule => rule.type === 'media') | ||
.reduce((acc, mediaQuery) => { | ||
mediaQuery.rules = mediaQuery.rules.filter(filter) | ||
if (mediaQuery.rules.length) { | ||
return acc.concat(mediaQuery) | ||
} | ||
return acc | ||
}, []) | ||
) | ||
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 => ( | ||
rule.type === 'rule' && classNames.includes(rule.selectors[0].substring(1)) | ||
)) | ||
const filter = filterNodes(classNames) | ||
const rules = ast.stylesheet.rules.filter(filter) | ||
const mediaQueries = getMediaQueries(ast, filter) | ||
ast.stylesheet.rules = rules.concat(mediaQueries) | ||
return css.stringify(ast) | ||
@@ -36,2 +58,3 @@ } | ||
const styles = getStyles(classNames) | ||
val.withStyles = true | ||
@@ -38,0 +61,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6019
91