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
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@

const {unstable_spawnDebuggerShellWithArgs} = require('../../');

// prevent console pollution from spawned shell
const logger = {
...console,
info: jest.fn(),
error: jest.fn(),
};

describe('debugger-shell Node package', () => {
test('can spawn in detached+prebuilt mode without crashing', async () => {
await expect(
unstable_spawnDebuggerShellWithArgs(['--version'], {
flavor: 'prebuilt',
mode: 'detached',
logger,
}),
).resolves.toBeUndefined();
});
Expand All @@ -32,6 +40,7 @@ describe('debugger-shell Node package', () => {
unstable_spawnDebuggerShellWithArgs(['--version'], {
flavor: 'dev',
mode: 'detached',
logger,
}),
).resolves.toBeUndefined();
});
Expand Down
10 changes: 6 additions & 4 deletions packages/debugger-shell/src/node/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function unstable_spawnDebuggerShellWithArgs(
mode = 'detached',
flavor = process.env.RNDT_DEV === '1' ? 'dev' : 'prebuilt',
prebuiltBinaryPath,
logger = console,
}: $ReadOnly<{
// In 'syncAndExit' mode, the current process will block until the spawned process exits, and then it will exit
// with the same exit code as the spawned process.
Expand All @@ -40,6 +41,7 @@ async function unstable_spawnDebuggerShellWithArgs(
mode?: 'syncThenExit' | 'detached',
flavor?: DebuggerShellFlavor,
prebuiltBinaryPath?: ?string,
logger?: typeof console,
}> = {},
): Promise<void> {
const [binaryPath, baseArgs] = getShellBinaryAndArgs(
Expand Down Expand Up @@ -69,7 +71,7 @@ async function unstable_spawnDebuggerShellWithArgs(
child.on('close', (code: number, signal) => {
debug('Debugger closed with code %s and signal %s', code, signal);
if (code !== 0) {
console.error(
logger.error(
'Debugger closed with code %s and signal %s',
code,
signal,
Expand All @@ -86,17 +88,17 @@ async function unstable_spawnDebuggerShellWithArgs(
reject(error);
});
child.stdout.on('data', data =>
console.debug('[DebuggerShell stdout] ' + String(data)),
logger.info('[DebuggerShell stdout] ' + String(data)),
);
child.stderr.on('data', data =>
console.debug('[DebuggerShell stderr] ' + String(data)),
logger.info('[DebuggerShell stderr] ' + String(data)),
);
child.unref();
} else if (mode === 'syncThenExit') {
child.on('close', function (code, signal) {
debug('Debugger closed with code %s and signal %s', code, signal);
if (code === null) {
console.error(
logger.error(
'Debugger closed with code %s and signal %s',
code,
signal,
Expand Down
Loading