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

Commit 388dd55

Browse files
Create not-working example with lazy + suspense (#410)
* Create not-working example with lazy + suspense * Remove console.log * Add Readme description
1 parent a5ea166 commit 388dd55

File tree

10 files changed

+498
-55
lines changed

10 files changed

+498
-55
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ Spec | Description
182182
[radioactive-state](cypress/component/advanced/radioactive-state) | Testing components that use [radioactive-state](https://github.com/MananTank/radioactive-state) library
183183
[react-bootstrap](cypress/component/advanced/react-bootstrap) | Confirms [react-bootstrap](https://react-bootstrap.github.io/) components are working
184184
[select React component](cypress/component/advanced/react-book-example/src/components/ProductsList.spec.js) | Uses [cypress-react-selector](https://github.com/abhinaba-ghosh/cypress-react-selector) to find DOM elements using React component name and state values
185+
[lazy-loaded](cypress/component/advanced/lazy-loaded-suspense) | Uses multiple chunks and async components with `React.lazy` + `React.Suspense`.
185186
[i18n](cypress/component/advanced/i18n) | Uses[react-i18next](https://react.i18next.com/) for localizaiton.
186187
<!-- prettier-ignore-end -->
187188

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react'
2+
// @ts-ignore
3+
import SamoyedImage from './samoyed.jpg'
4+
5+
interface DogProps {}
6+
7+
export const Dog: React.FC<DogProps> = ({}) => {
8+
return (
9+
<div>
10+
<h1> Your dog is Samoyed: </h1>
11+
<img src={SamoyedImage} />
12+
</div>
13+
)
14+
}
15+
16+
export default Dog
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
3+
const LazyDog = React.lazy(() => import(/* webpackChunkName: "Dog" */ './Dog'))
4+
interface LazyComponentProps {}
5+
6+
export const LazyComponent: React.FC<LazyComponentProps> = ({}) => {
7+
return (
8+
<div>
9+
Loading a dog:
10+
<React.Suspense fallback={'loading...'}>
11+
<LazyDog />
12+
</React.Suspense>
13+
</div>
14+
)
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from 'react'
2+
import { LazyComponent } from './LazyComponent'
3+
import { mount } from 'cypress-react-unit-test'
4+
5+
describe.skip('React.lazy component with <Suspense />', () => {
6+
it('renders and retries till component is loaded', () => {
7+
mount(<LazyComponent />)
8+
cy.contains('loading...')
9+
cy.contains('Your dog is')
10+
})
11+
})
112 KB
Loading

cypress/plugins/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path')
22
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
33
const babelConfig = require('../../babel.config.js')
44

5-
// should we just reuse root webpack config?
5+
/** @type import("webpack").Configuration */
66
const webpackOptions = {
77
resolve: {
88
extensions: ['.js', '.ts', '.jsx', '.tsx'],
@@ -12,6 +12,10 @@ const webpackOptions = {
1212
},
1313
mode: 'development',
1414
devtool: false,
15+
output: {
16+
publicPath: '/',
17+
chunkFilename: '[name].bundle.js',
18+
},
1519
module: {
1620
rules: [
1721
{
@@ -29,6 +33,15 @@ const webpackOptions = {
2933
test: /\.svg$/,
3034
loader: 'svg-url-loader',
3135
},
36+
{
37+
// some of our examples import SVG
38+
test: /\.svg$/,
39+
loader: 'svg-url-loader',
40+
},
41+
{
42+
test: /\.(png|jpg)$/,
43+
use: ['file-loader'],
44+
},
3245
],
3346
},
3447
}

cypress/tsconfig.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"extends": "../tsconfig.json",
3-
"include": ["./**/*.ts"],
3+
"include": ["./**/*.ts*"],
44
"compilerOptions": {
5-
"baseUrl": "../node_modules",
6-
"types": ["cypress"]
5+
"baseUrl": ".",
6+
"jsx": "react",
7+
"types": ["cypress"],
8+
"paths": {
9+
"cypress-react-unit-test": ["../lib"]
10+
}
711
}
812
}

0 commit comments

Comments
 (0)