Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/dev-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Open the JavaScript debugger for a given CDP target. Must be provided with one o

- `device`‌ — An ID unique to a combination of device and app, stable across installs. Implemented by `getInspectorDeviceId` on each native platform.
- `target` — The target page ID as returned by `/json/list` for the current dev server session.
- `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.

<details>
<summary>Example</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
);
try {
Expand Down Expand Up @@ -108,7 +107,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
);
try {
Expand Down Expand Up @@ -147,7 +145,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
{
deviceHostHeader: '192.168.0.123:' + serverRef.port,
Expand Down Expand Up @@ -189,7 +186,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
{
deviceHostHeader: sourceHost,
Expand Down Expand Up @@ -224,7 +220,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
{
deviceHostHeader: sourceHost,
Expand Down Expand Up @@ -271,7 +266,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
{
debuggerHeaders: {
Expand Down Expand Up @@ -356,7 +350,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
{
deviceHostHeader: sourceHost,
Expand Down Expand Up @@ -396,7 +389,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
{
deviceHostHeader: '127.0.0.1:' + serverRef.port,
Expand Down Expand Up @@ -431,7 +423,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
);
try {
Expand Down Expand Up @@ -479,7 +470,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
);

Expand Down Expand Up @@ -528,7 +518,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
);

Expand Down Expand Up @@ -581,7 +570,6 @@ describe.each(['HTTP', 'HTTPS'])(
capabilities: {
nativeSourceCodeFetching: true,
},
vm: 'bar-vm',
};

describe('Debugger.scriptParsed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import type {
PageDescription,
} from '../inspector-proxy/types';

import {WS_CLOSE_REASON} from '../inspector-proxy/Device';
import {fetchJson} from './FetchUtils';
import {createDebuggerMock} from './InspectorDebuggerUtils';
import {createDeviceMock} from './InspectorDeviceUtils';
import {sendFromDebuggerToTarget} from './InspectorProtocolUtils';
import {
createAndConnectTarget,
sendFromDebuggerToTarget,
} from './InspectorProtocolUtils';
import {withAbortSignalForEachTest} from './ResourceUtils';
import {withServerForEachTest} from './ServerUtils';
import until from 'wait-for-expect';
Expand Down Expand Up @@ -51,7 +55,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);

Expand Down Expand Up @@ -111,7 +114,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);

Expand Down Expand Up @@ -167,7 +169,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);
let pageList: Array<PageDescription> = [];
Expand Down Expand Up @@ -217,7 +218,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);
let pageList: Array<PageDescription> = [];
Expand Down Expand Up @@ -291,7 +291,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);

Expand Down Expand Up @@ -337,7 +336,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);

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

test('device disconnect event closes the debugger connection', async () => {
const {device, debugger_, sessionId} = await createAndConnectTarget(
serverRef,
autoCleanup.signal,
{
app: 'bar-app',
id: 'page1',
title: 'bar-title',
},
);
const debuggerClosed = new Promise<{code: number, reason: string}>(
resolve =>
debugger_.socket.once('close', (code: number, reason: Buffer) =>
resolve({code, reason: reason.toString()}),
),
);

try {
device.send({
event: 'disconnect',
payload: {
pageId: 'page1',
sessionId,
},
});
expect(await debuggerClosed).toEqual({
code: 1000,
reason: WS_CLOSE_REASON.PAGE_REMOVED,
});
} finally {
device.close();
debugger_.close();
}
});

describe('session ID handling', () => {
test('each debugger connection receives a unique session ID', async () => {
let device, debugger1, debugger2;
Expand All @@ -376,7 +409,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);
let pageList: Array<PageDescription> = [];
Expand Down Expand Up @@ -439,7 +471,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);
let pageList: Array<PageDescription> = [];
Expand Down Expand Up @@ -493,7 +524,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);
let pageList: Array<PageDescription> = [];
Expand Down Expand Up @@ -546,7 +576,6 @@ describe.each(['HTTP', 'HTTPS'])(
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
},
]);
let pageList: Array<PageDescription> = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe('inspector proxy concurrent sessions', () => {
id: 'page1',
app: 'bar-app',
title: 'bar-title',
vm: 'bar-vm',
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
* @format
*/

import {fetchJson} from './FetchUtils';
import {createDebuggerMock} from './InspectorDebuggerUtils';
import {createDeviceMock} from './InspectorDeviceUtils';
import {createAndConnectTarget} from './InspectorProtocolUtils';
import {withAbortSignalForEachTest} from './ResourceUtils';
import {baseUrlForServer, createServer} from './ServerUtils';
import invariant from 'invariant';
import until from 'wait-for-expect';

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

afterEach(() => {
Expand Down Expand Up @@ -78,85 +73,6 @@ describe('inspector proxy device message middleware', () => {
}
});

test('middleware is created with device, debugger, and page information for synthetic reloadable page', async () => {
const createCustomMessageHandler = jest.fn().mockImplementation(() => null);
const {server} = await createServer({
logger: undefined,
unstable_customInspectorMessageHandler: createCustomMessageHandler,
});
const {serverBaseUrl, serverBaseWsUrl} = serverRefUrls(server);

let device, debugger_;
try {
device = await createDeviceMock(
`${serverBaseWsUrl}/inspector/device?device=device1&name=foo&app=bar`,
autoCleanup.signal,
);
// Mock the device to return a normal React (Native) page
device.getPages.mockImplementation(() => [
{
...page,
// NOTE: 'React' is a magic string used to detect React Native pages.
title: 'React Native (mock)',
},
]);

// Retrieve the full page list from device
let pageList;
await until(async () => {
pageList = (await fetchJson(
`${serverBaseUrl}/json`,
// $FlowFixMe[unclear-type]
)) as any;
expect(pageList.length).toBeGreaterThan(0);
});
invariant(pageList != null, '');

// Find the synthetic page
const syntheticPage = pageList.find(
({title}) =>
// NOTE: Magic string used for the synthetic page that has a stable ID
title === 'React Native Experimental (Improved Chrome Reloads)',
);
expect(syntheticPage).not.toBeUndefined();

// Connect the debugger to this synthetic page
debugger_ = await createDebuggerMock(
syntheticPage.webSocketDebuggerUrl,
autoCleanup.signal,
);

// Ensure the middleware was created with the device information
await until(() =>
expect(createCustomMessageHandler).toBeCalledWith(
expect.objectContaining({
page: expect.objectContaining({
id: expect.any(String),
title: syntheticPage.title,
vm: syntheticPage.vm,
app: expect.any(String),
capabilities: expect.any(Object),
}),
device: expect.objectContaining({
appId: expect.any(String),
id: expect.any(String),
name: expect.any(String),
sendMessage: expect.any(Function),
}),
debugger: expect.objectContaining({
userAgent: null,
sendMessage: expect.any(Function),
}),
}),
),
);
} finally {
device?.close();
debugger_?.close();
await closeServer(server);
}
});

test('send message functions are passing messages to sockets', async () => {
const handleDebuggerMessage = jest.fn();
const handleDeviceMessage = jest.fn();
Expand Down
Loading
Loading