Move screenshot to iOSBridge

Summary:
In order to support IOS cloud devices, we need to abstract
over the direct uses of idb/xcrun so we can switch them
out based on more than the device type.

Note that there's a bit of a type weirdness in there. I'll
clean this up with the next diff.

Reviewed By: mweststrate

Differential Revision: D30248036

fbshipit-source-id: ec8571429e04abe059850ef334a6645ae4a5e034
This commit is contained in:
Pascal Hartig
2021-08-11 11:02:10 -07:00
committed by Facebook GitHub Bot
parent f515df1c01
commit 52b3edc5ad
3 changed files with 66 additions and 19 deletions

View File

@@ -9,11 +9,15 @@
import {makeIOSBridge} from '../IOSBridge';
import childProcess from 'child_process';
import * as promisifyChildProcess from 'promisify-child-process';
import {mocked} from 'ts-jest/utils';
jest.mock('child_process');
const spawn = mocked(childProcess.spawn);
jest.mock('promisify-child-process');
const exec = mocked(promisifyChildProcess.exec);
test('uses xcrun with no idb when xcode is detected', async () => {
const ib = await makeIOSBridge('', true);
expect(ib.startLogListener).toBeDefined();
@@ -92,3 +96,23 @@ test('uses no log listener when xcode is not detected', async () => {
const ib = await makeIOSBridge('', false);
expect(ib.startLogListener).toBeUndefined();
});
test('uses xcrun to take screenshots with no idb when xcode is detected', async () => {
const ib = await makeIOSBridge('', true);
ib.screenshot!('deadbeef');
expect(exec).toHaveBeenCalledWith(
'xcrun simctl io deadbeef screenshot /temp/00000000-0000-0000-0000-000000000000.png',
);
});
test('uses idb to take screenshots when available', async () => {
const ib = await makeIOSBridge('/usr/local/bin/idb', true, async (_) => true);
ib.screenshot!('deadbeef');
expect(exec).toHaveBeenCalledWith(
'idb screenshot --udid deadbeef /temp/00000000-0000-0000-0000-000000000000.png',
);
});