-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrapRuntime.test.js
More file actions
155 lines (134 loc) · 4.32 KB
/
bootstrapRuntime.test.js
File metadata and controls
155 lines (134 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const test = require('node:test');
const assert = require('node:assert/strict');
const {
DEFAULT_MAX_BODY_CAPTURE_CHARACTERS,
DEFAULT_MASK_HEADERS,
DEFAULT_VIEWER_PATH,
DEFAULT_VIEWER_PORT,
createRNNetworkDebuggerBootstrapRuntime,
resolveRNNetworkDebuggerViewerHost,
resolveRNNetworkDebuggerViewerURL,
} = require('./bootstrapRuntime');
test('resolveRNNetworkDebuggerViewerHost prefers the Metro host from SourceCode.scriptURL', () => {
assert.equal(
resolveRNNetworkDebuggerViewerHost({
platform: 'android',
scriptURL: 'http://192.168.1.12:8081/index.bundle?platform=android&dev=true',
}),
'192.168.1.12',
);
});
test('resolveRNNetworkDebuggerViewerURL uses the configured VIEWER_PORT and default ingest path', () => {
assert.equal(
resolveRNNetworkDebuggerViewerURL({
platform: 'ios',
scriptURL: null,
config: {
VIEWER_PORT: 49000,
},
}),
`ws://127.0.0.1:49000${DEFAULT_VIEWER_PATH}`,
);
});
test('createRNNetworkDebuggerBootstrapRuntime boots capture with resolved viewerURL and default mask headers', () => {
const started = [];
const stopped = [];
const globalObject = {};
const runtime = createRNNetworkDebuggerBootstrapRuntime({
getPlatform: () => 'android',
getScriptURL: () => 'http://10.11.12.13:8081/index.bundle?platform=android&dev=true',
getGlobalObject: () => globalObject,
startCapture: options => {
started.push(options);
return {
stop() {
stopped.push('current');
},
};
},
});
const controller = runtime.bootRNNetworkDebugger({
VIEWER_PORT: DEFAULT_VIEWER_PORT,
});
assert.ok(controller);
assert.deepEqual(started, [
{
viewerURL: `ws://10.11.12.13:${DEFAULT_VIEWER_PORT}${DEFAULT_VIEWER_PATH}`,
maxBodyCaptureCharacters: DEFAULT_MAX_BODY_CAPTURE_CHARACTERS,
maxBodyPreviewCharacters: 2048,
maskHeaders: DEFAULT_MASK_HEADERS,
},
]);
runtime.stopRNNetworkDebuggerBootstrap();
assert.deepEqual(stopped, ['current']);
});
test('createRNNetworkDebuggerBootstrapRuntime can boot directly from a viewer port without a config file', () => {
const started = [];
const runtime = createRNNetworkDebuggerBootstrapRuntime({
getPlatform: () => 'ios',
getScriptURL: () => 'http://192.168.0.50:8081/index.bundle?platform=ios&dev=true',
getGlobalObject: () => ({}),
startCapture: options => {
started.push(options);
return {stop() {}};
},
});
runtime.bootRNNetworkDebuggerWithPort(49001);
assert.deepEqual(started, [
{
viewerURL: `ws://192.168.0.50:49001${DEFAULT_VIEWER_PATH}`,
maxBodyCaptureCharacters: DEFAULT_MAX_BODY_CAPTURE_CHARACTERS,
maxBodyPreviewCharacters: 2048,
maskHeaders: DEFAULT_MASK_HEADERS,
},
]);
});
test('createRNNetworkDebuggerBootstrapRuntime passes through maxBodyCaptureCharacters override', () => {
const started = [];
const runtime = createRNNetworkDebuggerBootstrapRuntime({
getPlatform: () => 'ios',
getScriptURL: () => 'http://192.168.0.50:8081/index.bundle?platform=ios&dev=true',
getGlobalObject: () => ({}),
startCapture: options => {
started.push(options);
return {stop() {}};
},
});
runtime.bootRNNetworkDebugger({
VIEWER_PORT: 49001,
MAX_BODY_CAPTURE_CHARACTERS: 65536,
});
assert.deepEqual(started, [
{
viewerURL: `ws://192.168.0.50:49001${DEFAULT_VIEWER_PATH}`,
maxBodyCaptureCharacters: 65536,
maxBodyPreviewCharacters: 2048,
maskHeaders: DEFAULT_MASK_HEADERS,
},
]);
});
test('createRNNetworkDebuggerBootstrapRuntime passes through captureConsole override', () => {
const started = [];
const runtime = createRNNetworkDebuggerBootstrapRuntime({
getPlatform: () => 'ios',
getScriptURL: () => 'http://192.168.0.50:8081/index.bundle?platform=ios&dev=true',
getGlobalObject: () => ({}),
startCapture: options => {
started.push(options);
return {stop() {}};
},
});
runtime.bootRNNetworkDebugger({
VIEWER_PORT: 49001,
CAPTURE_CONSOLE: true,
});
assert.deepEqual(started, [
{
viewerURL: `ws://192.168.0.50:49001${DEFAULT_VIEWER_PATH}`,
maxBodyCaptureCharacters: DEFAULT_MAX_BODY_CAPTURE_CHARACTERS,
maxBodyPreviewCharacters: 2048,
maskHeaders: DEFAULT_MASK_HEADERS,
captureConsole: true,
},
]);
});