Skip to content

Commit e3f47f4

Browse files
authored
Remove legacy page support from inspector proxy
1 parent 149aba6 commit e3f47f4

14 files changed

Lines changed: 71 additions & 911 deletions

‎packages/dev-middleware/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Open the JavaScript debugger for a given CDP target. Must be provided with one o
7171

7272
- `device`‌ — An ID unique to a combination of device and app, stable across installs. Implemented by `getInspectorDeviceId` on each native platform.
7373
- `target` — The target page ID as returned by `/json/list` for the current dev server session.
74-
- `appId` (deprecated, legacy only) — The application bundle identifier to match (non-unique across multiple connected devices). This param will only match legacy Hermes debugger targets.
7574

7675
<details>
7776
<summary>Example</summary>

‎packages/dev-middleware/src/__tests__/InspectorProxyCdpRewritingHacks-test.js‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ describe.each(['HTTP', 'HTTPS'])(
6868
app: 'bar-app',
6969
id: 'page1',
7070
title: 'bar-title',
71-
vm: 'bar-vm',
7271
},
7372
);
7473
try {
@@ -108,7 +107,6 @@ describe.each(['HTTP', 'HTTPS'])(
108107
app: 'bar-app',
109108
id: 'page1',
110109
title: 'bar-title',
111-
vm: 'bar-vm',
112110
},
113111
);
114112
try {
@@ -147,7 +145,6 @@ describe.each(['HTTP', 'HTTPS'])(
147145
app: 'bar-app',
148146
id: 'page1',
149147
title: 'bar-title',
150-
vm: 'bar-vm',
151148
},
152149
{
153150
deviceHostHeader: '192.168.0.123:' + serverRef.port,
@@ -189,7 +186,6 @@ describe.each(['HTTP', 'HTTPS'])(
189186
app: 'bar-app',
190187
id: 'page1',
191188
title: 'bar-title',
192-
vm: 'bar-vm',
193189
},
194190
{
195191
deviceHostHeader: sourceHost,
@@ -224,7 +220,6 @@ describe.each(['HTTP', 'HTTPS'])(
224220
app: 'bar-app',
225221
id: 'page1',
226222
title: 'bar-title',
227-
vm: 'bar-vm',
228223
},
229224
{
230225
deviceHostHeader: sourceHost,
@@ -271,7 +266,6 @@ describe.each(['HTTP', 'HTTPS'])(
271266
app: 'bar-app',
272267
id: 'page1',
273268
title: 'bar-title',
274-
vm: 'bar-vm',
275269
},
276270
{
277271
debuggerHeaders: {
@@ -356,7 +350,6 @@ describe.each(['HTTP', 'HTTPS'])(
356350
app: 'bar-app',
357351
id: 'page1',
358352
title: 'bar-title',
359-
vm: 'bar-vm',
360353
},
361354
{
362355
deviceHostHeader: sourceHost,
@@ -396,7 +389,6 @@ describe.each(['HTTP', 'HTTPS'])(
396389
app: 'bar-app',
397390
id: 'page1',
398391
title: 'bar-title',
399-
vm: 'bar-vm',
400392
},
401393
{
402394
deviceHostHeader: '127.0.0.1:' + serverRef.port,
@@ -431,7 +423,6 @@ describe.each(['HTTP', 'HTTPS'])(
431423
app: 'bar-app',
432424
id: 'page1',
433425
title: 'bar-title',
434-
vm: 'bar-vm',
435426
},
436427
);
437428
try {
@@ -479,7 +470,6 @@ describe.each(['HTTP', 'HTTPS'])(
479470
app: 'bar-app',
480471
id: 'page1',
481472
title: 'bar-title',
482-
vm: 'bar-vm',
483473
},
484474
);
485475

@@ -528,7 +518,6 @@ describe.each(['HTTP', 'HTTPS'])(
528518
app: 'bar-app',
529519
id: 'page1',
530520
title: 'bar-title',
531-
vm: 'bar-vm',
532521
},
533522
);
534523

@@ -581,7 +570,6 @@ describe.each(['HTTP', 'HTTPS'])(
581570
capabilities: {
582571
nativeSourceCodeFetching: true,
583572
},
584-
vm: 'bar-vm',
585573
};
586574

587575
describe('Debugger.scriptParsed', () => {

‎packages/dev-middleware/src/__tests__/InspectorProxyCdpTransport-test.js‎

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import type {
1515
PageDescription,
1616
} from '../inspector-proxy/types';
1717

18+
import {WS_CLOSE_REASON} from '../inspector-proxy/Device';
1819
import {fetchJson} from './FetchUtils';
1920
import {createDebuggerMock} from './InspectorDebuggerUtils';
2021
import {createDeviceMock} from './InspectorDeviceUtils';
21-
import {sendFromDebuggerToTarget} from './InspectorProtocolUtils';
22+
import {
23+
createAndConnectTarget,
24+
sendFromDebuggerToTarget,
25+
} from './InspectorProtocolUtils';
2226
import {withAbortSignalForEachTest} from './ResourceUtils';
2327
import {withServerForEachTest} from './ServerUtils';
2428
import until from 'wait-for-expect';
@@ -51,7 +55,6 @@ describe.each(['HTTP', 'HTTPS'])(
5155
app: 'bar-app',
5256
id: 'page1',
5357
title: 'bar-title',
54-
vm: 'bar-vm',
5558
},
5659
]);
5760

@@ -111,7 +114,6 @@ describe.each(['HTTP', 'HTTPS'])(
111114
app: 'bar-app',
112115
id: 'page1',
113116
title: 'bar-title',
114-
vm: 'bar-vm',
115117
},
116118
]);
117119

@@ -167,7 +169,6 @@ describe.each(['HTTP', 'HTTPS'])(
167169
app: 'bar-app',
168170
id: 'page1',
169171
title: 'bar-title',
170-
vm: 'bar-vm',
171172
},
172173
]);
173174
let pageList: Array<PageDescription> = [];
@@ -217,7 +218,6 @@ describe.each(['HTTP', 'HTTPS'])(
217218
app: 'bar-app',
218219
id: 'page1',
219220
title: 'bar-title',
220-
vm: 'bar-vm',
221221
},
222222
]);
223223
let pageList: Array<PageDescription> = [];
@@ -291,7 +291,6 @@ describe.each(['HTTP', 'HTTPS'])(
291291
app: 'bar-app',
292292
id: 'page1',
293293
title: 'bar-title',
294-
vm: 'bar-vm',
295294
},
296295
]);
297296

