Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enzyme adapter 17 #1

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bcab26a
[New] add `enzyme-adapter-react-17`
ljharb Aug 10, 2020
a1541ea
feat: add an adapter for React 17
layershifter Aug 12, 2020
64c15dd
add versions to CI
layershifter Aug 12, 2020
4840ec4
version updates
layershifter Aug 12, 2020
027f4ed
offscreencomponent wip
ljharb Oct 26, 2020
143abed
test TODOs
ljharb Jan 20, 2021
d4442b1
Remove TODO_17 tags
createthis Aug 10, 2021
41c69ed
Fix two failing tests by using less fragile syntax.
createthis Aug 10, 2021
d115a03
Fix another test with fragile matching.
createthis Aug 10, 2021
14c5b61
componentWillReceiveProps and UNSAFE_componentWillReceiveProps removed
createthis Aug 10, 2021
69ca1dd
Fix shallow() so that it calls componentWillReceiveProps() and
createthis Aug 11, 2021
360abe7
Forgot a test case. Call componentWillReceiveProps() even when shallow
createthis Aug 11, 2021
4a2bb7b
displayNameOfNode gets a little wonky when used with React.memo and
createthis Aug 11, 2021
e5aabce
punt on the simulate failure. I worked on this all day yesterday and
createthis Aug 13, 2021
6de291b
Make a few changes I saw https://github.com/wojtekmaj requested in the
createthis Aug 13, 2021
c85b394
Add tip from https://github.com/ljharb to CONTRIBUTING
createthis Aug 13, 2021
31e0b17
Restore suspense tests to the best of my ability.
createthis Aug 13, 2021
2201a77
createReactClass and React.Component pass the same check
eps1lon Aug 2, 2022
7ffe370
Remove unused TODO_17
eps1lon Aug 2, 2022
6f3d912
Adjust displayname test to be invariant across React versions
eps1lon Aug 2, 2022
71bd3ee
Fix displayNameOfNode for Memo components
eps1lon Aug 2, 2022
fb9f79a
Fix isEmptyRender for SimpleMemoComponent
eps1lon Aug 3, 2022
c3c708b
Ensure Suspense tests are the same in 16 and 17
eps1lon Aug 3, 2022
6f4e2e8
Remove React 16 logic that is no longer covered by tests
eps1lon Aug 3, 2022
1f9f081
Remove no obsolete "supports*" checks when detecting Fiber tags
eps1lon Aug 3, 2022
2b4026a
node_modules/.bin -> npx
eps1lon Aug 9, 2022
fdcaae9
Revert .gitignore changes from base branch
eps1lon Aug 9, 2022
46cf1b6
Remove outdated comment
eps1lon Aug 9, 2022
6197cb8
Simplify semver matcher for create-react-class
eps1lon Aug 9, 2022
c80a860
[enzyme-adapter-react-17]: make it publishable
aks- Feb 15, 2024
2e900ce
[enzyme-adapter-17]: update readme
aks- Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,3 @@ packages/*/LICENSE.md
packages/enzyme/README.md
packages/enzyme-adapter-react-*/README.md
packages/enzyme-adapter-utils*/README.md

.npmignore
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ npm run build:watch
npm run test:watch
```

Alternatively, run this in one terminal tab:
```bash
# build Enzyme locally upon save
npm run build:watch
```

In another terminal tab execute a specific test file for faster TDD test execution:
```bash
npx mocha packages/enzyme-test-suite/build/ReactWrapper-spec.js
```

NOTE that this alternate strategy may fail to rebuild some code and will bypass lint, so `npm test` will still be necessary periodically.

### Tests for functionality shared between `shallow` and `mount`

Tests for a method "foo" are stored in `packages/enzyme-test-suite/test/shared/methods/foo`. The file default exports a function that receives an injected object argument, containing the following properties:
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ moving on to Enzyme v3 where React 16 is supported.

To get started with enzyme, you can simply install it via npm. You will need to install enzyme
along with an Adapter corresponding to the version of react (or other UI Component library) you
are using. For instance, if you are using enzyme with React 16, you can run:
are using. For instance, if you are using enzyme with React 17, you can run:

```bash
npm i --save-dev enzyme enzyme-adapter-react-16
npm i --save-dev enzyme enzyme-adapter-react-17
```

Each adapter may have additional peer dependencies which you will need to install as well. For instance,
`enzyme-adapter-react-16` has peer dependencies on `react` and `react-dom`.
`enzyme-adapter-react-17` has peer dependencies on `react` and `react-dom`.

At the moment, Enzyme has adapters that provide compatibility with `React 16.x`, `React 15.x`,
At the moment, Enzyme has adapters that provide compatibility with `React 17.x`, `React 16.x`, `React 15.x`,
`React 0.14.x` and `React 0.13.x`.

The following adapters are officially provided by enzyme, and have the following compatibility with
React:

| Enzyme Adapter Package | React semver compatibility |
| --- | --- |
| `enzyme-adapter-react-17` | `^17.0.0-0` |
| `enzyme-adapter-react-16` | `^16.4.0-0` |
| `enzyme-adapter-react-16.3` | `~16.3.0-0` |
| `enzyme-adapter-react-16.2` | `~16.2` |
Expand All @@ -54,7 +55,7 @@ the top level `configure(...)` API.

```js
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Adapter from 'enzyme-adapter-react-17';

