diff --git a/.travis.yml b/.travis.yml index 567b9e534..8179f0695 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,10 @@ matrix: - node_js: "lts/*" env: LINT=true stage: test + - node_js: "lts/*" + env: CRA=true REACT=16 + script: 'cd packages/enzyme-example-cra && npm run tests-only' + stage: test - node_js: "8" env: REACT=16 stage: test diff --git a/packages/enzyme-example-cra/.env b/packages/enzyme-example-cra/.env new file mode 100644 index 000000000..6f809cc25 --- /dev/null +++ b/packages/enzyme-example-cra/.env @@ -0,0 +1 @@ +SKIP_PREFLIGHT_CHECK=true diff --git a/packages/enzyme-example-cra/.eslintrc b/packages/enzyme-example-cra/.eslintrc new file mode 100644 index 000000000..5ac98674b --- /dev/null +++ b/packages/enzyme-example-cra/.eslintrc @@ -0,0 +1,13 @@ +{ + "overrides": [ + { + "files": ["src/setupTests.*", "src/*.test.*"], + "env": { + "jest": true, + }, + "rules": { + "import/no-extraneous-dependencies": [2, { devDependencies: true }], + }, + }, + ], +} diff --git a/packages/enzyme-example-cra/.gitignore b/packages/enzyme-example-cra/.gitignore new file mode 100644 index 000000000..4d29575de --- /dev/null +++ b/packages/enzyme-example-cra/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/packages/enzyme-example-cra/.npmrc b/packages/enzyme-example-cra/.npmrc new file mode 100644 index 000000000..43c97e719 --- /dev/null +++ b/packages/enzyme-example-cra/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/enzyme-example-cra/README.md b/packages/enzyme-example-cra/README.md new file mode 100644 index 000000000..0c83cde2c --- /dev/null +++ b/packages/enzyme-example-cra/README.md @@ -0,0 +1,70 @@ +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.\ +You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `npm run build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/packages/enzyme-example-cra/package.json b/packages/enzyme-example-cra/package.json new file mode 100644 index 000000000..444d09696 --- /dev/null +++ b/packages/enzyme-example-cra/package.json @@ -0,0 +1,37 @@ +{ + "name": "enzyme-example-cra", + "version": "0.1.0", + "private": true, + "dependencies": { + "react": "^16.14.0", + "react-dom": "^16.14.0", + "react-scripts": "^3.4.4", + "web-vitals": "^0.2.4" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "pretest": "npm run lint", + "tests-only": "react-scripts test", + "test": "react-scripts test", + "eject": "react-scripts eject", + "lint": "eslint ." + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "devDependencies": { + "enzyme": "^3.11.0", + "enzyme-adapter-react-16": "^1.15.5", + "eslint-config-react-app": "^6.0.0" + } +} diff --git a/packages/enzyme-example-cra/public/favicon.ico b/packages/enzyme-example-cra/public/favicon.ico new file mode 100644 index 000000000..a11777cc4 Binary files /dev/null and b/packages/enzyme-example-cra/public/favicon.ico differ diff --git a/packages/enzyme-example-cra/public/index.html b/packages/enzyme-example-cra/public/index.html new file mode 100644 index 000000000..aa069f27c --- /dev/null +++ b/packages/enzyme-example-cra/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/packages/enzyme-example-cra/public/logo192.png b/packages/enzyme-example-cra/public/logo192.png new file mode 100644 index 000000000..fc44b0a37 Binary files /dev/null and b/packages/enzyme-example-cra/public/logo192.png differ diff --git a/packages/enzyme-example-cra/public/logo512.png b/packages/enzyme-example-cra/public/logo512.png new file mode 100644 index 000000000..a4e47a654 Binary files /dev/null and b/packages/enzyme-example-cra/public/logo512.png differ diff --git a/packages/enzyme-example-cra/public/manifest.json b/packages/enzyme-example-cra/public/manifest.json new file mode 100644 index 000000000..080d6c77a --- /dev/null +++ b/packages/enzyme-example-cra/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/packages/enzyme-example-cra/public/robots.txt b/packages/enzyme-example-cra/public/robots.txt new file mode 100644 index 000000000..e9e57dc4d --- /dev/null +++ b/packages/enzyme-example-cra/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/packages/enzyme-example-cra/src/App.css b/packages/enzyme-example-cra/src/App.css new file mode 100644 index 000000000..74b5e0534 --- /dev/null +++ b/packages/enzyme-example-cra/src/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/packages/enzyme-example-cra/src/App.jsx b/packages/enzyme-example-cra/src/App.jsx new file mode 100644 index 000000000..ce9cbd294 --- /dev/null +++ b/packages/enzyme-example-cra/src/App.jsx @@ -0,0 +1,26 @@ +import React from 'react'; +import logo from './logo.svg'; +import './App.css'; + +function App() { + return ( +
+
+ logo +

+ Edit src/App.js and save to reload. +

+ + Learn React + +
+
+ ); +} + +export default App; diff --git a/packages/enzyme-example-cra/src/App.test.jsx b/packages/enzyme-example-cra/src/App.test.jsx new file mode 100644 index 000000000..7209c32a8 --- /dev/null +++ b/packages/enzyme-example-cra/src/App.test.jsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +import App from './App'; + +test('renders learn react link', () => { + const wrapper = shallow(); + expect(wrapper.is('div')).toEqual(true); +}); diff --git a/packages/enzyme-example-cra/src/Context.test.jsx b/packages/enzyme-example-cra/src/Context.test.jsx new file mode 100644 index 000000000..7c4c85b4e --- /dev/null +++ b/packages/enzyme-example-cra/src/Context.test.jsx @@ -0,0 +1,83 @@ +import React from 'react'; +import { mount } from 'enzyme'; + +const initial =
; +const Context = React.createContext(initial); +const { Consumer, Provider } = Context; + +class Component extends React.Component { + static contextType = Context; + + render() { + return this.context || null; + } +} + +function SFC() { + return {(value) => value}; +} + +/* +function WithHook() { + const context = React.useContext(Context); + return context || null; +} + +describe('shallow', () => { +}); +*/ + +describe('mount', () => { + [ + [Component, 'a class component'], + [SFC, 'an SFC using Consumer'], + // [WithHook, 'an SFC with useContext hook'], + ].forEach(([C, desc]) => { + it(`works with ${desc}`, () => { + const wrapper = mount(); + + expect(wrapper.debug()).toEqual(`<${C.name}> +
+`); + }); + + it(`works with ${desc} with an inline Provider`, () => { + const wrapper = mount(); + + expect(wrapper.debug()).toEqual(`<${C.name} />`); + }); + + it(`works with ${desc} with an inline Provider with a value`, () => { + const wrapper = mount(}>); + + expect(wrapper.debug()).toEqual(`<${C.name}> +