diff --git a/README.md b/README.md
index b93ea512..f71bc3aa 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,8 @@
> A little helper to unit test React components in the open source [Cypress.io](https://www.cypress.io/) E2E test runner **v4.5.0+**
+**Jump to:** [Comparison](#comparison), [Install](#install), Examples: [basic](#basic-examples), [advanced](#advanced-examples), [full](#full-examples), [external](#external-examples), [Options](#options), [Code coverage](#code-coverage), [Visual testing](#visual-testing), [Commoon problems](#common-problems)
+
## TLDR
- What is this? This package allows you to use [Cypress](https://www.cypress.io/) test runner to unit test your React components with zero effort. Here is a typical component testing, notice there is not external URL shown, since it is mounting the component directly.
@@ -64,8 +66,6 @@ module.exports = (on, config) => {
See [Recipes](./docs/recipes.md) for more examples.
-**⚠️ Note:** when using `react-scripts` you must place component specs in the `src` folder too, otherwise they won't be transpiled correctly.
-
3. ⚠️ Turn the experimental component support on in your `cypress.json`. You can also specify where component spec files are located. For example, to have them located in `src` folder use:
```json
@@ -145,7 +145,18 @@ Spec | Description
[react-bootstrap](cypress/component/advanced/react-bootstrap) | Confirms [react-bootstrap](https://react-bootstrap.github.io/) components are working
-### Large examples
+### Full examples
+
+We have several subfolders in [examples](examples) folder that have complete projects with just their dependencies installed in the root folder.
+
+
+Folder Name | Description
+--- | ---
+[react-scripts](examples/react-scripts) | A project using `react-scripts` with component tests in `src` folder
+[react-scripts-folder](examples/react-scripts-folder) | A project using `react-scripts` with component tests in `cypress/component`
+
+
+### External examples
This way of component testing has been verified in a number of forked 3rd party projects.
diff --git a/circle.yml b/circle.yml
index 1ed04169..71ae11c6 100644
--- a/circle.yml
+++ b/circle.yml
@@ -33,6 +33,20 @@ workflows:
command: npm test
store_artifacts: true
+ - cypress/run:
+ # react-scripts example with component tests not in "src" folder
+ # but in "cypress/component" folder
+ name: Example Component Folder
+ requires:
+ - Install
+ # each example installs "cypress-react-unit-test" as a local dependency (symlink)
+ install-command: npm install
+ verify-command: echo 'Already verified'
+ no-workspace: true
+ working_directory: examples/react-scripts-folder
+ command: npm test
+ store_artifacts: true
+
- cypress/run:
name: Test
parallelism: 4
@@ -63,6 +77,7 @@ workflows:
- Install
- Test
- Example React Scripts
+ - Example Component Folder
install-command: echo 'Already installed'
verify-command: echo 'Already verified'
no-workspace: true
diff --git a/examples/react-scripts-folder/.npmrc b/examples/react-scripts-folder/.npmrc
new file mode 100644
index 00000000..43c97e71
--- /dev/null
+++ b/examples/react-scripts-folder/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/examples/react-scripts-folder/README.md b/examples/react-scripts-folder/README.md
new file mode 100644
index 00000000..811959e7
--- /dev/null
+++ b/examples/react-scripts-folder/README.md
@@ -0,0 +1,13 @@
+# example: react-scripts-folder
+
+A typical project using `react-scripts` with components in the [src](src) folder and component tests inside [cypress/component](cypress/component) folder. Cypress automatically finds Webpack settings used by `react-scripts` and inserts the component folder name allowing to transpile the component specs the same way the `src` code is transpiled.
+
+Note: run `npm install` in this folder to symlink `cypress-react-unit-test` dependency.
+
+```shell
+npm run cy:open
+# or just run headless tests
+npm test
+```
+
+
diff --git a/examples/react-scripts-folder/cypress.json b/examples/react-scripts-folder/cypress.json
new file mode 100644
index 00000000..7307c0f7
--- /dev/null
+++ b/examples/react-scripts-folder/cypress.json
@@ -0,0 +1,8 @@
+{
+ "fixturesFolder": false,
+ "testFiles": "**/*cy-spec.js",
+ "viewportWidth": 500,
+ "viewportHeight": 500,
+ "experimentalComponentTesting": true,
+ "componentFolder": "cypress/component"
+}
diff --git a/examples/react-scripts-folder/cypress/component/App.cy-spec.js b/examples/react-scripts-folder/cypress/component/App.cy-spec.js
new file mode 100644
index 00000000..64bdfd4c
--- /dev/null
+++ b/examples/react-scripts-folder/cypress/component/App.cy-spec.js
@@ -0,0 +1,18 @@
+///
+// compare to App.test.js
+import React from 'react'
+import App from '../../src/App'
+import { mount } from 'cypress-react-unit-test'
+
+describe('App', () => {
+ it('renders learn react link', () => {
+ expect(1).to.equal(1)
+ mount()
+ cy.contains(/Learn React/)
+ })
+
+ it('renders inline component', () => {
+ mount(
JSX
)
+ cy.contains('JSX')
+ })
+})
diff --git a/examples/react-scripts/cypress/integration/spec.js b/examples/react-scripts-folder/cypress/integration/cy-spec.js
similarity index 100%
rename from examples/react-scripts/cypress/integration/spec.js
rename to examples/react-scripts-folder/cypress/integration/cy-spec.js
diff --git a/examples/react-scripts-folder/cypress/plugins/index.js b/examples/react-scripts-folder/cypress/plugins/index.js
new file mode 100644
index 00000000..7a27c8cd
--- /dev/null
+++ b/examples/react-scripts-folder/cypress/plugins/index.js
@@ -0,0 +1,7 @@
+const preprocessor = require('../../../../plugins/react-scripts')
+module.exports = (on, config) => {
+ preprocessor(on, config)
+ // IMPORTANT to return the config object
+ // with the any changed environment variables
+ return config
+}
diff --git a/examples/react-scripts-folder/cypress/support/index.js b/examples/react-scripts-folder/cypress/support/index.js
new file mode 100644
index 00000000..6d8199e9
--- /dev/null
+++ b/examples/react-scripts-folder/cypress/support/index.js
@@ -0,0 +1,2 @@
+require('cypress-react-unit-test/support')
+require('@cypress/code-coverage/support')
diff --git a/examples/react-scripts-folder/images/app-test.png b/examples/react-scripts-folder/images/app-test.png
new file mode 100644
index 00000000..49837f1b
Binary files /dev/null and b/examples/react-scripts-folder/images/app-test.png differ
diff --git a/examples/react-scripts-folder/package.json b/examples/react-scripts-folder/package.json
new file mode 100644
index 00000000..d8e5eb84
--- /dev/null
+++ b/examples/react-scripts-folder/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "example-react-scripts-folder",
+ "description": "Handles component tests from cypress folder",
+ "private": true,
+ "scripts": {
+ "test": "../../node_modules/.bin/cypress run",
+ "cy:open": "../../node_modules/.bin/cypress open"
+ },
+ "devDependencies": {
+ "cypress-react-unit-test": "file:../.."
+ }
+}
diff --git a/examples/react-scripts-folder/public/favicon.ico b/examples/react-scripts-folder/public/favicon.ico
new file mode 100644
index 00000000..bcd5dfd6
Binary files /dev/null and b/examples/react-scripts-folder/public/favicon.ico differ
diff --git a/examples/react-scripts-folder/public/index.html b/examples/react-scripts-folder/public/index.html
new file mode 100644
index 00000000..aa069f27
--- /dev/null
+++ b/examples/react-scripts-folder/public/index.html
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ React App
+
+
+
+
+
+
+
diff --git a/examples/react-scripts-folder/public/logo192.png b/examples/react-scripts-folder/public/logo192.png
new file mode 100644
index 00000000..fc44b0a3
Binary files /dev/null and b/examples/react-scripts-folder/public/logo192.png differ
diff --git a/examples/react-scripts-folder/public/logo512.png b/examples/react-scripts-folder/public/logo512.png
new file mode 100644
index 00000000..a4e47a65
Binary files /dev/null and b/examples/react-scripts-folder/public/logo512.png differ
diff --git a/examples/react-scripts-folder/public/manifest.json b/examples/react-scripts-folder/public/manifest.json
new file mode 100644
index 00000000..080d6c77
--- /dev/null
+++ b/examples/react-scripts-folder/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/examples/react-scripts-folder/public/robots.txt b/examples/react-scripts-folder/public/robots.txt
new file mode 100644
index 00000000..e9e57dc4
--- /dev/null
+++ b/examples/react-scripts-folder/public/robots.txt
@@ -0,0 +1,3 @@
+# https://www.robotstxt.org/robotstxt.html
+User-agent: *
+Disallow:
diff --git a/examples/react-scripts-folder/src/App.css b/examples/react-scripts-folder/src/App.css
new file mode 100644
index 00000000..74b5e053
--- /dev/null
+++ b/examples/react-scripts-folder/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/examples/react-scripts-folder/src/App.js b/examples/react-scripts-folder/src/App.js
new file mode 100644
index 00000000..b0511af9
--- /dev/null
+++ b/examples/react-scripts-folder/src/App.js
@@ -0,0 +1,38 @@
+import React from 'react'
+// this CSS will be inlined ✅
+import './App.css'
+import logo from './logo.svg' // => "/__root/src/logo.svg"
+import cypressLogo from './cypress-logo-dark.png' // => "/__root/src/cypress-logo-dark.png"
+
+// large image will be transformed into
+// a different url static/media/vans.25e5784d.jpg
+// import giantImage from './vans.jpg'
+
+// we cannot load the image from direct url
+// import giantImage from '/__root/src/vans.jpg'
+//
+
+function App() {
+ return (
+