@@ -337,7 +336,6 @@ describe.each(['HTTP', 'HTTPS'])(
337336
app: 'bar-app',
338337
id: 'page1',
339338
title: 'bar-title',
340-
vm: 'bar-vm',
341339
},
342340
]);
343341

@@ -363,6 +361,41 @@ describe.each(['HTTP', 'HTTPS'])(
363361
},
364362
);
365363

364+
test('device disconnect event closes the debugger connection', async () => {
365+
const {device, debugger_, sessionId} = await createAndConnectTarget(
366+
serverRef,
367+
autoCleanup.signal,
368+
{
369+
app: 'bar-app',
370+
id: 'page1',
371+
title: 'bar-title',
372+
},
373+
);
374+
const debuggerClosed = new Promise<{code: number, reason: string}>(
375+
resolve =>
376+
debugger_.socket.once('close', (code: number, reason: Buffer) =>
377+
resolve({code, reason: reason.toString()}),
378+
),
379+
);
380+
381+
try {
382+
device.send({
383+
event: 'disconnect',
384+
payload: {
385+
pageId: 'page1',
386+
sessionId,
387+
},
388+
});
389+
expect(await debuggerClosed).toEqual({
390+
code: 1000,
391+
reason: WS_CLOSE_REASON.PAGE_REMOVED,
392+
});
393+
} finally {
394+
device.close();
395+
debugger_.close();
396+
}
397+
});
398+
366399
describe('session ID handling', () => {
367400
test('each debugger connection receives a unique session ID', async () => {
368401
let device, debugger1, debugger2;
@@ -376,7 +409,6 @@ describe.each(['HTTP', 'HTTPS'])(
376409
app: 'bar-app',
377410
id: 'page1',
378411
title: 'bar-title',
379-
vm: 'bar-vm',
380412
},
381413
]);
382414
let pageList: Array<PageDescription> = [];
@@ -439,7 +471,6 @@ describe.each(['HTTP', 'HTTPS'])(
439471
app: 'bar-app',
440472
id: 'page1',
441473
title: 'bar-title',
442-
vm: 'bar-vm',
443474
},
444475
]);
445476
let pageList: Array<PageDescription> = [];
@@ -493,7 +524,6 @@ describe.each(['HTTP', 'HTTPS'])(
493524
app: 'bar-app',
494525
id: 'page1',
495526
title: 'bar-title',
496-
vm: 'bar-vm',
497527
},
498528
]);
499529
let pageList: Array<PageDescription> = [];
@@ -546,7 +576,6 @@ describe.each(['HTTP', 'HTTPS'])(
546576
app: 'bar-app',
547577
id: 'page1',
548578
title: 'bar-title',
549-
vm: 'bar-vm',
550579
},
551580
]);
552581
let pageList: Array<PageDescription> = [];

