Skip to content

Commit e4cfe63

Browse files
committed
upgrade web-vitals, fix test cases failing to run
1 parent 227d2d0 commit e4cfe63

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

apps/react-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"react-router-dom": "^6.26.2",
2626
"react-scripts": "5.0.1",
2727
"redux-persist": "^6.0.0",
28-
"web-vitals": "^3.5.2"
28+
"web-vitals": "^4.2.3"
2929
},
3030
"devDependencies": {
3131
"@nish1896/eslint-config": "^2.0.5",

apps/react-client/src/App.test.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
/**
2-
* Need to fix..failing due to redux
3-
*/
41
import { render } from '@testing-library/react';
2+
import { Provider } from 'react-redux';
3+
import { PersistGate } from 'redux-persist/integration/react';
4+
import { store, persistor } from 'redux-store';
55
import App from './App';
66

7+
const ReactApp = () => (
8+
<Provider store={store}>
9+
<PersistGate loading={''} persistor={persistor}>
10+
<App />
11+
</PersistGate>
12+
</Provider>
13+
);
14+
715
test('renders learn react link', () => {
8-
const { getByText } = render(<App />);
16+
const { getByText } = render(<ReactApp />);
917
const linkElement = getByText(/learn react/i);
1018
expect(linkElement).toBeInTheDocument();
1119
});

apps/react-client/src/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ root.render(
2020
</React.StrictMode>
2121
);
2222

23-
// If you want to start measuring performance in your app, pass a function
24-
// to log results (for example: reportWebVitals(console.log))
25-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
26-
reportWebVitals();
23+
/**
24+
* If you want to start measuring performance in your app, pass a function
25+
* to log results (for example: reportWebVitals(console.log))
26+
* or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
27+
*/
28+
reportWebVitals(console.log);

apps/react-client/src/reportWebVitals.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import { ReportHandler } from 'web-vitals';
2-
3-
/**
4-
* getXXX() has been renamed to onXXX() in v3.
5-
*
6-
* Refer here https://www.npmjs.com/package/web-vitals
7-
*/
8-
9-
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
1+
const reportWebVitals = (onPerfEntry?: () => void) => {
102
if (onPerfEntry && onPerfEntry instanceof Function) {
11-
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
12-
getCLS(onPerfEntry);
13-
getFID(onPerfEntry);
14-
getFCP(onPerfEntry);
15-
getLCP(onPerfEntry);
16-
getTTFB(onPerfEntry);
3+
import('web-vitals').then(({ onLCP, onCLS, onINP, onFCP, onTTFB }) => {
4+
onLCP(onPerfEntry);
5+
onCLS(onPerfEntry);
6+
onINP(onPerfEntry);
7+
onFCP(onPerfEntry);
8+
onTTFB(onPerfEntry);
179
});
1810
}
1911
};

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12434,10 +12434,10 @@ wcwidth@^1.0.1:
1243412434
dependencies:
1243512435
defaults "^1.0.3"
1243612436

12437-
web-vitals@^3.5.2:
12438-
version "3.5.2"
12439-
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-3.5.2.tgz#5bb58461bbc173c3f00c2ddff8bfe6e680999ca9"
12440-
integrity sha512-c0rhqNcHXRkY/ogGDJQxZ9Im9D19hDihbzSQJrsioex+KnFgmMzBiy57Z1EjkhX/+OjyBpclDCzz2ITtjokFmg==
12437+
web-vitals@^4.2.3:
12438+
version "4.2.3"
12439+
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-4.2.3.tgz#270c4baecfbc6ec6fc15da1989e465e5f9b94fb7"
12440+
integrity sha512-/CFAm1mNxSmOj6i0Co+iGFJ58OS4NRGVP+AWS/l509uIK5a1bSoIVaHz/ZumpHTfHSZBpgrJ+wjfpAOrTHok5Q==
1244112441

1244212442
webidl-conversions@^3.0.0:
1244312443
version "3.0.1"

0 commit comments

Comments
 (0)