Skip to content

Commit e5d43fc

Browse files
authored
Drop Enzyme's support (#3292)
* Drop Enzyme's support * update lockfile * update snapshots * rename to setup-env * update snapshots agains
1 parent 6158389 commit e5d43fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+87
-2010
lines changed

.changeset/polite-items-cheat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/jest': major
3+
---
4+
5+
Drop support for Enzyme

docs/testing.mdx

+1-18
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,9 @@ import { createSerializer } from '@emotion/jest'
3232
expect.addSnapshotSerializer(createSerializer())
3333
```
3434

35-
When using Enzyme, you can add `"@emotion/jest/enzyme-serializer"` instead.
36-
37-
```json
38-
{
39-
"snapshotSerializers": ["@emotion/jest/enzyme-serializer"]
40-
}
41-
```
42-
43-
Or use `expect.addSnapshotSerializer` to add it like this:
44-
45-
```javascript
46-
// also adds the enzyme-to-json serializer
47-
import { createEnzymeSerializer } from '@emotion/jest/enzyme-serializer'
48-
49-
expect.addSnapshotSerializer(createEnzymeSerializer())
50-
```
51-
5235
### Writing a test
5336

54-
Writing a test with `@emotion/jest` involves creating a snapshot from the `react-test-renderer` or `enzyme-to-json`'s resulting JSON.
37+
Writing a test with `@emotion/jest` involves creating a snapshot from the `react-test-renderer`'s resulting JSON.
5538

5639
```jsx
5740
import React from 'react'

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,6 @@
201201
"bundlesize": "^0.13.2",
202202
"codecov": "^2.3.1",
203203
"cssjanus": "^1.2.0",
204-
"enzyme": "^3.11.0",
205-
"enzyme-adapter-react-16": "^1.15.5",
206-
"enzyme-to-json": "^3.6.1",
207204
"eslint": "^8.57.0",
208205
"eslint-config-prettier": "^9.1.0",
209206
"eslint-config-react": "^1.1.7",

packages/cache/__tests__/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @jsx jsx */
2-
import 'test-utils/next-env'
2+
import 'test-utils/setup-env'
33
import { safeQuerySelector } from 'test-utils'
44
import createCache from '@emotion/cache'
55
import { jsx, CacheProvider } from '@emotion/react'

packages/css/test/__snapshots__/selectivity.test.js.snap

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,62 @@ exports[`css complex nested media queries 1`] = `
1515
`;
1616

1717
exports[`css complex nested styles 1`] = `
18-
".css-52fshx {
18+
".css-1fh6au3 {
1919
color: blue;
2020
}
2121
22-
.css-52fshx:hover {
22+
.css-1fh6au3:hover {
2323
color: green;
2424
}
2525
26-
.css-52fshx:hover .name {
26+
.css-1fh6au3:hover .name {
2727
color: amethyst;
2828
}
2929
30-
.css-52fshx:hover .name:focus {
30+
.css-1fh6au3:hover .name:focus {
3131
color: burlywood;
3232
}
3333
3434
@media (min-width: 420px) {
35-
.css-52fshx:hover .name:focus {
35+
.css-1fh6au3:hover .name:focus {
3636
color: rebeccapurple;
3737
}
3838
}"
3939
`;
4040

