@johnf/react-native-owl
Version:
Visual regression testing for React Native
125 lines (123 loc) • 3.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toExist = exports.scrollToEnd = exports.scrollTo = exports.reload = exports.press = exports.longPress = exports.changeText = void 0;
var _config = require("./cli/config.js");
var _logger = require("./logger.js");
var _adb = require("./utils/adb.js");
var _waitFor = require("./utils/wait-for.js");
var _xcrun = require("./utils/xcrun.js");
var _websocket = require("./websocket.js");
const logger = new _logger.Logger(process.env.OWL_DEBUG === 'true');
const sendEvent = async event => new Promise(async (resolve, reject) => {
// Create a websocket client just for this event request/response cycle.
const actionsWebSocketClient = await (0, _websocket.createWebSocketClient)(logger, message => {
// Close this connection
actionsWebSocketClient.close();
// The message received here indicates the outcome of the action we sent to the app client
const event = JSON.parse(message);
switch (event.type) {
case 'DONE':
resolve(true);
break;
case 'NOT_FOUND':
reject(`Element not found: ${event.testID}`);
break;
case 'ERROR':
reject(`Element error: ${event.testID} - ${event.message}`);
break;
default:
reject('Unknown onMessage event type');
break;
}
});
actionsWebSocketClient.send(JSON.stringify(event));
});
const press = testID => sendEvent({
type: 'ACTION',
action: 'PRESS',
testID
});
exports.press = press;
const longPress = testID => sendEvent({
type: 'ACTION',
action: 'LONG_PRESS',
testID
});
exports.longPress = longPress;
const changeText = (testID, value) => sendEvent({
type: 'ACTION',
action: 'CHANGE_TEXT',
testID,
value
});
exports.changeText = changeText;
const scrollTo = (testID, value) => sendEvent({
type: 'ACTION',
action: 'SCROLL_TO',
testID,
value
});
exports.scrollTo = scrollTo;
const scrollToEnd = testID => sendEvent({
type: 'ACTION',
action: 'SCROLL_TO_END',
testID
});
exports.scrollToEnd = scrollToEnd;
const toExist = testID => sendEvent({
type: 'LAYOUT',
action: 'EXISTS',
testID
});
exports.toExist = toExist;
const reload = async () => {
const args = global.OWL_CLI_ARGS;
if (!args) {
return;
}
const config = await (0, _config.getConfig)(args.config);
if (args.platform === 'ios') {
if (!config.ios?.device) {
return Promise.reject('Missing device name');
}
await (0, _xcrun.xcrunTerminate)({
debug: config.debug,
binaryPath: config.ios?.binaryPath,
device: config.ios.device,
scheme: config.ios?.scheme,
configuration: config.ios?.configuration
});
await (0, _xcrun.xcrunLaunch)({
debug: config.debug,
binaryPath: config.ios?.binaryPath,
device: config.ios.device,
scheme: config.ios?.scheme,
configuration: config.ios?.configuration
});
await (0, _waitFor.waitFor)(1000);
await (0, _xcrun.xcrunUi)({
debug: config.debug,
device: config.ios.device,
configuration: config.ios.configuration,
binaryPath: config.ios.binaryPath
});
}
if (args.platform === 'android') {
if (!config.android?.packageName) {
return Promise.reject('Missing package name');
}
await (0, _adb.adbTerminate)({
debug: config.debug,
packageName: config.android.packageName
});
await (0, _adb.adbLaunch)({
debug: config.debug,
packageName: config.android.packageName
});
await (0, _waitFor.waitFor)(1000);
}
};
exports.reload = reload;
//# sourceMappingURL=actions.js.map