File tree Expand file tree Collapse file tree 5 files changed +29
-17
lines changed Expand file tree Collapse file tree 5 files changed +29
-17
lines changed Original file line number Diff line number Diff line change 1
- // https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Network/XHRInterceptor.js
2
- declare module 'react-native/Libraries/Network/XHRInterceptor' {
3
- export function isInterceptorEnabled ( ) : boolean ;
4
- export function setOpenCallback ( ...props : any ) : void ;
5
- export function setRequestHeaderCallback ( ...props : any ) : void ;
6
- export function setSendCallback ( ...props : any ) : void ;
7
- export function setHeaderReceivedCallback ( ...props : any ) : void ;
8
- export function setResponseCallback ( ...props : any ) : void ;
9
- export function enableInterception ( ) : void ;
10
- export function disableInterception ( ) : void ;
11
- }
12
-
13
1
declare module 'react-native/Libraries/Blob/FileReader' {
14
2
type Events =
15
3
| 'abort'
Original file line number Diff line number Diff line change 1
- import XHRInterceptor from 'react-native/Libraries/Network /XHRInterceptor' ;
1
+ import XHRInterceptor from '. /XHRInterceptor' ;
2
2
import NetworkRequestInfo from './NetworkRequestInfo' ;
3
3
import { Headers , RequestMethod , StartNetworkLoggingOptions } from './types' ;
4
4
import extractHost from './utils/extractHost' ;
Original file line number Diff line number Diff line change
1
+ type XHRInterceptorModule = {
2
+ isInterceptorEnabled : ( ) => boolean ;
3
+ setOpenCallback : ( ...props : any [ ] ) => void ;
4
+ setRequestHeaderCallback : ( ...props : any [ ] ) => void ;
5
+ setSendCallback : ( ...props : any [ ] ) => void ;
6
+ setHeaderReceivedCallback : ( ...props : any [ ] ) => void ;
7
+ setResponseCallback : ( ...props : any [ ] ) => void ;
8
+ enableInterception : ( ) => void ;
9
+ disableInterception : ( ) => void ;
10
+ } ;
11
+
12
+ let XHRInterceptor : XHRInterceptorModule ;
13
+ try {
14
+ // new location for React Native 0.79+
15
+ XHRInterceptor = require ( 'react-native/src/private/inspector/XHRInterceptor' ) ;
16
+ } catch {
17
+ try {
18
+ XHRInterceptor = require ( 'react-native/Libraries/Network/XHRInterceptor' ) ;
19
+ } catch {
20
+ throw new Error ( 'XHRInterceptor could not be found in either location' ) ;
21
+ }
22
+ }
23
+
24
+ export default XHRInterceptor ;
Original file line number Diff line number Diff line change 1
- import XHRInterceptor from 'react-native/Libraries/Network /XHRInterceptor' ;
1
+ import XHRInterceptor from '.. /XHRInterceptor' ;
2
2
import { warn } from '../utils/logger' ;
3
3
import Logger from '../Logger' ;
4
4
import { LOGGER_MAX_REQUESTS , LOGGER_REFRESH_RATE } from '../constant' ;
5
5
6
6
jest . mock ( 'react-native/Libraries/Blob/FileReader' , ( ) => ( { } ) ) ;
7
- jest . mock ( 'react-native/Libraries/Network /XHRInterceptor' , ( ) => ( {
7
+ jest . mock ( '.. /XHRInterceptor' , ( ) => ( {
8
8
isInterceptorEnabled : jest . fn ( ) ,
9
9
setOpenCallback : jest . fn ( ) ,
10
10
setRequestHeaderCallback : jest . fn ( ) ,
Original file line number Diff line number Diff line change 1
- import XHRInterceptor from 'react-native/Libraries/Network /XHRInterceptor' ;
1
+ import XHRInterceptor from '.. /XHRInterceptor' ;
2
2
import { startNetworkLogging , stopNetworkLogging } from '..' ;
3
3
import logger from '../loggerSingleton' ;
4
4
import { LOGGER_MAX_REQUESTS , LOGGER_REFRESH_RATE } from '../constant' ;
5
5
6
6
jest . mock ( 'react-native/Libraries/Blob/FileReader' , ( ) => ( { } ) ) ;
7
- jest . mock ( 'react-native/Libraries/Network /XHRInterceptor' , ( ) => ( {
7
+ jest . mock ( '.. /XHRInterceptor' , ( ) => ( {
8
8
isInterceptorEnabled : jest . fn ( ) ,
9
9
setOpenCallback : jest . fn ( ) ,
10
10
setRequestHeaderCallback : jest . fn ( ) ,
You can’t perform that action at this time.
0 commit comments