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

Commit

Permalink
feat: specify custom paths to React and React DOM, close #66
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Mar 18, 2019
1 parent 14f0f33 commit f1f6e4c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ describe('HelloState component', () => {

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

## Configuration

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:

```json
{
"env": {
"cypress-react-unit-test": {
"react": "node_modules/react/umd/react.development.js",
"react-dom": "node_modules/react-dom/umd/react-dom.development.js"
}
}
}
```

## Transpilation

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.
Expand Down
8 changes: 7 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
"viewportHeight": 100,
"video": false,
"projectId": "z9dxah",
"ignoreTestFiles": "*.css"
"ignoreTestFiles": "*.css",
"env": {
"cypress-react-unit-test": {
"react": "node_modules/react/umd/react.development.js",
"react-dom": "node_modules/react-dom/umd/react-dom.development.js"
}
}
}
28 changes: 15 additions & 13 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,6 @@ Cypress.Commands.overwrite('get', (originalFn, selector, options) => {
}
})

const moduleNames = [
{
name: 'react',
type: 'file',
location: 'node_modules/react/umd/react.development.js'
},
{
name: 'react-dom',
type: 'file',
location: 'node_modules/react-dom/umd/react-dom.development.js'
}
]

/*
Before All
- Load and cache UMD modules specified in fixtures/modules.json
Expand All @@ -187,6 +174,21 @@ Before All
Format: [{name, type, location}, ...]
*/
before(() => {
const settings = Cypress.env('cypress-react-unit-test') || {}

const moduleNames = [
{
name: 'react',
type: 'file',
location: settings.react || 'node_modules/react/umd/react.development.js'
},
{
name: 'react-dom',
type: 'file',
location: settings['react-dom'] || 'node_modules/react-dom/umd/react-dom.development.js'
}
]

Cypress.modules = []
cy.log('Initializing UMD module cache').then(() => {
for (const module of moduleNames) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "webpack -d",
"cy:open": "cypress open",
"transpile": "tsc",
"watch": "tsc -w",
"pretest": "npm run lint && npm run transpile",
"lint": "standard --verbose --fix *.js src cypress/integration",
"semantic-release": "semantic-action pre && npm run transpile && npm publish && semantic-action post"
Expand Down

0 comments on commit f1f6e4c

Please sign in to comment.