Enzyme.configure({ adapter: new Adapter() });
```
Expand Down
3 changes: 3 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ function getAdapter(reactVersion) {
return '16.1';
}
}
if (semver.intersects(reactVersion, '^17.0.0')) {
return '17';
}
return null;
}
const reactVersion = version < 15 ? '0.' + version : version;
Expand Down
2 changes: 1 addition & 1 deletion install-relevant-react.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

REACT="${REACT:-${1:-16}}"
REACT="${REACT:-${1:-17}}"

echo "installing React $REACT"

Expand Down
4 changes: 4 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ function getPlugins() {
const adapter162 = new IgnorePlugin(/enzyme-adapter-react-16.2$/);
const adapter163 = new IgnorePlugin(/enzyme-adapter-react-16.3$/);
const adapter16 = new IgnorePlugin(/enzyme-adapter-react-16$/);
const adapter17 = new IgnorePlugin(/enzyme-adapter-react-17$/);

var plugins = [
adapter13,
adapter14,
adapter154,
adapter15,
adapter16,
adapter17,
];

function not(x) {
Expand All @@ -48,6 +50,8 @@ function getPlugins() {
plugins = plugins.filter(not(adapter163));
} else if (is('^16.4.0-0')) {
plugins = plugins.filter(not(adapter16));
} else if (is('^17.0.0')) {
plugins = plugins.filter(not(adapter17));
}

return plugins;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test:watch": "npm run test:only -- --watch",
"pretest:karma": "npm run build",
"test:karma": "karma start",
"test:all": "npm run react 13 && npm run test:only && npm run react 14 && npm run test:only && npm run react 15 && npm run test:only && npm run react 15.4 && npm run test:only && npm run react 15.5 && npm run test:only && npm run react 16 && npm run test:only && npm run react 16.1 && npm run test:only && npm run react 16.2 && npm run test:only && npm run react 16.3 && npm run test:only && npm run react 16.4 && npm run test:only && npm run react 16.5 && npm run test:only && npm run react 16.8 && npm run test:only",
"test:all": "npm run react 13 && npm run test:only && npm run react 14 && npm run test:only && npm run react 15 && npm run test:only && npm run react 15.4 && npm run test:only && npm run react 15.5 && npm run test:only && npm run react 16 && npm run test:only && npm run react 16.1 && npm run test:only && npm run react 16.2 && npm run test:only && npm run react 16.3 && npm run test:only && npm run react 16.4 && npm run test:only && npm run react 16.5 && npm run test:only && npm run react 16.8 && npm run test:only && npm run react 17 && npm run test:only",
"react": "sh install-relevant-react.sh",
"env:": "babel-node ./env.js",
"docs:clean": "rimraf _book",
Expand Down
9 changes: 9 additions & 0 deletions packages/enzyme-adapter-react-17/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["airbnb", { "transformRuntime": false }],
],
"plugins": [
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
],
"sourceMaps": "both",
}
1 change: 1 addition & 0 deletions packages/enzyme-adapter-react-17/.eslintignore
22 changes: 22 additions & 0 deletions packages/enzyme-adapter-react-17/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "airbnb",
"parser": "babel-eslint",
"root": true,
"rules": {
"max-classes-per-file": 0,
"max-len": 0,
"import/no-extraneous-dependencies": 2,
"import/no-unresolved": 2,
"import/extensions": 2,
"react/no-deprecated": 0,
"react/no-find-dom-node": 0,
"react/no-multi-comp": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 0
},
"settings": {
"react": {
"version": "17",
},
},
}
1 change: 1 addition & 0 deletions packages/enzyme-adapter-react-17/.npmignore
1 change: 1 addition & 0 deletions packages/enzyme-adapter-react-17/.npmrc
74 changes: 74 additions & 0 deletions packages/enzyme-adapter-react-17/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "enzyme-adapter-react-17",
"version": "0.0.0",
"description": "JavaScript Testing utilities for React",
"homepage": "https://enzymejs.github.io/enzyme/",
"main": "build",
"scripts": {
"clean": "rimraf build",
"lint": "eslint --ext js,jsx .",
"pretest": "npm run lint",
"prebuild": "npm run clean",
"build": "babel --source-maps=both src --out-dir build",
"watch": "npm run build -- -w",
"prepublish": "not-in-publish || (npm run build && safe-publish-latest && cp ../../{LICENSE,README}.md ./)"
},
"repository": {
"type": "git",
"url": "https://github.com/enzymejs/enzyme.git",
"directory": "packages/enzyme-adapter-react-17"
},
"keywords": [
"javascript",
"shallow rendering",
"shallowRender",
"test",
"reactjs",
"react",
"flux",
"testing",
"test utils",
"assertion helpers",
"tdd",
"mocha"
],
"author": "Jordan Harband <[email protected]>",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.13.1",
"enzyme-shallow-equal": "^1.0.4",
"has": "^1.0.3",
"object.assign": "^4.1.0",
"object.values": "^1.1.1",
"prop-types": "^15.7.2",
"react-is": "^17.0.0",
"react-reconciler": "^0.26.1",
"react-test-renderer": "^17.0.0",
"semver": "^5.7.0"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-replace-object-assign": "^2.0.0",
"babel-preset-airbnb": "^4.5.0",
"enzyme": "^3.0.0",
"eslint": "^7.6.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.5",
"eslint-plugin-react-hooks": "^4.0.8",
"in-publish": "^2.0.1",
"rimraf": "^2.7.1",
"safe-publish-latest": "^1.1.4"
}
}
Loading