Merge remote-tracking branch 'upstream/main' into bundler

This commit is contained in:
Like Zhu 2021-07-20 17:15:10 -07:00
Родитель db8e00697a 703426c971
Коммит db8cdba16a
6 изменённых файлов: 2535 добавлений и 3756 удалений

6246
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^5.13.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^13.1.9",
"fetch-mock": "^9.11.0",
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
"react-scripts": "^4.0.3",

Просмотреть файл

@ -4,6 +4,11 @@ import {
DataFetcher,
Environment,
Store,
middlewareTypes,
createFetchPolicyMiddleware,
createErrorMiddleware,
createInstrumentationMiddleware,
} from '@microsoft/overreact';
// Previously defined schema and network requestor
@ -82,33 +87,29 @@ function isExpectedErrorCodes(errorResponseJson) {
return true;
}
export const middlewares = {
[middlewareTypes.FETCH_POLICY]: createFetchPolicyMiddleware(),
[middlewareTypes.ERROR]: createErrorMiddleware({
errorProcessor: error => {
console.log(error);
},
}),
[middlewareTypes.ERROR]: createErrorMiddleware(),
[middlewareTypes.INSTRUMENTATION]: createInstrumentationMiddleware({
pageTrackingId: '123',
loggerFunc: {
traceFunc: ({
requestId, message, api, httpMethod,
requestId, message, api, httpMethod, statusCode,
}) => {
console.log('TRACE', message || '', api, requestId, httpMethod);
console.log(message || '', api, requestId, httpMethod, statusCode);
},
errorFunc: ({
requestId, api, httpMethod, message,
requestId, api, httpMethod, message, statusCode,
}) => {
console.error(message || '', api, requestId, null /* impact user */, httpMethod);
console.error(message || '', api, requestId, null /* impact user */, httpMethod, statusCode);
},
perfFunc: ({
requestId, api, httpMethod, timeTaken, message, isMethodEnter,
requestId, api, httpMethod, timeTaken, message, isMethodEnter, statusCode,
}) => {
console.log(
'PERF',
requestId, api, isMethodEnter,
httpMethod, timeTaken, null /* pass */, message,
httpMethod, timeTaken, null /* pass */, message, statusCode,
);
},
},
@ -128,7 +129,7 @@ export const middlewares = {
// define an Environment object to configure overreact
const store = new Store();
const tripPinEnvironment = new Environment(networkRequestor, schema, store, []);
const tripPinEnvironment = new Environment(networkRequestor, schema, store, middlewares);
export default function App() {
return (

Просмотреть файл

@ -3,6 +3,9 @@ import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import setupMock from './mocks';
setupMock();
ReactDOM.render(
<React.StrictMode>

Просмотреть файл

@ -0,0 +1,9 @@
import fetchMock from 'fetch-mock';
export default function setupMocks() {
fetchMock.mock('*', new Response(
'{"value":[{"Code":"BadRequest"}]}', {
status: 400,
},
));
}

Просмотреть файл

@ -9,6 +9,7 @@ export const defaultStubOptions = {
detectError(respData, serverErrorCodes) {
const result = {
pass: true,
status: 400, // hard code to 400 for user-defined error
};
if (respData
@ -86,6 +87,7 @@ export function successHandler(instrumentationContext, response, errorFunc, perf
requestId: instrumentationContext.requestId,
impactUser: result.impactUser,
httpMethod: instrumentationContext.httpMethod,
statusCode: result.status,
});
}
@ -97,6 +99,7 @@ export function successHandler(instrumentationContext, response, errorFunc, perf
timeTaken: instrumentationContext.requestTimeTaken,
pass: instrumentationContext.requestResult,
message: instrumentationContext.stubOptions.getServerPerf(response),
statusCode: 200,
});
}
@ -149,6 +152,7 @@ export function errorHandler(
api: instrumentationContext.url,
requestId: instrumentationContext.requestId,
httpMethod: instrumentationContext.httpMethod,
statusCode: error.status,
});
perfFunc({
@ -158,5 +162,6 @@ export function errorHandler(
httpMethod: instrumentationContext.httpMethod,
timeTaken: instrumentationContext.requestTimeTaken,
pass: instrumentationContext.requestResult,
statusCode: error.status,
});
}