‎packages/dev-middleware/src/__tests__/InspectorProxyConcurrentSessions-test.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ describe('inspector proxy concurrent sessions', () => {
5959
id: 'page1',
6060
app: 'bar-app',
6161
title: 'bar-title',
62-
vm: 'bar-vm',
6362
},
6463
]);
6564

‎packages/dev-middleware/src/__tests__/InspectorProxyCustomMessageHandler-test.js‎

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
* @format
99
*/
1010

11-
import {fetchJson} from './FetchUtils';
12-
import {createDebuggerMock} from './InspectorDebuggerUtils';
13-
import {createDeviceMock} from './InspectorDeviceUtils';
1411
import {createAndConnectTarget} from './InspectorProtocolUtils';
1512
import {withAbortSignalForEachTest} from './ResourceUtils';
1613
import {baseUrlForServer, createServer} from './ServerUtils';
17-
import invariant from 'invariant';
1814
import until from 'wait-for-expect';
1915

2016
// WebSocket is unreliable when using fake timers.
@@ -28,7 +24,6 @@ describe('inspector proxy device message middleware', () => {
2824
id: 'page1',
2925
app: 'bar-app',
3026
title: 'bar-title',
31-
vm: 'bar-vm',
3227
};
3328

3429
afterEach(() => {
@@ -78,85 +73,6 @@ describe('inspector proxy device message middleware', () => {
7873
}
7974
});
8075

81-
test('middleware is created with device, debugger, and page information for synthetic reloadable page', async () => {
82-
const createCustomMessageHandler = jest.fn().mockImplementation(() => null);
83-
const {server} = await createServer({
84-
logger: undefined,
85-
unstable_customInspectorMessageHandler: createCustomMessageHandler,
86-
});
87-
const {serverBaseUrl, serverBaseWsUrl} = serverRefUrls(server);
88-
89-
let device, debugger_;
90-
try {
91-
device = await createDeviceMock(
92-
`${serverBaseWsUrl}/inspector/device?device=device1&name=foo&app=bar`,
93-
autoCleanup.signal,
94-
);
95-
// Mock the device to return a normal React (Native) page
96-
device.getPages.mockImplementation(() => [
97-
{
98-
...page,
99-
// NOTE: 'React' is a magic string used to detect React Native pages.
100-
title: 'React Native (mock)',
101-
},
102-
]);
103-
104-
// Retrieve the full page list from device
105-
let pageList;
106-
await until(async () => {
107-
pageList = (await fetchJson(
108-
`${serverBaseUrl}/json`,
109-
// $FlowFixMe[unclear-type]
110-
)) as any;
111-
expect(pageList.length).toBeGreaterThan(0);
112-
});
113-
invariant(pageList != null, '');
114-
115-
// Find the synthetic page
116-
const syntheticPage = pageList.find(
117-
({title}) =>
118-
// NOTE: Magic string used for the synthetic page that has a stable ID
119-
title === 'React Native Experimental (Improved Chrome Reloads)',
120-
);
121-
expect(syntheticPage).not.toBeUndefined();
122-
123-
// Connect the debugger to this synthetic page
124-
debugger_ = await createDebuggerMock(
125-
syntheticPage.webSocketDebuggerUrl,
126-
autoCleanup.signal,
127-
);
128-
129-
// Ensure the middleware was created with the device information
130-
await until(() =>
131-
expect(createCustomMessageHandler).toBeCalledWith(
132-
expect.objectContaining({
133-
page: expect.objectContaining({
134-
id: expect.any(String),
135-
title: syntheticPage.title,
136-
vm: syntheticPage.vm,
137-
app: expect.any(String),
138-
capabilities: expect.any(Object),
139-
}),
140-
device: expect.objectContaining({
141-
appId: expect.any(String),
142-
id: expect.any(String),
143-
name: expect.any(String),
144-
sendMessage: expect.any(Function),
145-
}),
146-
debugger: expect.objectContaining({
147-
userAgent: null,
148-
sendMessage: expect.any(Function),
149-
}),
150-
}),
151-
),
152-
);
153-
} finally {
154-
device?.close();
155-
debugger_?.close();
156-
await closeServer(server);
157-
}
158-
});
159-
16076
test('send message functions are passing messages to sockets', async () => {
16177
const handleDebuggerMessage = jest.fn();
16278
const handleDeviceMessage = jest.fn();

0 commit comments

Comments
 (0)