You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docusaurus/docs/folder-structure.md
+2
Original file line number
Diff line number
Diff line change
@@ -34,3 +34,5 @@ You may create subdirectories inside `src`. For faster rebuilds, only files insi
34
34
Only files inside `public` can be used from `public/index.html`. Read instructions below for using assets from JavaScript and HTML.
35
35
36
36
You can, however, create more top-level directories. They will not be included in the production build so you can use them for things like documentation.
37
+
38
+
If you have Git installed and your project is not part of a larger repository, then a new repository will be initialized resulting in an additional top-level `.git` directory.
Copy file name to clipboardexpand all lines: docusaurus/docs/making-a-progressive-web-app.md
+21-17
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ the build process will generate a service worker file, but it will not be
10
10
registered, so it will not take control of your production web app.
11
11
12
12
In order to opt-in to the offline-first behavior, developers should look for the
13
-
following in their [`src/index.js`](src/index.js) file:
13
+
following in their [`src/index.js`](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/src/index.js) file:
14
14
15
15
```js
16
16
// If you want your app to work offline and load faster, you can change
@@ -47,16 +47,32 @@ or unreliable network.
47
47
If you do decide to opt-in to service worker registration, please take the
48
48
following into account:
49
49
50
+
1. After the initial caching is done, the [service worker lifecycle](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle)
51
+
controls when updated content ends up being shown to users. In order to guard against
52
+
[race conditions with lazy-loaded content](https://github.com/facebook/create-react-app/issues/3613#issuecomment-353467430),
53
+
the default behavior is to conservatively keep the updated service worker in the "[waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)"
54
+
state. This means that users will end up seeing older content until they close (reloading is not
55
+
enough) their existing, open tabs. See [this blog post](https://jeffy.info/2018/10/10/sw-in-c-r-a.html)
56
+
for more details about this behavior.
57
+
58
+
1. Users aren't always familiar with offline-first web apps. It can be useful to
59
+
[let the user know](https://developers.google.com/web/fundamentals/instant-and-offline/offline-ux#inform_the_user_when_the_app_is_ready_for_offline_consumption)
60
+
when the service worker has finished populating your caches (showing a "This web
61
+
app works offline!" message) and also let them know when the service worker has
62
+
fetched the latest updates that will be available the next time they load the
63
+
page (showing a "New content is available once existing tabs are closed." message). Showing
64
+
this messages is currently left as an exercise to the developer, but as a
65
+
starting point, you can make use of the logic included in [`src/serviceWorker.js`](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/src/serviceWorker.js), which
66
+
demonstrates which service worker lifecycle events to listen for to detect each
67
+
scenario, and which as a default, just logs appropriate messages to the
68
+
JavaScript console.
69
+
50
70
1. Service workers [require HTTPS](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers#you_need_https),
51
71
although to facilitate local testing, that policy
52
72
[does not apply to `localhost`](http://stackoverflow.com/questions/34160509/options-for-testing-service-workers-via-http/34161385#34161385).
53
73
If your production web server does not support HTTPS, then the service worker
54
74
registration will fail, but the rest of your web app will remain functional.
55
75
56
-
1. Service workers are [not supported](https://jakearchibald.github.io/isserviceworkerready/#moar)
57
-
in older web browsers. Service worker registration [won't be attempted](src/registerServiceWorker.js)
58
-
on browsers that lack support.
59
-
60
76
1. The service worker is only enabled in the [production environment](/docs/deployment),
61
77
e.g. the output of `npm run build`. It's recommended that you do not enable an
62
78
offline-first service worker in a development environment, as it can lead to
@@ -70,18 +86,6 @@ following into account:
70
86
instructions for using other methods. _Be sure to always use an
71
87
incognito window to avoid complications with your browser cache._
72
88
73
-
1. Users aren't always familiar with offline-first web apps. It can be useful to
74
-
[let the user know](https://developers.google.com/web/fundamentals/instant-and-offline/offline-ux#inform_the_user_when_the_app_is_ready_for_offline_consumption)
75
-
when the service worker has finished populating your caches (showing a "This web
76
-
app works offline!" message) and also let them know when the service worker has
77
-
fetched the latest updates that will be available the next time they load the
78
-
page (showing a "New content is available; please refresh." message). Showing
79
-
this messages is currently left as an exercise to the developer, but as a
80
-
starting point, you can make use of the logic included in [`src/registerServiceWorker.js`](src/registerServiceWorker.js), which
81
-
demonstrates which service worker lifecycle events to listen for to detect each
82
-
scenario, and which as a default, just logs appropriate messages to the
83
-
JavaScript console.
84
-
85
89
1. By default, the generated service worker file will not intercept or cache any
86
90
cross-origin traffic, like HTTP [API requests](/docs/integrating-with-an-api-backend),
Copy file name to clipboardexpand all lines: docusaurus/docs/post-processing-css.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ This project setup minifies your CSS and adds vendor prefixes to it automaticall
7
7
8
8
Support for new CSS features like the [`all` property](https://developer.mozilla.org/en-US/docs/Web/CSS/all), [`break` properties](https://www.w3.org/TR/css-break-3/#breaking-controls), [custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables), and [media query ranges](https://www.w3.org/TR/mediaqueries-4/#range-context) are automatically polyfilled to add support for older browsers.
9
9
10
-
You can customize your target support browsers by adjusting the `browserslist` key in `package.json`accoring to the [Browserslist specification](https://github.com/browserslist/browserslist#readme).
10
+
You can customize your target support browsers by adjusting the `browserslist` key in `package.json`according to the [Browserslist specification](https://github.com/browserslist/browserslist#readme).
Copy file name to clipboardexpand all lines: docusaurus/docs/running-tests.md
+45-2
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,8 @@ This test mounts a component and makes sure that it didn’t throw during render
82
82
83
83
When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior.
84
84
85
+
### Option 1: Shallow Rendering
86
+
85
87
If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). To install it, run:
86
88
87
89
```sh
@@ -167,6 +169,47 @@ Import it in [`src/setupTests.js`](#initializing-test-environment) to make its m
167
169
import'jest-enzyme';
168
170
```
169
171
172
+
### Option 2: React Testing Library
173
+
174
+
As an alternative or companion to `enzyme`, you may consider using `react-testing-library`. [`react-testing-library`](https://github.com/kentcdodds/react-testing-library) is a library for testing React components in a way that resembles the way the components are used by end users. It is well suited for unit, integration, and end-to-end testing of React components and applications. It works more directly with DOM nodes, and therefore it's recommended to use with [`jest-dom`](https://github.com/gnapse/jest-dom) for improved assertions.
175
+
176
+
To install `react-testing-library` and `jest-dom`, you can run:
177
+
178
+
```sh
179
+
npm install --save react-testing-library jest-dom
180
+
```
181
+
182
+
Alternatively you may use `yarn`:
183
+
184
+
```sh
185
+
yarn add react-testing-library jest-dom
186
+
```
187
+
188
+
Similar to `enzyme` you can create a `src/setupTests.js` file to avoid boilerplate in your test files:
189
+
190
+
```js
191
+
// react-testing-library renders your components to document.body,
192
+
// this will ensure they're removed after each test.
193
+
import'react-testing-library/cleanup-after-each';
194
+
// this adds jest-dom's custom assertions
195
+
import'jest-dom/extend-expect';
196
+
```
197
+
198
+
Here's an example of using `react-testing-library` and `jest-dom` for testing that the `<App />` component renders "Welcome to React".
199
+
200
+
```js
201
+
importReactfrom'react';
202
+
import { render } from'react-testing-library';
203
+
importAppfrom'./App';
204
+
205
+
it('renders welcome message', () => {
206
+
const { getByText } =render(<App />);
207
+
expect(getByText('Welcome to React')).toBeInTheDocument();
208
+
});
209
+
```
210
+
211
+
Learn more about the utilities provided by `react-testing-library` to facilitate testing asynchronous interactions as well as selecting form elements from [the `react-testing-library` documentation](https://github.com/kentcdodds/react-testing-library) and [examples](https://codesandbox.io/s/github/kentcdodds/react-testing-library-examples).
212
+
170
213
## Using Third Party Assertion Libraries
171
214
172
215
We recommend that you use `expect()` for assertions and `jest.fn()` for spies. If you are having issues with them please [file those against Jest](https://github.com/facebook/jest/issues/new), and we’ll fix them. We intend to keep making them better for React, supporting, for example, [pretty-printing React elements as JSX](https://github.com/facebook/jest/pull/1566).
0 commit comments