Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit f1f6e4c

Browse files
committed
feat: specify custom paths to React and React DOM, close #66
1 parent 14f0f33 commit f1f6e4c

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ describe('HelloState component', () => {
6363

6464
![Unit testing React components](images/demo.png)
6565

66+
## Configuration
67+
68+
If your React and React DOM libraries are installed in non-standard paths (think monorepo scenario), you can tell this plugin where to find them. In `cypress.json` specify paths like this:
69+
70+
```json
71+
{
72+
"env": {
73+
"cypress-react-unit-test": {
74+
"react": "node_modules/react/umd/react.development.js",
75+
"react-dom": "node_modules/react-dom/umd/react-dom.development.js"
76+
}
77+
}
78+
}
79+
```
80+
6681
## Transpilation
6782

6883
How can we use features that require transpilation? Using [@cypress/webpack-preprocessor](https://github.com/cypress-io/cypress-webpack-preprocessor#readme). You can use [cypress/plugins/index.js](cypress/plugins/index.js) to configure any transpilation plugins you need.

cypress.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"viewportHeight": 100,
44
"video": false,
55
"projectId": "z9dxah",
6-
"ignoreTestFiles": "*.css"
6+
"ignoreTestFiles": "*.css",
7+
"env": {
8+
"cypress-react-unit-test": {
9+
"react": "node_modules/react/umd/react.development.js",
10+
"react-dom": "node_modules/react-dom/umd/react-dom.development.js"
11+
}
12+
}
713
}

lib/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,6 @@ Cypress.Commands.overwrite('get', (originalFn, selector, options) => {
166166
}
167167
})
168168

169-
const moduleNames = [
170-
{
171-
name: 'react',
172-
type: 'file',
173-
location: 'node_modules/react/umd/react.development.js'
174-
},
175-
{
176-
name: 'react-dom',
177-
type: 'file',
178-
location: 'node_modules/react-dom/umd/react-dom.development.js'
179-
}
180-
]
181-
182169
/*
183170
Before All
184171
- Load and cache UMD modules specified in fixtures/modules.json
@@ -187,6 +174,21 @@ Before All
187174
Format: [{name, type, location}, ...]
188175
*/
189176
before(() => {
177+
const settings = Cypress.env('cypress-react-unit-test') || {}
178+
179+
const moduleNames = [
180+
{
181+
name: 'react',
182+
type: 'file',
183+
location: settings.react || 'node_modules/react/umd/react.development.js'
184+
},
185+
{
186+
name: 'react-dom',
187+
type: 'file',
188+
location: settings['react-dom'] || 'node_modules/react-dom/umd/react-dom.development.js'
189+
}
190+
]
191+
190192
Cypress.modules = []
191193
cy.log('Initializing UMD module cache').then(() => {
192194
for (const module of moduleNames) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build": "webpack -d",
1010
"cy:open": "cypress open",
1111
"transpile": "tsc",
12+
"watch": "tsc -w",
1213
"pretest": "npm run lint && npm run transpile",
1314
"lint": "standard --verbose --fix *.js src cypress/integration",
1415
"semantic-release": "semantic-action pre && npm run transpile && npm publish && semantic-action post"

0 commit comments

Comments
 (0)