Separate concerns of reading screenshot into buffer & execing screenshot function
Summary: This allows us to change the way that the command is itself exec'd (for instance to change the idb exec'ing in D33818298) Reviewed By: passy Differential Revision: D33818822 fbshipit-source-id: c90b7e58c7476f5db08da0e74e9791230ff97f6f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4f886448e0
commit
e2abe1c89a
@@ -47,8 +47,8 @@ class IDBBridge implements IOSBridge {
|
||||
|
||||
async screenshot(serial: string): Promise<Buffer> {
|
||||
const imagePath = makeTempScreenshotFilePath();
|
||||
const command = `idb screenshot --udid ${serial} ${imagePath}`;
|
||||
return runScreenshotCommand(command, imagePath);
|
||||
await exec(`idb screenshot --udid ${serial} ${imagePath}`);
|
||||
return readScreenshotIntoBuffer(imagePath);
|
||||
}
|
||||
|
||||
startLogListener(
|
||||
@@ -95,8 +95,8 @@ class SimctlBridge implements IOSBridge {
|
||||
|
||||
async screenshot(serial: string): Promise<Buffer> {
|
||||
const imagePath = makeTempScreenshotFilePath();
|
||||
const command = `xcrun simctl io ${serial} screenshot ${imagePath}`;
|
||||
return runScreenshotCommand(command, imagePath);
|
||||
await exec(`xcrun simctl io ${serial} screenshot ${imagePath}`);
|
||||
return readScreenshotIntoBuffer(imagePath);
|
||||
}
|
||||
|
||||
async navigate(serial: string, location: string): Promise<void> {
|
||||
@@ -144,11 +144,7 @@ function makeTempScreenshotFilePath() {
|
||||
return path.join(getFlipperServerConfig().paths.tempPath, imageName);
|
||||
}
|
||||
|
||||
async function runScreenshotCommand(
|
||||
command: string,
|
||||
imagePath: string,
|
||||
): Promise<Buffer> {
|
||||
await exec(command);
|
||||
async function readScreenshotIntoBuffer(imagePath: string): Promise<Buffer> {
|
||||
const buffer = await fs.readFile(imagePath);
|
||||
await fs.unlink(imagePath);
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user