Skip to content

Commit

Permalink
drop v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Feb 24, 2018
1 parent 19bca15 commit 94a85f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Table of Contents
* [Preact](#preact)
* [toHaveStyleRule](#tohavestylerule)
* [Global installation](#global-installation)
* [styled-components < v2](#styled-components--v2)
* [Contributing](#contributing)

# Snapshot Testing
Expand Down Expand Up @@ -370,17 +369,6 @@ And import the library once in the `setupTest.js` as follows:
import 'jest-styled-components'
```

# styled-components < v2

To use this package with styled-components < v2 (e.g. v1.4.6) the following annotation must be added at the top of the test files.
Consequently, it won't be possible to use Enzyme's full DOM rendering.

```js
/**
* @jest-environment node
*/
```

# Contributing

Please [open an issue](https://github.com/styled-components/jest-styled-components/issues/new) and discuss with us before submitting a PR.
7 changes: 2 additions & 5 deletions src/styleSheetSerializer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const css = require('css')
const { getCSS, getHashes, isOverV2 } = require('./utils')
const { getCSS, getHashes } = require('./utils')

const KEY = '__jest-styled-components__'

Expand Down Expand Up @@ -99,10 +99,7 @@ const styleSheetSerializer = {

const hashes = getHashes()
let classNames = [...getClassNames(nodes)]

if (isOverV2()) {
classNames = filterClassNames(classNames, hashes)
}
classNames = filterClassNames(classNames, hashes)

const style = getStyle(classNames)
const code = print(val)
Expand Down
33 changes: 6 additions & 27 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const css = require('css')
const { ServerStyleSheet, isStyledComponent } = require('styled-components')

const isOverV3 = !!isStyledComponent
const isOverV2 = () => !!ServerStyleSheet

let StyleSheet

/* eslint-disable */
if (isOverV3) {
if (!!isStyledComponent) {
const secretInternals = require('styled-components')
.__DO_NOT_USE_OR_YOU_WILL_BE_HAUNTED_BY_SPOOKY_GHOSTS

Expand All @@ -28,11 +25,7 @@ if (isOverV3) {

const isServer = () => typeof document === 'undefined'

const resetStyleSheet = () => {
if (isOverV2()) {
StyleSheet.reset(isServer())
}
}
const resetStyleSheet = () => StyleSheet.reset(isServer())

const getHTML = () =>
isServer()
Expand All @@ -52,18 +45,7 @@ const extract = regex => {

const getStyle = () => extract(/<style[^>]*>([^<]*)</g)

const getRules = () =>
StyleSheet.globalStyleSheet.sheet && StyleSheet.componentStyleSheet.sheet
? StyleSheet.rules()
.map(rule => rule.cssText)
.join('\n')
: ''

const getCSS = () => {
const style = isOverV2() ? getStyle() : getRules()

return css.parse(style)
}
const getCSS = () => css.parse(getStyle())

const getClassNames = () =>
extract(/data-styled-components="([^"]*)"/g).split(/\s/)
Expand All @@ -72,14 +54,11 @@ const getComponentIDs = () =>
extract(/sc-component-id: ([^\\*\\/]*) \*\//g).split(/\s/)

const getHashes = () =>
isOverV2()
? getClassNames()
.concat(getComponentIDs())
.filter(Boolean)
: []
getClassNames()
.concat(getComponentIDs())
.filter(Boolean)

module.exports = {
isOverV2,
resetStyleSheet,
getCSS,
getHashes,
Expand Down

0 comments on commit 94a85f2

Please sign in to comment.