@wordpress/jest-preset-default 9.1.1-next.4d3b314fd5.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,64 @@ npm install @wordpress/jest-preset-default --save-dev
36
36
  - `transform` - keeps the default [babel-jest](https://github.com/facebook/jest/tree/HEAD/packages/babel-jest) transformer.
37
37
  - `verbose` - each individual test won't be reported during the run.
38
38
 
39
+ #### Using enzyme
40
+
41
+ Historically, this package used to use `enzyme`, but support was dropped in favor of `@testing-library/react`, primary reason being unblocking the upgrade to React 18.
42
+
43
+ If you wish to use `enzyme`, you can still use it by manually providing the React 17 adapter, by following the steps below.
44
+
45
+ To install the enzyme dependency, run:
46
+
47
+ ```bash
48
+ npm install --save enzyme
49
+ ```
50
+
51
+ To install the React 17 adapter dependency, run:
52
+
53
+ ```bash
54
+ npm install --save @wojtekmaj/enzyme-adapter-react-17
55
+ ```
56
+
57
+ To use the React 17 adapter, use this in your [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array) configuration:
58
+
59
+ ```javascript
60
+ // It "mocks" enzyme, so that we can delay loading of
61
+ // the utility functions until enzyme is imported in tests.
62
+ // Props to @gdborton for sharing this technique in his article:
63
+ // https://medium.com/airbnb-engineering/unlocking-test-performance-migrating-from-mocha-to-jest-2796c508ec50.
64
+ let mockEnzymeSetup = false;
65
+
66
+ jest.mock( 'enzyme', () => {
67
+ const actualEnzyme = jest.requireActual( 'enzyme' );
68
+ if ( ! mockEnzymeSetup ) {
69
+ mockEnzymeSetup = true;
70
+
71
+ // Configure enzyme 3 for React, from docs: http://airbnb.io/enzyme/docs/installation/index.html
72
+ const Adapter = jest.requireActual(
73
+ '@wojtekmaj/enzyme-adapter-react-17'
74
+ );
75
+ actualEnzyme.configure( { adapter: new Adapter() } );
76
+ }
77
+ return actualEnzyme;
78
+ } );
79
+ ```
80
+
81
+ If you also use snapshot tests with `enzyme`, you might want to add support for serializing them, through the `enzyme-to-json` package.
82
+
83
+ To install the dependency, run:
84
+
85
+ ```bash
86
+ npm install --save enzyme-to-json
87
+ ```
88
+
89
+ Finally, you should add `enzyme-to-json/serializer` to the array of [`snapshotSerializers`](https://jestjs.io/docs/configuration#snapshotserializers-arraystring):
90
+
91
+ ```javascript
92
+ {
93
+ snapshotSerializers: [ 'enzyme-to-json/serializer' ]
94
+ }
95
+ ```
96
+
39
97
  ## Contributing to this package
40
98
 
41
99
  This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
package/jest-preset.js CHANGED
@@ -17,7 +17,6 @@ module.exports = {
17
17
  '@wordpress/jest-preset-default/scripts/setup-test-framework.js'
18
18
  ),
19
19
  ],
20
- snapshotSerializers: [ require.resolve( 'enzyme-to-json/serializer.js' ) ],
21
20
  testEnvironment: 'jsdom',
22
21
  testMatch: [
23
22
  '**/__tests__/**/*.[jt]s?(x)',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/jest-preset-default",
3
- "version": "9.1.1-next.4d3b314fd5.0",
3
+ "version": "10.0.0",
4
4
  "description": "Default Jest preset for WordPress development.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -9,8 +9,7 @@
9
9
  "gutenberg",
10
10
  "jest",
11
11
  "preset",
12
- "react",
13
- "enzyme"
12
+ "react"
14
13
  ],
15
14
  "homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/jest-preset-default/README.md",
16
15
  "repository": {
@@ -31,11 +30,8 @@
31
30
  ],
32
31
  "main": "index.js",
33
32
  "dependencies": {
34
- "@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
35
- "@wordpress/jest-console": "^6.1.1-next.4d3b314fd5.0",
36
- "babel-jest": "^27.4.5",
37
- "enzyme": "^3.11.0",
38
- "enzyme-to-json": "^3.4.4"
33
+ "@wordpress/jest-console": "^6.2.0",
34
+ "babel-jest": "^27.4.5"
39
35
  },
40
36
  "peerDependencies": {
41
37
  "@babel/core": ">=7",
@@ -46,5 +42,5 @@
46
42
  "publishConfig": {
47
43
  "access": "public"
48
44
  },
49
- "gitHead": "25054766423cb49d959eb656c2533530073ff5c2"
45
+ "gitHead": "8d42d2febb7d0ba8372a33e560a62f5a5f6a9112"
50
46
  }
@@ -1,21 +1 @@
1
1
  require( '@wordpress/jest-console' );
2
-
3
- // It "mocks" enzyme, so that we can delay loading of
4
- // the utility functions until enzyme is imported in tests.
5
- // Props to @gdborton for sharing this technique in his article:
6
- // https://medium.com/airbnb-engineering/unlocking-test-performance-migrating-from-mocha-to-jest-2796c508ec50.
7
- let mockEnzymeSetup = false;
8
-
9
- jest.mock( 'enzyme', () => {
10
- const actualEnzyme = jest.requireActual( 'enzyme' );
11
- if ( ! mockEnzymeSetup ) {
12
- mockEnzymeSetup = true;
13
-
14
- // Configure enzyme 3 for React, from docs: http://airbnb.io/enzyme/docs/installation/index.html
15
- const Adapter = jest.requireActual(
16
- '@wojtekmaj/enzyme-adapter-react-17'
17
- );
18
- actualEnzyme.configure( { adapter: new Adapter() } );
19
- }
20
- return actualEnzyme;
21
- } );