Skip to content

Commit 9c64236

Browse files
dmtrKovalenkolmiller1990Barthélémy Ledoux
authored
chore(component-testing): Remove useless code & deps in @cypress/react and @cypress/vue (#15113)
* Remove useless code * Add code-coverage to reacr devDependencies * Remove react/support imports * Remove some useless code from @cypress/react * Cleanup vue * Make it works :) * Fix react errors * Fix next.js react example Co-authored-by: Lachlan Miller <[email protected]> Co-authored-by: Barthélémy Ledoux <[email protected]>
1 parent 02aec1e commit 9c64236

File tree

42 files changed

+187
-1632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+187
-1632
lines changed

npm/react/.mocharc.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

npm/react/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ If your React and React DOM libraries are installed in non-standard paths (think
307307

308308
## Code coverage
309309

310+
In order to use code coverage you can follow the instructions from [docs](https://github.com/cypress-io/code-coverage). In most of cases you need to install 2 dependencies:
311+
312+
```
313+
npm i @cypress/code-coverage babel-plugin-istanbul
314+
315+
yarn add @cypress/code-coverage babel-plugin-istanbul
316+
```
317+
310318
If you are using [plugins/cra-v3](plugins/cra-v3) it instruments the code on the fly using `babel-plugin-istanbul` and generates report using dependency [cypress-io/code-coverage](https://github.com/cypress-io/code-coverage) (included). If you want to disable code coverage instrumentation and reporting, use `--env coverage=false` or `CYPRESS_coverage=false` or set in your `cypress.json` file
311319

312320
```json

npm/react/cypress.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
"projectId": "z9dxah",
66
"testFiles": "**/*spec.{js,jsx,ts,tsx}",
77
"env": {
8-
"reactDevtools": true,
9-
"cypress-react-selector": {
10-
"root": "#cypress-root"
11-
}
8+
"reactDevtools": true
129
},
1310
"ignoreTestFiles": [
1411
"**/__snapshots__/*",

npm/react/cypress/component/advanced/lazy-loaded-suspense/lazy-loaded-suspense.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as React from 'react'
22
import { LazyComponent } from './LazyComponent'
33
import { mount } from '@cypress/react'
44

5-
// NOTE: It doesn't work because of chunk splitting issue with webpack
6-
describe.skip('React.lazy component with <Suspense />', () => {
5+
describe('React.lazy component with <Suspense />', () => {
76
it('renders and retries till component is loaded', () => {
7+
cy.viewport(1000, 1000)
88
mount(<LazyComponent />)
99
cy.contains('loading...')
1010
cy.contains('Your dog is')

npm/react/cypress/component/advanced/react-book-example/src/Todos.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ it('Todo - should create snapshot', () => {
2323
// expect(tree).toMatchSnapshot();
2424

2525
// entire test area
26-
cy.get('#cypress-root')
26+
cy.get('#__cy_root')
2727
.invoke('html')
2828
.then(pretty)
2929
.should(

npm/react/cypress/component/advanced/renderless/mouse-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Renderless component', () => {
1616
const onMoved = cy.stub()
1717

1818
mount(<MouseMovement onMoved={onMoved} />)
19-
cy.get('#cypress-root').should('be.empty')
19+
cy.get('#__cy_root').should('be.empty')
2020
cy.document()
2121
.trigger('mousemove')
2222
.then(() => {

npm/react/cypress/component/advanced/set-timeout-example/loading-indicator-spec.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react'
2-
import { unmountComponentAtNode } from 'react-dom'
3-
import { mount } from '@cypress/react'
2+
import { mount, unmount } from '@cypress/react'
43
import LoadingIndicator from './LoadingIndicator'
54

65
// compare these tests to Jest + Enzyme tests in
@@ -74,17 +73,9 @@ describe('LoadingIndicator', () => {
7473
)
7574

7675
cy.tick(2010)
77-
cy.get('#cypress-root').then(($el) => {
78-
unmountComponentAtNode($el[0])
79-
})
76+
unmount()
8077

8178
cy.get('@clearTimeout').should('have.been.calledOnce')
8279
})
8380
})
84-
85-
afterEach(() => {
86-
cy.get('#cypress-root').then(($el) => {
87-
unmountComponentAtNode($el[0])
88-
})
89-
})
9081
})

npm/react/cypress/component/advanced/timers/card-without-effect-spec.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import Card from './card-without-effect.jsx'
33
import React from 'react'
44
import { mount, unmount } from '@cypress/react'
5-
import { unmountComponentAtNode } from 'react-dom'
65

76
it('should select null after timing out', () => {
87
const onSelect = cy.stub()
@@ -29,9 +28,7 @@ it('should cleanup on being removed', () => {
2928
expect(onSelect).to.not.have.been.called
3029
})
3130

32-
cy.get('#cypress-root').then(($el) => {
33-
unmountComponentAtNode($el[0])
34-
})
31+
unmount()
3532

3633
cy.tick(5000).then(() => {
3734
expect(onSelect).to.not.have.been.called

npm/react/cypress/component/basic/before-hook/spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Hello = ({ children }) => {
1414
describe('mount in before hook', () => {
1515
// let's mount the component once
1616
// and then run multiple tests against it
17-
before(() => {
17+
beforeEach(() => {
1818
mount(
1919
<Hello>
2020
<div className="inside">Inner div</div>

npm/react/cypress/component/basic/react-tutorial/pretty-snapshots-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import pretty from 'pretty'
77
it('says hello world', () => {
88
mount(<Hello name="world" />)
99
cy.contains('Hello, world!').should('be.visible')
10-
cy.get('#cypress-root')
10+
cy.get('#__cy_root')
1111
.invoke('html')
1212
.then(pretty)
1313
.should('equal', '<h1>Hello, world!</h1>')
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
require('@cypress/react/support')
21
require('cypress-axe')
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import '@cypress/react/support'
21
import '@cypress/code-coverage/support'
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
require('@cypress/react/support')
21
require('@cypress/code-coverage/support')
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
require('@cypress/react/support')
21
require('@cypress/code-coverage/support')

npm/react/examples/react-scripts/src/RemotePizza.cy-spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const ingredients = ['bacon', 'tomato', 'mozzarella', 'pineapples']
66

77
describe('RemotePizza', () => {
88
it('download ingredients from internets (network mock)', () => {
9-
cy.server()
10-
cy.route('https://httpbin.org/anything*', { args: { ingredients } }).as(
9+
cy.intercept('https://httpbin.org/anything*', { args: { ingredients } }).as(
1110
'pizza',
1211
)
1312

0 commit comments

Comments
 (0)