-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Expand file tree
/
Copy pathStandaloneFuseboxShell-test.js
More file actions
133 lines (119 loc) · 4.41 KB
/
StandaloneFuseboxShell-test.js
File metadata and controls
133 lines (119 loc) · 4.41 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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
import type {JsonPagesListResponse} from '../inspector-proxy/types';
import type {AppLauncher} from '../types/AppLauncher';
import DefaultAppLauncher from '../utils/DefaultAppLauncher';
import {fetchJson, requestLocal} from './FetchUtils';
import {createDeviceMock} from './InspectorDeviceUtils';
import {withAbortSignalForEachTest} from './ResourceUtils';
import {withServerForEachTest} from './ServerUtils';
// Must be greater than PAGES_POLLING_INTERVAL in `Device.js`
const PAGES_POLLING_DELAY = 2100;
jest.useFakeTimers();
describe('enableStandaloneFuseboxShell experiment', () => {
const AppLauncherWithFuseboxShell: AppLauncher = {
...DefaultAppLauncher,
launchDebuggerShell: () => {
throw new Error('Not implemented');
},
prepareDebuggerShell: async () => {
return {code: 'not_implemented'};
},
};
const serverRef = withServerForEachTest({
logger: undefined,
unstable_appLauncher: AppLauncherWithFuseboxShell,
unstable_experiments: {
enableStandaloneFuseboxShell: true,
},
});
const autoCleanup = withAbortSignalForEachTest();
afterEach(() => {
jest.clearAllMocks();
});
describe('/open-debugger endpoint', () => {
test('launches the shell with a frontend URL and stable window key', async () => {
// Connect a device to use when opening the debugger
const device = await createDeviceMock(
`${serverRef.serverBaseWsUrl}/inspector/device?device=device1&name=foo&app=bar`,
autoCleanup.signal,
);
device.getPages.mockImplementation(() => [
{
app: 'bar-app',
id: 'page1',
title: 'bar-title',
vm: 'bar-vm',
capabilities: {
// Ensure the device target can be found when launching the debugger
nativePageReloads: true,
},
},
]);
jest.advanceTimersByTime(PAGES_POLLING_DELAY);
const launchDebuggerAppWindowSpy = jest
.spyOn(AppLauncherWithFuseboxShell, 'launchDebuggerAppWindow')
.mockResolvedValue();
const showFuseboxShellSpy = jest
.spyOn(AppLauncherWithFuseboxShell, 'launchDebuggerShell')
.mockResolvedValue();
try {
// Fetch the target information for the device
const pageListResponse = await fetchJson<JsonPagesListResponse>(
`${serverRef.serverBaseUrl}/json`,
);
// Select the first target from the page list response
expect(pageListResponse.length).toBeGreaterThanOrEqual(1);
const firstPage = pageListResponse[0];
// Build the URL for the debugger
const openUrl = new URL('/open-debugger', serverRef.serverBaseUrl);
openUrl.searchParams.set('launchId', 'launch1');
openUrl.searchParams.set(
'device',
firstPage.reactNative.logicalDeviceId,
);
openUrl.searchParams.set('target', firstPage.id);
// Request to open the debugger for the first device
{
const response = await requestLocal(openUrl.toString(), {
method: 'POST',
});
// Ensure the request was handled properly
expect(response.statusCode).toBe(200);
}
openUrl.searchParams.set('launchId', 'launch1');
// Ensure the debugger was launched using the standalone shell API
expect(showFuseboxShellSpy).toHaveBeenCalledWith(
expect.any(String),
expect.any(String),
);
const firstWindowKey = showFuseboxShellSpy.mock.calls[0][1];
showFuseboxShellSpy.mockClear();
openUrl.searchParams.set('launchId', 'launch2');
{
const response = await requestLocal(openUrl.toString(), {
method: 'POST',
});
// Ensure the request was handled properly
expect(response.statusCode).toBe(200);
}
// Ensure the debugger was launched using the standalone shell API and the same window key
expect(showFuseboxShellSpy).toHaveBeenCalledWith(
expect.any(String),
firstWindowKey,
);
expect(launchDebuggerAppWindowSpy).not.toHaveBeenCalled();
} finally {
device.close();
}
});
// TODO(moti): Add tests around prepareDebuggerShell
});
});