4141
exports[`css handles media query merges 1`] = `
42-
".css-19kb3dc {
42+
".css-uzr6q5 {
4343
color: darkslateblue;
4444
color: red;
4545
color: purple;
4646
}
4747
4848
@media (min-width: 420px) {
49-
.css-19kb3dc {
49+
.css-uzr6q5 {
5050
color: amethyst;
5151
}
5252
}
5353
5454
@media (min-width: 640px) {
55-
.css-19kb3dc {
55+
.css-uzr6q5 {
5656
color: rebeccapurple;
5757
}
5858
}
5959
6060
@media (min-width: 960px) {
61-
.css-19kb3dc {
61+
.css-uzr6q5 {
6262
color: burlywood;
6363
}
6464
}
6565
6666
@media (min-width: 640px) {
67-
.css-19kb3dc {
67+
.css-uzr6q5 {
6868
color: blue;
6969
}
7070
}
7171
7272
@media (min-width: 640px) {
73-
.css-19kb3dc {
73+
.css-uzr6q5 {
7474
color: aquamarine;
7575
}
7676
}"

packages/css/test/component-selector.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import styled from '@emotion/styled'
44
import renderer from 'react-test-renderer'

packages/css/test/css.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css, flush, sheet } from '@emotion/css'

packages/css/test/cx.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css, cx } from '@emotion/css'

packages/css/test/inject-global.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import { injectGlobal, sheet, flush, css } from '@emotion/css'
33

44
describe('injectGlobal', () => {

packages/css/test/instance/css.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/next-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css as differentCss, flush, sheet } from './emotion-instance'

packages/css/test/keyframes.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { keyframes, flush, css } from '@emotion/css'
@@ -13,17 +13,17 @@ describe('keyframes', () => {
1313
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
1414
transform: translate3d(0,0,0);
1515
}
16-
16+
1717
40%, 43% {
1818
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
1919
transform: translate3d(0, -30px, 0);
2020
}
21-
21+
2222
70% {
2323
animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
2424
transform: translate3d(0, -15px, 0);
2525
}
26-
26+
2727
90% {
2828
transform: translate3d(0,-4px,0);
2929
}
@@ -54,7 +54,7 @@ describe('keyframes', () => {
5454
from {
5555
transform: rotate(0deg);
5656
}
57-
57+
5858
to {
5959
transform: rotate(${endingRotation});
6060
}

packages/css/test/label-pattern.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import styled from '@emotion/styled'
44
import renderer from 'react-test-renderer'

packages/css/test/no-babel/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import React from 'react'
33
import renderer from 'react-test-renderer'
44
import { css } from '@emotion/css'

packages/css/test/no-babel/warnings.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import { css } from '@emotion/css'
33

44
console.error = jest.fn()

packages/css/test/selectivity.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import { css, sheet, flush } from '@emotion/css'
33

44
describe('css', () => {

packages/css/test/source-map/__snapshots__/source-map.test.js.snap

+14-14
Large diffs are not rendered by default.

packages/css/test/source-map/source-map.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import { css, sheet, flush } from '@emotion/css'
33

44
const commentPattern = /\/\*[\s\S]*?\*\//g

packages/css/test/warnings.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'test-utils/legacy-env'
1+
import 'test-utils/setup-env'
22
import { css } from '@emotion/css'
33
import createCss from '@emotion/css/create-instance'
44
import * as React from 'react'

packages/jest/README.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,7 @@ module.exports = {
2222
}
2323
```
2424

25-
To assist with shallow rendering, there's a custom enzyme snapshot serializer, that includes the `enzyme-to-json` serializer, which is available by importing `@emotion/jest/enzyme-serializer`. If you already have the `enzyme-to-json` serializer added to `snapshotSerializers`, it will need to be removed to allow this to work.
26-
27-
```js
28-
// jest.config.js
29-
module.exports = {
30-
// ... other config
31-
snapshotSerializers: ['@emotion/jest/enzyme-serializer']
32-
}
33-
```
34-
35-
Or you can add the serializer via the `expect.addSnapshotSerializer` method like so: (the example below is with react-test-renderer but @emotion/jest also works with enzyme and react-testing-library)
25+
Or you can add the serializer via the `expect.addSnapshotSerializer` method like so:
3626

3727
```jsx
3828
import React from 'react'

packages/jest/enzyme-serializer/package.json

-5
This file was deleted.

packages/jest/enzyme/package.json

-4
This file was deleted.

packages/jest/package.json

+1-21
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
"import": "./dist/emotion-jest.cjs.mjs",
1515
"default": "./dist/emotion-jest.cjs.js"
1616
},
17-
"./enzyme": {
18-
"types": {
19-
"import": "./enzyme/dist/emotion-jest-enzyme.cjs.mjs",
20-
"default": "./enzyme/dist/emotion-jest-enzyme.cjs.js"
21-
},
22-
"module": "./enzyme/dist/emotion-jest-enzyme.esm.js",
23-
"import": "./enzyme/dist/emotion-jest-enzyme.cjs.mjs",
24-
"default": "./enzyme/dist/emotion-jest-enzyme.cjs.js"
25-
},
2617
"./serializer": {
2718
"types": {
2819
"import": "./serializer/dist/emotion-jest-serializer.cjs.mjs",
@@ -32,15 +23,6 @@
3223
"import": "./serializer/dist/emotion-jest-serializer.cjs.mjs",
3324
"default": "./serializer/dist/emotion-jest-serializer.cjs.js"
3425
},
35-
"./enzyme-serializer": {
36-
"types": {
37-
"import": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.mjs",
38-
"default": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.js"
39-
},
40-
"module": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.esm.js",
41-
"import": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.mjs",
42-
"default": "./enzyme-serializer/dist/emotion-jest-enzyme-serializer.cjs.js"
43-
},
4426
"./package.json": "./package.json"
4527
},
4628
"types": "types/index.d.ts",
@@ -104,9 +86,7 @@
10486
"preconstruct": {
10587
"entrypoints": [
10688
"./index.js",
107-
"./serializer.js",
108-
"./enzyme.js",
109-
"./enzyme-serializer.js"
89+
"./serializer.js"
11090
]
11191
}
11292
}

0 commit comments

Comments
 (0)