From a09fa4446119e702e7053a85393aec2ec1585399 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 20 Apr 2018 09:21:28 +0200 Subject: [PATCH] ensure generation delivers prettified code --- detox/src/android/espressoapi/DetoxAction.js | 181 ++-- detox/src/android/espressoapi/DetoxMatcher.js | 351 ++++++-- detox/src/android/espressoapi/ViewActions.js | 50 +- detox/src/ios/earlgreyapi/GREYActions.js | 832 ++++++++++++------ detox/src/ios/earlgreyapi/GREYCondition.js | 61 +- .../src/ios/earlgreyapi/GREYConditionDetox.js | 24 +- detox/src/ios/earlgreyapi/GREYInteraction.js | 108 ++- .../src/ios/earlgreyapi/GREYMatchers+Detox.js | 172 +++- detox/src/ios/earlgreyapi/GREYMatchers.js | 519 +++++++---- generation/index.js | 14 + 10 files changed, 1605 insertions(+), 707 deletions(-) diff --git a/detox/src/android/espressoapi/DetoxAction.js b/detox/src/android/espressoapi/DetoxAction.js index c0aabe94f8..e33c4bcf6f 100644 --- a/detox/src/android/espressoapi/DetoxAction.js +++ b/detox/src/android/espressoapi/DetoxAction.js @@ -4,127 +4,168 @@ For more information see generation/README.md. */ - function sanitize_android_edge(edge) { - switch (edge) { - case "left": - return 1; - case "right": - return 2; - case "top": - return 3; - case "bottom": - return 4; - default: - throw new Error( - `edge must be a 'left'/'right'/'top'/'bottom', got ${edge}` - ); - } -} + switch (edge) { + case "left": + return 1; + case "right": + return 2; + case "top": + return 3; + case "bottom": + return 4; + default: + throw new Error( + `edge must be a 'left'/'right'/'top'/'bottom', got ${edge}` + ); + } +} function sanitize_android_direction(direction) { - switch (direction) { - case "left": - return 1; - case "right": - return 2; - case "up": - return 3; - case "down": - return 4; - default: - throw new Error( - `direction must be a 'left'/'right'/'up'/'down', got ${direction}` - ); - } -} + switch (direction) { + case "left": + return 1; + case "right": + return 2; + case "up": + return 3; + case "down": + return 4; + default: + throw new Error( + `direction must be a 'left'/'right'/'up'/'down', got ${direction}` + ); + } +} class DetoxAction { static multiClick(times) { - if (typeof times !== "number") throw new Error("times should be a number, but got " + (times + (" (" + (typeof times + ")")))); + if (typeof times !== "number") + throw new Error( + "times should be a number, but got " + + (times + (" (" + (typeof times + ")"))) + ); return { target: { type: "Class", value: "com.wix.detox.espresso.DetoxAction" }, method: "multiClick", - args: [{ - type: "Integer", - value: times - }] + args: [ + { + type: "Integer", + value: times + } + ] }; } static tapAtLocation(x, y) { - if (typeof x !== "number") throw new Error("x should be a number, but got " + (x + (" (" + (typeof x + ")")))); - if (typeof y !== "number") throw new Error("y should be a number, but got " + (y + (" (" + (typeof y + ")")))); + if (typeof x !== "number") + throw new Error( + "x should be a number, but got " + (x + (" (" + (typeof x + ")"))) + ); + if (typeof y !== "number") + throw new Error( + "y should be a number, but got " + (y + (" (" + (typeof y + ")"))) + ); return { target: { type: "Class", value: "com.wix.detox.espresso.DetoxAction" }, method: "tapAtLocation", - args: [{ - type: "Integer", - value: x - }, { - type: "Integer", - value: y - }] + args: [ + { + type: "Integer", + value: x + }, + { + type: "Integer", + value: y + } + ] }; } static scrollToEdge(edge) { - if (typeof edge !== "string") throw new Error("edge should be a string, but got " + (edge + (" (" + (typeof edge + ")")))); + if (typeof edge !== "string") + throw new Error( + "edge should be a string, but got " + + (edge + (" (" + (typeof edge + ")"))) + ); return { target: { type: "Class", value: "com.wix.detox.espresso.DetoxAction" }, method: "scrollToEdge", - args: [{ - type: "Integer", - value: sanitize_android_edge(edge) - }] + args: [ + { + type: "Integer", + value: sanitize_android_edge(edge) + } + ] }; } static scrollInDirection(direction, amountInDP) { - if (typeof direction !== "string") throw new Error("direction should be a string, but got " + (direction + (" (" + (typeof direction + ")")))); - if (typeof amountInDP !== "number") throw new Error("amountInDP should be a number, but got " + (amountInDP + (" (" + (typeof amountInDP + ")")))); + if (typeof direction !== "string") + throw new Error( + "direction should be a string, but got " + + (direction + (" (" + (typeof direction + ")"))) + ); + if (typeof amountInDP !== "number") + throw new Error( + "amountInDP should be a number, but got " + + (amountInDP + (" (" + (typeof amountInDP + ")"))) + ); return { target: { type: "Class", value: "com.wix.detox.espresso.DetoxAction" }, method: "scrollInDirection", - args: [{ - type: "Integer", - value: sanitize_android_direction(direction) - }, { - type: "Double", - value: amountInDP - }] + args: [ + { + type: "Integer", + value: sanitize_android_direction(direction) + }, + { + type: "Double", + value: amountInDP + } + ] }; } static swipeInDirection(direction, fast) { - if (typeof direction !== "string") throw new Error("direction should be a string, but got " + (direction + (" (" + (typeof direction + ")")))); - if (typeof fast !== "boolean") throw new Error("fast should be a boolean, but got " + (fast + (" (" + (typeof fast + ")")))); + if (typeof direction !== "string") + throw new Error( + "direction should be a string, but got " + + (direction + (" (" + (typeof direction + ")"))) + ); + if (typeof fast !== "boolean") + throw new Error( + "fast should be a boolean, but got " + + (fast + (" (" + (typeof fast + ")"))) + ); return { target: { type: "Class", value: "com.wix.detox.espresso.DetoxAction" }, method: "swipeInDirection", - args: [{ - type: "Integer", - value: sanitize_android_direction(direction) - }, { - type: "boolean", - value: fast - }] + args: [ + { + type: "Integer", + value: sanitize_android_direction(direction) + }, + { + type: "boolean", + value: fast + } + ] }; } - } -module.exports = DetoxAction; \ No newline at end of file +module.exports = DetoxAction; diff --git a/detox/src/android/espressoapi/DetoxMatcher.js b/detox/src/android/espressoapi/DetoxMatcher.js index cc2107a693..e439b0347b 100644 --- a/detox/src/android/espressoapi/DetoxMatcher.js +++ b/detox/src/android/espressoapi/DetoxMatcher.js @@ -4,15 +4,18 @@ For more information see generation/README.md. */ - function sanitize_matcher(matcher) { - const originalMatcher = - typeof matcher._call === "function" ? matcher._call() : matcher._call; - return originalMatcher.type ? originalMatcher.value : originalMatcher; -} + const originalMatcher = + typeof matcher._call === "function" ? matcher._call() : matcher._call; + return originalMatcher.type ? originalMatcher.value : originalMatcher; +} class DetoxMatcher { static matcherForText(text) { - if (typeof text !== "string") throw new Error("text should be a string, but got " + (text + (" (" + (typeof text + ")")))); + if (typeof text !== "string") + throw new Error( + "text should be a string, but got " + + (text + (" (" + (typeof text + ")"))) + ); return { target: { type: "Class", @@ -24,7 +27,11 @@ class DetoxMatcher { } static matcherForContentDescription(contentDescription) { - if (typeof contentDescription !== "string") throw new Error("contentDescription should be a string, but got " + (contentDescription + (" (" + (typeof contentDescription + ")")))); + if (typeof contentDescription !== "string") + throw new Error( + "contentDescription should be a string, but got " + + (contentDescription + (" (" + (typeof contentDescription + ")"))) + ); return { target: { type: "Class", @@ -36,7 +43,11 @@ class DetoxMatcher { } static matcherForTestId(testId) { - if (typeof testId !== "string") throw new Error("testId should be a string, but got " + (testId + (" (" + (typeof testId + ")")))); + if (typeof testId !== "string") + throw new Error( + "testId should be a string, but got " + + (testId + (" (" + (typeof testId + ")"))) + ); return { target: { type: "Class", @@ -48,16 +59,42 @@ class DetoxMatcher { } static matcherForAnd(m1, m2) { - if (typeof m1 !== 'object' || typeof m1.constructor !== 'function' || m1.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m1 === 'object'; - const additionalErrorInfo = isObject ? typeof m1.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m1.constructor.name + '"' : 'it is no object'; - throw new Error('m1 should be an instance of Matcher, got "' + m1 + '", it appears that ' + additionalErrorInfo); + if ( + typeof m1 !== "object" || + typeof m1.constructor !== "function" || + m1.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m1 === "object"; + const additionalErrorInfo = isObject + ? typeof m1.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m1.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm1 should be an instance of Matcher, got "' + + m1 + + '", it appears that ' + + additionalErrorInfo + ); } - if (typeof m2 !== 'object' || typeof m2.constructor !== 'function' || m2.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m2 === 'object'; - const additionalErrorInfo = isObject ? typeof m2.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m2.constructor.name + '"' : 'it is no object'; - throw new Error('m2 should be an instance of Matcher, got "' + m2 + '", it appears that ' + additionalErrorInfo); + if ( + typeof m2 !== "object" || + typeof m2.constructor !== "function" || + m2.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m2 === "object"; + const additionalErrorInfo = isObject + ? typeof m2.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m2.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm2 should be an instance of Matcher, got "' + + m2 + + '", it appears that ' + + additionalErrorInfo + ); } return { @@ -66,27 +103,56 @@ class DetoxMatcher { value: "com.wix.detox.espresso.DetoxMatcher" }, method: "matcherForAnd", - args: [{ - type: "Invocation", - value: sanitize_matcher(m1) - }, { - type: "Invocation", - value: sanitize_matcher(m2) - }] + args: [ + { + type: "Invocation", + value: sanitize_matcher(m1) + }, + { + type: "Invocation", + value: sanitize_matcher(m2) + } + ] }; } static matcherForOr(m1, m2) { - if (typeof m1 !== 'object' || typeof m1.constructor !== 'function' || m1.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m1 === 'object'; - const additionalErrorInfo = isObject ? typeof m1.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m1.constructor.name + '"' : 'it is no object'; - throw new Error('m1 should be an instance of Matcher, got "' + m1 + '", it appears that ' + additionalErrorInfo); + if ( + typeof m1 !== "object" || + typeof m1.constructor !== "function" || + m1.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m1 === "object"; + const additionalErrorInfo = isObject + ? typeof m1.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m1.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm1 should be an instance of Matcher, got "' + + m1 + + '", it appears that ' + + additionalErrorInfo + ); } - if (typeof m2 !== 'object' || typeof m2.constructor !== 'function' || m2.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m2 === 'object'; - const additionalErrorInfo = isObject ? typeof m2.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m2.constructor.name + '"' : 'it is no object'; - throw new Error('m2 should be an instance of Matcher, got "' + m2 + '", it appears that ' + additionalErrorInfo); + if ( + typeof m2 !== "object" || + typeof m2.constructor !== "function" || + m2.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m2 === "object"; + const additionalErrorInfo = isObject + ? typeof m2.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m2.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm2 should be an instance of Matcher, got "' + + m2 + + '", it appears that ' + + additionalErrorInfo + ); } return { @@ -95,21 +161,37 @@ class DetoxMatcher { value: "com.wix.detox.espresso.DetoxMatcher" }, method: "matcherForOr", - args: [{ - type: "Invocation", - value: sanitize_matcher(m1) - }, { - type: "Invocation", - value: sanitize_matcher(m2) - }] + args: [ + { + type: "Invocation", + value: sanitize_matcher(m1) + }, + { + type: "Invocation", + value: sanitize_matcher(m2) + } + ] }; } static matcherForNot(m) { - if (typeof m !== 'object' || typeof m.constructor !== 'function' || m.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m === 'object'; - const additionalErrorInfo = isObject ? typeof m.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m.constructor.name + '"' : 'it is no object'; - throw new Error('m should be an instance of Matcher, got "' + m + '", it appears that ' + additionalErrorInfo); + if ( + typeof m !== "object" || + typeof m.constructor !== "function" || + m.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m === "object"; + const additionalErrorInfo = isObject + ? typeof m.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm should be an instance of Matcher, got "' + + m + + '", it appears that ' + + additionalErrorInfo + ); } return { @@ -118,24 +200,54 @@ class DetoxMatcher { value: "com.wix.detox.espresso.DetoxMatcher" }, method: "matcherForNot", - args: [{ - type: "Invocation", - value: sanitize_matcher(m) - }] + args: [ + { + type: "Invocation", + value: sanitize_matcher(m) + } + ] }; } static matcherWithAncestor(m, ancestorMatcher) { - if (typeof m !== 'object' || typeof m.constructor !== 'function' || m.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m === 'object'; - const additionalErrorInfo = isObject ? typeof m.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m.constructor.name + '"' : 'it is no object'; - throw new Error('m should be an instance of Matcher, got "' + m + '", it appears that ' + additionalErrorInfo); + if ( + typeof m !== "object" || + typeof m.constructor !== "function" || + m.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m === "object"; + const additionalErrorInfo = isObject + ? typeof m.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm should be an instance of Matcher, got "' + + m + + '", it appears that ' + + additionalErrorInfo + ); } - if (typeof ancestorMatcher !== 'object' || typeof ancestorMatcher.constructor !== 'function' || ancestorMatcher.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof ancestorMatcher === 'object'; - const additionalErrorInfo = isObject ? typeof ancestorMatcher.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + ancestorMatcher.constructor.name + '"' : 'it is no object'; - throw new Error('ancestorMatcher should be an instance of Matcher, got "' + ancestorMatcher + '", it appears that ' + additionalErrorInfo); + if ( + typeof ancestorMatcher !== "object" || + typeof ancestorMatcher.constructor !== "function" || + ancestorMatcher.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof ancestorMatcher === "object"; + const additionalErrorInfo = isObject + ? typeof ancestorMatcher.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + + ancestorMatcher.constructor.name + + '"' + : "it is no object"; + throw new Error( + 'ancestorMatcher should be an instance of Matcher, got "' + + ancestorMatcher + + '", it appears that ' + + additionalErrorInfo + ); } return { @@ -144,27 +256,58 @@ class DetoxMatcher { value: "com.wix.detox.espresso.DetoxMatcher" }, method: "matcherWithAncestor", - args: [{ - type: "Invocation", - value: sanitize_matcher(m) - }, { - type: "Invocation", - value: sanitize_matcher(ancestorMatcher) - }] + args: [ + { + type: "Invocation", + value: sanitize_matcher(m) + }, + { + type: "Invocation", + value: sanitize_matcher(ancestorMatcher) + } + ] }; } static matcherWithDescendant(m, descendantMatcher) { - if (typeof m !== 'object' || typeof m.constructor !== 'function' || m.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof m === 'object'; - const additionalErrorInfo = isObject ? typeof m.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m.constructor.name + '"' : 'it is no object'; - throw new Error('m should be an instance of Matcher, got "' + m + '", it appears that ' + additionalErrorInfo); + if ( + typeof m !== "object" || + typeof m.constructor !== "function" || + m.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof m === "object"; + const additionalErrorInfo = isObject + ? typeof m.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + m.constructor.name + '"' + : "it is no object"; + throw new Error( + 'm should be an instance of Matcher, got "' + + m + + '", it appears that ' + + additionalErrorInfo + ); } - if (typeof descendantMatcher !== 'object' || typeof descendantMatcher.constructor !== 'function' || descendantMatcher.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof descendantMatcher === 'object'; - const additionalErrorInfo = isObject ? typeof descendantMatcher.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + descendantMatcher.constructor.name + '"' : 'it is no object'; - throw new Error('descendantMatcher should be an instance of Matcher, got "' + descendantMatcher + '", it appears that ' + additionalErrorInfo); + if ( + typeof descendantMatcher !== "object" || + typeof descendantMatcher.constructor !== "function" || + descendantMatcher.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof descendantMatcher === "object"; + const additionalErrorInfo = isObject + ? typeof descendantMatcher.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + + descendantMatcher.constructor.name + + '"' + : "it is no object"; + throw new Error( + 'descendantMatcher should be an instance of Matcher, got "' + + descendantMatcher + + '", it appears that ' + + additionalErrorInfo + ); } return { @@ -173,18 +316,25 @@ class DetoxMatcher { value: "com.wix.detox.espresso.DetoxMatcher" }, method: "matcherWithDescendant", - args: [{ - type: "Invocation", - value: sanitize_matcher(m) - }, { - type: "Invocation", - value: sanitize_matcher(descendantMatcher) - }] + args: [ + { + type: "Invocation", + value: sanitize_matcher(m) + }, + { + type: "Invocation", + value: sanitize_matcher(descendantMatcher) + } + ] }; } static matcherForClass(className) { - if (typeof className !== "string") throw new Error("className should be a string, but got " + (className + (" (" + (typeof className + ")")))); + if (typeof className !== "string") + throw new Error( + "className should be a string, but got " + + (className + (" (" + (typeof className + ")"))) + ); return { target: { type: "Class", @@ -240,12 +390,29 @@ class DetoxMatcher { } static matcherForAtIndex(index, innerMatcher) { - if (typeof index !== "number") throw new Error("index should be a number, but got " + (index + (" (" + (typeof index + ")")))); + if (typeof index !== "number") + throw new Error( + "index should be a number, but got " + + (index + (" (" + (typeof index + ")"))) + ); - if (typeof innerMatcher !== 'object' || typeof innerMatcher.constructor !== 'function' || innerMatcher.constructor.name.indexOf('Matcher') === -1) { - const isObject = typeof innerMatcher === 'object'; - const additionalErrorInfo = isObject ? typeof innerMatcher.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + innerMatcher.constructor.name + '"' : 'it is no object'; - throw new Error('innerMatcher should be an instance of Matcher, got "' + innerMatcher + '", it appears that ' + additionalErrorInfo); + if ( + typeof innerMatcher !== "object" || + typeof innerMatcher.constructor !== "function" || + innerMatcher.constructor.name.indexOf("Matcher") === -1 + ) { + const isObject = typeof innerMatcher === "object"; + const additionalErrorInfo = isObject + ? typeof innerMatcher.constructor === "object" + ? "the constructor is no object" + : 'it has a wrong class name: "' + innerMatcher.constructor.name + '"' + : "it is no object"; + throw new Error( + 'innerMatcher should be an instance of Matcher, got "' + + innerMatcher + + '", it appears that ' + + additionalErrorInfo + ); } return { @@ -254,13 +421,16 @@ class DetoxMatcher { value: "com.wix.detox.espresso.DetoxMatcher" }, method: "matcherForAtIndex", - args: [{ - type: "Integer", - value: index - }, { - type: "Invocation", - value: sanitize_matcher(innerMatcher) - }] + args: [ + { + type: "Integer", + value: index + }, + { + type: "Invocation", + value: sanitize_matcher(innerMatcher) + } + ] }; } @@ -274,7 +444,6 @@ class DetoxMatcher { args: [] }; } - } -module.exports = DetoxMatcher; \ No newline at end of file +module.exports = DetoxMatcher; diff --git a/detox/src/android/espressoapi/ViewActions.js b/detox/src/android/espressoapi/ViewActions.js index f01f12c6d9..1806e955e3 100644 --- a/detox/src/android/espressoapi/ViewActions.js +++ b/detox/src/android/espressoapi/ViewActions.js @@ -4,8 +4,6 @@ For more information see generation/README.md. */ - - class ViewActions { static clearGlobalAssertions() { return { @@ -129,17 +127,23 @@ class ViewActions { } static pressKey(keyCode) { - if (typeof keyCode !== "number") throw new Error("keyCode should be a number, but got " + (keyCode + (" (" + (typeof keyCode + ")")))); + if (typeof keyCode !== "number") + throw new Error( + "keyCode should be a number, but got " + + (keyCode + (" (" + (typeof keyCode + ")"))) + ); return { target: { type: "Class", value: "android.support.test.espresso.action.ViewActions" }, method: "pressKey", - args: [{ - type: "Integer", - value: keyCode - }] + args: [ + { + type: "Integer", + value: keyCode + } + ] }; } @@ -177,7 +181,11 @@ class ViewActions { } static typeTextIntoFocusedView(stringToBeTyped) { - if (typeof stringToBeTyped !== "string") throw new Error("stringToBeTyped should be a string, but got " + (stringToBeTyped + (" (" + (typeof stringToBeTyped + ")")))); + if (typeof stringToBeTyped !== "string") + throw new Error( + "stringToBeTyped should be a string, but got " + + (stringToBeTyped + (" (" + (typeof stringToBeTyped + ")"))) + ); return { target: { type: "Class", @@ -189,7 +197,11 @@ class ViewActions { } static typeText(stringToBeTyped) { - if (typeof stringToBeTyped !== "string") throw new Error("stringToBeTyped should be a string, but got " + (stringToBeTyped + (" (" + (typeof stringToBeTyped + ")")))); + if (typeof stringToBeTyped !== "string") + throw new Error( + "stringToBeTyped should be a string, but got " + + (stringToBeTyped + (" (" + (typeof stringToBeTyped + ")"))) + ); return { target: { type: "Class", @@ -201,7 +213,11 @@ class ViewActions { } static replaceText(stringToBeSet) { - if (typeof stringToBeSet !== "string") throw new Error("stringToBeSet should be a string, but got " + (stringToBeSet + (" (" + (typeof stringToBeSet + ")")))); + if (typeof stringToBeSet !== "string") + throw new Error( + "stringToBeSet should be a string, but got " + + (stringToBeSet + (" (" + (typeof stringToBeSet + ")"))) + ); return { target: { type: "Class", @@ -213,7 +229,11 @@ class ViewActions { } static openLinkWithText(linkText) { - if (typeof linkText !== "string") throw new Error("linkText should be a string, but got " + (linkText + (" (" + (typeof linkText + ")")))); + if (typeof linkText !== "string") + throw new Error( + "linkText should be a string, but got " + + (linkText + (" (" + (typeof linkText + ")"))) + ); return { target: { type: "Class", @@ -225,7 +245,10 @@ class ViewActions { } static openLinkWithUri(uri) { - if (typeof uri !== "string") throw new Error("uri should be a string, but got " + (uri + (" (" + (typeof uri + ")")))); + if (typeof uri !== "string") + throw new Error( + "uri should be a string, but got " + (uri + (" (" + (typeof uri + ")"))) + ); return { target: { type: "Class", @@ -235,7 +258,6 @@ class ViewActions { args: [uri] }; } - } -module.exports = ViewActions; \ No newline at end of file +module.exports = ViewActions; diff --git a/detox/src/ios/earlgreyapi/GREYActions.js b/detox/src/ios/earlgreyapi/GREYActions.js index ff01f28295..fba41b9a88 100644 --- a/detox/src/ios/earlgreyapi/GREYActions.js +++ b/detox/src/ios/earlgreyapi/GREYActions.js @@ -4,78 +4,107 @@ For more information see generation/README.md. */ - function sanitize_greyDirection(action) { - switch (action) { - case "left": - return 1; - case "right": - return 2; - case "up": - return 3; - case "down": - return 4; - - default: - throw new Error( - `GREYAction.GREYDirection must be a 'left'/'right'/'up'/'down', got ${action}` - ); - } -} + switch (action) { + case "left": + return 1; + case "right": + return 2; + case "up": + return 3; + case "down": + return 4; + + default: + throw new Error( + `GREYAction.GREYDirection must be a 'left'/'right'/'up'/'down', got ${action}` + ); + } +} function sanitize_greyContentEdge(action) { - switch (action) { - case "left": - return 0; - case "right": - return 1; - case "top": - return 2; - case "bottom": - return 3; - - default: - throw new Error( - `GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}` - ); - } -} + switch (action) { + case "left": + return 0; + case "right": + return 1; + case "top": + return 2; + case "bottom": + return 3; + + default: + throw new Error( + `GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}` + ); + } +} class GREYActions { /*@return A GREYAction that performs multiple taps of a specified @c count. -*/static actionForMultipleTapsWithCount(count) { - if (typeof count !== "number") throw new Error("count should be a number, but got " + (count + (" (" + (typeof count + ")")))); +*/ static actionForMultipleTapsWithCount( + count + ) { + if (typeof count !== "number") + throw new Error( + "count should be a number, but got " + + (count + (" (" + (typeof count + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForMultipleTapsWithCount:", - args: [{ - type: "NSInteger", - value: count - }] + args: [ + { + type: "NSInteger", + value: count + } + ] }; } /*@return A GREYAction that performs multiple taps of a specified @c count at a specified @c point. -*/static actionForMultipleTapsWithCountAtPoint(count, point) { - if (typeof count !== "number") throw new Error("count should be a number, but got " + (count + (" (" + (typeof count + ")")))); - if (typeof point !== "object") throw new Error("point should be a object, but got " + (point + (" (" + (typeof point + ")")))); - if (typeof point.x !== "number") throw new Error("point.x should be a number, but got " + (point.x + (" (" + (typeof point.x + ")")))); - if (typeof point.y !== "number") throw new Error("point.y should be a number, but got " + (point.y + (" (" + (typeof point.y + ")")))); +*/ static actionForMultipleTapsWithCountAtPoint( + count, + point + ) { + if (typeof count !== "number") + throw new Error( + "count should be a number, but got " + + (count + (" (" + (typeof count + ")"))) + ); + if (typeof point !== "object") + throw new Error( + "point should be a object, but got " + + (point + (" (" + (typeof point + ")"))) + ); + if (typeof point.x !== "number") + throw new Error( + "point.x should be a number, but got " + + (point.x + (" (" + (typeof point.x + ")"))) + ); + if (typeof point.y !== "number") + throw new Error( + "point.y should be a number, but got " + + (point.y + (" (" + (typeof point.y + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForMultipleTapsWithCount:atPoint:", - args: [{ - type: "NSInteger", - value: count - }, { - type: "CGPoint", - value: point - }] + args: [ + { + type: "NSInteger", + value: count + }, + { + type: "CGPoint", + value: point + } + ] }; } @@ -83,7 +112,7 @@ class GREYActions { simulate a long press. @return A GREYAction that performs a long press on an element. -*/static actionForLongPress() { +*/ static actionForLongPress() { return { target: { type: "Class", @@ -99,18 +128,26 @@ simulate a long press. @param duration The duration of the long press. @return A GREYAction that performs a long press on an element. -*/static actionForLongPressWithDuration(duration) { - if (typeof duration !== "number") throw new Error("duration should be a number, but got " + (duration + (" (" + (typeof duration + ")")))); +*/ static actionForLongPressWithDuration( + duration + ) { + if (typeof duration !== "number") + throw new Error( + "duration should be a number, but got " + + (duration + (" (" + (typeof duration + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForLongPressWithDuration:", - args: [{ - type: "CGFloat", - value: duration - }] + args: [ + { + type: "CGFloat", + value: duration + } + ] }; } @@ -121,24 +158,46 @@ simulate a long press. @param duration The duration of the long press. @return A GREYAction that performs a long press on an element. -*/static actionForLongPressAtPointDuration(point, duration) { - if (typeof point !== "object") throw new Error("point should be a object, but got " + (point + (" (" + (typeof point + ")")))); - if (typeof point.x !== "number") throw new Error("point.x should be a number, but got " + (point.x + (" (" + (typeof point.x + ")")))); - if (typeof point.y !== "number") throw new Error("point.y should be a number, but got " + (point.y + (" (" + (typeof point.y + ")")))); - if (typeof duration !== "number") throw new Error("duration should be a number, but got " + (duration + (" (" + (typeof duration + ")")))); +*/ static actionForLongPressAtPointDuration( + point, + duration + ) { + if (typeof point !== "object") + throw new Error( + "point should be a object, but got " + + (point + (" (" + (typeof point + ")"))) + ); + if (typeof point.x !== "number") + throw new Error( + "point.x should be a number, but got " + + (point.x + (" (" + (typeof point.x + ")"))) + ); + if (typeof point.y !== "number") + throw new Error( + "point.y should be a number, but got " + + (point.y + (" (" + (typeof point.y + ")"))) + ); + if (typeof duration !== "number") + throw new Error( + "duration should be a number, but got " + + (duration + (" (" + (typeof duration + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForLongPressAtPoint:duration:", - args: [{ - type: "CGPoint", - value: point - }, { - type: "CGFloat", - value: duration - }] + args: [ + { + type: "CGPoint", + value: point + }, + { + type: "CGFloat", + value: duration + } + ] }; } @@ -149,22 +208,36 @@ simulate a long press. @param amount The amount of points in CGPoints to scroll. @return A GREYAction that scrolls a scroll view in a given @c direction for a given @c amount. -*/static actionForScrollInDirectionAmount(direction, amount) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof amount !== "number") throw new Error("amount should be a number, but got " + (amount + (" (" + (typeof amount + ")")))); +*/ static actionForScrollInDirectionAmount( + direction, + amount + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof amount !== "number") + throw new Error( + "amount should be a number, but got " + + (amount + (" (" + (typeof amount + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForScrollInDirection:amount:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "CGFloat", - value: amount - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "CGFloat", + value: amount + } + ] }; } @@ -184,46 +257,82 @@ exclusive, of the total height of the scrollable visible area. @return A GREYAction that scrolls a scroll view in a given @c direction for a given @c amount starting from the given start points. -*/static actionForScrollInDirectionAmountXOriginStartPercentageYOriginStartPercentage(direction, amount, xOriginStartPercentage, yOriginStartPercentage) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof amount !== "number") throw new Error("amount should be a number, but got " + (amount + (" (" + (typeof amount + ")")))); - if (typeof xOriginStartPercentage !== "number") throw new Error("xOriginStartPercentage should be a number, but got " + (xOriginStartPercentage + (" (" + (typeof xOriginStartPercentage + ")")))); - if (typeof yOriginStartPercentage !== "number") throw new Error("yOriginStartPercentage should be a number, but got " + (yOriginStartPercentage + (" (" + (typeof yOriginStartPercentage + ")")))); +*/ static actionForScrollInDirectionAmountXOriginStartPercentageYOriginStartPercentage( + direction, + amount, + xOriginStartPercentage, + yOriginStartPercentage + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof amount !== "number") + throw new Error( + "amount should be a number, but got " + + (amount + (" (" + (typeof amount + ")"))) + ); + if (typeof xOriginStartPercentage !== "number") + throw new Error( + "xOriginStartPercentage should be a number, but got " + + (xOriginStartPercentage + + (" (" + (typeof xOriginStartPercentage + ")"))) + ); + if (typeof yOriginStartPercentage !== "number") + throw new Error( + "yOriginStartPercentage should be a number, but got " + + (yOriginStartPercentage + + (" (" + (typeof yOriginStartPercentage + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, - method: "actionForScrollInDirection:amount:xOriginStartPercentage:yOriginStartPercentage:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "CGFloat", - value: amount - }, { - type: "CGFloat", - value: xOriginStartPercentage - }, { - type: "CGFloat", - value: yOriginStartPercentage - }] + method: + "actionForScrollInDirection:amount:xOriginStartPercentage:yOriginStartPercentage:", + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "CGFloat", + value: amount + }, + { + type: "CGFloat", + value: xOriginStartPercentage + }, + { + type: "CGFloat", + value: yOriginStartPercentage + } + ] }; } /*@return A GREYAction that scrolls to the given content @c edge of a scroll view. -*/static actionForScrollToContentEdge(edge) { - if (!["left", "right", "top", "bottom"].some(option => option === edge)) throw new Error("edge should be one of [left, right, top, bottom], but got " + edge); +*/ static actionForScrollToContentEdge( + edge + ) { + if (!["left", "right", "top", "bottom"].some(option => option === edge)) + throw new Error( + "edge should be one of [left, right, top, bottom], but got " + edge + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForScrollToContentEdge:", - args: [{ - type: "NSInteger", - value: sanitize_greyContentEdge(edge) - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyContentEdge(edge) + } + ] }; } @@ -242,26 +351,48 @@ exclusive, of the total height of the scrollable visible area. @return A GREYAction that scrolls to the given content @c edge of a scroll view with the scroll action starting from the given start point. -*/static actionForScrollToContentEdgeXOriginStartPercentageYOriginStartPercentage(edge, xOriginStartPercentage, yOriginStartPercentage) { - if (!["left", "right", "top", "bottom"].some(option => option === edge)) throw new Error("edge should be one of [left, right, top, bottom], but got " + edge); - if (typeof xOriginStartPercentage !== "number") throw new Error("xOriginStartPercentage should be a number, but got " + (xOriginStartPercentage + (" (" + (typeof xOriginStartPercentage + ")")))); - if (typeof yOriginStartPercentage !== "number") throw new Error("yOriginStartPercentage should be a number, but got " + (yOriginStartPercentage + (" (" + (typeof yOriginStartPercentage + ")")))); +*/ static actionForScrollToContentEdgeXOriginStartPercentageYOriginStartPercentage( + edge, + xOriginStartPercentage, + yOriginStartPercentage + ) { + if (!["left", "right", "top", "bottom"].some(option => option === edge)) + throw new Error( + "edge should be one of [left, right, top, bottom], but got " + edge + ); + if (typeof xOriginStartPercentage !== "number") + throw new Error( + "xOriginStartPercentage should be a number, but got " + + (xOriginStartPercentage + + (" (" + (typeof xOriginStartPercentage + ")"))) + ); + if (typeof yOriginStartPercentage !== "number") + throw new Error( + "yOriginStartPercentage should be a number, but got " + + (yOriginStartPercentage + + (" (" + (typeof yOriginStartPercentage + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, - method: "actionForScrollToContentEdge:xOriginStartPercentage:yOriginStartPercentage:", - args: [{ - type: "NSInteger", - value: sanitize_greyContentEdge(edge) - }, { - type: "CGFloat", - value: xOriginStartPercentage - }, { - type: "CGFloat", - value: yOriginStartPercentage - }] + method: + "actionForScrollToContentEdge:xOriginStartPercentage:yOriginStartPercentage:", + args: [ + { + type: "NSInteger", + value: sanitize_greyContentEdge(edge) + }, + { + type: "CGFloat", + value: xOriginStartPercentage + }, + { + type: "CGFloat", + value: yOriginStartPercentage + } + ] }; } @@ -271,18 +402,26 @@ achieve the maximum the swipe possible to the other edge. @param direction The direction of the swipe. @return A GREYAction that performs a fast swipe in the given direction. -*/static actionForSwipeFastInDirection(direction) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); +*/ static actionForSwipeFastInDirection( + direction + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForSwipeFastInDirection:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + } + ] }; } @@ -292,18 +431,26 @@ achieve maximum the swipe possible to the other edge. @param direction The direction of the swipe. @return A GREYAction that performs a slow swipe in the given direction. -*/static actionForSwipeSlowInDirection(direction) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); +*/ static actionForSwipeSlowInDirection( + direction + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForSwipeSlowInDirection:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + } + ] }; } @@ -318,26 +465,49 @@ of the view. This must be between 0 and 1. @return A GREYAction that performs a fast swipe through a view in a specific direction from the specified point. -*/static actionForSwipeFastInDirectionXOriginStartPercentageYOriginStartPercentage(direction, xOriginStartPercentage, yOriginStartPercentage) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof xOriginStartPercentage !== "number") throw new Error("xOriginStartPercentage should be a number, but got " + (xOriginStartPercentage + (" (" + (typeof xOriginStartPercentage + ")")))); - if (typeof yOriginStartPercentage !== "number") throw new Error("yOriginStartPercentage should be a number, but got " + (yOriginStartPercentage + (" (" + (typeof yOriginStartPercentage + ")")))); +*/ static actionForSwipeFastInDirectionXOriginStartPercentageYOriginStartPercentage( + direction, + xOriginStartPercentage, + yOriginStartPercentage + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof xOriginStartPercentage !== "number") + throw new Error( + "xOriginStartPercentage should be a number, but got " + + (xOriginStartPercentage + + (" (" + (typeof xOriginStartPercentage + ")"))) + ); + if (typeof yOriginStartPercentage !== "number") + throw new Error( + "yOriginStartPercentage should be a number, but got " + + (yOriginStartPercentage + + (" (" + (typeof yOriginStartPercentage + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, - method: "actionForSwipeFastInDirection:xOriginStartPercentage:yOriginStartPercentage:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "CGFloat", - value: xOriginStartPercentage - }, { - type: "CGFloat", - value: yOriginStartPercentage - }] + method: + "actionForSwipeFastInDirection:xOriginStartPercentage:yOriginStartPercentage:", + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "CGFloat", + value: xOriginStartPercentage + }, + { + type: "CGFloat", + value: yOriginStartPercentage + } + ] }; } @@ -352,26 +522,49 @@ of the view. This must be between 0 and 1. @return A GREYAction that performs a slow swipe through a view in a specific direction from the specified point. -*/static actionForSwipeSlowInDirectionXOriginStartPercentageYOriginStartPercentage(direction, xOriginStartPercentage, yOriginStartPercentage) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof xOriginStartPercentage !== "number") throw new Error("xOriginStartPercentage should be a number, but got " + (xOriginStartPercentage + (" (" + (typeof xOriginStartPercentage + ")")))); - if (typeof yOriginStartPercentage !== "number") throw new Error("yOriginStartPercentage should be a number, but got " + (yOriginStartPercentage + (" (" + (typeof yOriginStartPercentage + ")")))); +*/ static actionForSwipeSlowInDirectionXOriginStartPercentageYOriginStartPercentage( + direction, + xOriginStartPercentage, + yOriginStartPercentage + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof xOriginStartPercentage !== "number") + throw new Error( + "xOriginStartPercentage should be a number, but got " + + (xOriginStartPercentage + + (" (" + (typeof xOriginStartPercentage + ")"))) + ); + if (typeof yOriginStartPercentage !== "number") + throw new Error( + "yOriginStartPercentage should be a number, but got " + + (yOriginStartPercentage + + (" (" + (typeof yOriginStartPercentage + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, - method: "actionForSwipeSlowInDirection:xOriginStartPercentage:yOriginStartPercentage:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "CGFloat", - value: xOriginStartPercentage - }, { - type: "CGFloat", - value: yOriginStartPercentage - }] + method: + "actionForSwipeSlowInDirection:xOriginStartPercentage:yOriginStartPercentage:", + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "CGFloat", + value: xOriginStartPercentage + }, + { + type: "CGFloat", + value: yOriginStartPercentage + } + ] }; } @@ -383,22 +576,36 @@ the specified point. @return A GREYAction that performs a multi-finger slow swipe through a view in a specific direction from the specified point. -*/static actionForMultiFingerSwipeSlowInDirectionNumberOfFingers(direction, numberOfFingers) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof numberOfFingers !== "number") throw new Error("numberOfFingers should be a number, but got " + (numberOfFingers + (" (" + (typeof numberOfFingers + ")")))); +*/ static actionForMultiFingerSwipeSlowInDirectionNumberOfFingers( + direction, + numberOfFingers + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof numberOfFingers !== "number") + throw new Error( + "numberOfFingers should be a number, but got " + + (numberOfFingers + (" (" + (typeof numberOfFingers + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForMultiFingerSwipeSlowInDirection:numberOfFingers:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "NSInteger", - value: numberOfFingers - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "NSInteger", + value: numberOfFingers + } + ] }; } @@ -410,22 +617,36 @@ direction from the specified point. @return A GREYAction that performs a multi-finger fast swipe through a view in a specific direction from the specified point. -*/static actionForMultiFingerSwipeFastInDirectionNumberOfFingers(direction, numberOfFingers) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof numberOfFingers !== "number") throw new Error("numberOfFingers should be a number, but got " + (numberOfFingers + (" (" + (typeof numberOfFingers + ")")))); +*/ static actionForMultiFingerSwipeFastInDirectionNumberOfFingers( + direction, + numberOfFingers + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof numberOfFingers !== "number") + throw new Error( + "numberOfFingers should be a number, but got " + + (numberOfFingers + (" (" + (typeof numberOfFingers + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForMultiFingerSwipeFastInDirection:numberOfFingers:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "NSInteger", - value: numberOfFingers - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "NSInteger", + value: numberOfFingers + } + ] }; } @@ -437,30 +658,59 @@ direction from the specified point. @return A GREYAction that performs a multi-finger slow swipe through a view in a specific direction from the specified point. -*/static actionForMultiFingerSwipeSlowInDirectionNumberOfFingersXOriginStartPercentageYOriginStartPercentage(direction, numberOfFingers, xOriginStartPercentage, yOriginStartPercentage) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof numberOfFingers !== "number") throw new Error("numberOfFingers should be a number, but got " + (numberOfFingers + (" (" + (typeof numberOfFingers + ")")))); - if (typeof xOriginStartPercentage !== "number") throw new Error("xOriginStartPercentage should be a number, but got " + (xOriginStartPercentage + (" (" + (typeof xOriginStartPercentage + ")")))); - if (typeof yOriginStartPercentage !== "number") throw new Error("yOriginStartPercentage should be a number, but got " + (yOriginStartPercentage + (" (" + (typeof yOriginStartPercentage + ")")))); +*/ static actionForMultiFingerSwipeSlowInDirectionNumberOfFingersXOriginStartPercentageYOriginStartPercentage( + direction, + numberOfFingers, + xOriginStartPercentage, + yOriginStartPercentage + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof numberOfFingers !== "number") + throw new Error( + "numberOfFingers should be a number, but got " + + (numberOfFingers + (" (" + (typeof numberOfFingers + ")"))) + ); + if (typeof xOriginStartPercentage !== "number") + throw new Error( + "xOriginStartPercentage should be a number, but got " + + (xOriginStartPercentage + + (" (" + (typeof xOriginStartPercentage + ")"))) + ); + if (typeof yOriginStartPercentage !== "number") + throw new Error( + "yOriginStartPercentage should be a number, but got " + + (yOriginStartPercentage + + (" (" + (typeof yOriginStartPercentage + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, - method: "actionForMultiFingerSwipeSlowInDirection:numberOfFingers:xOriginStartPercentage:yOriginStartPercentage:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "NSInteger", - value: numberOfFingers - }, { - type: "CGFloat", - value: xOriginStartPercentage - }, { - type: "CGFloat", - value: yOriginStartPercentage - }] + method: + "actionForMultiFingerSwipeSlowInDirection:numberOfFingers:xOriginStartPercentage:yOriginStartPercentage:", + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "NSInteger", + value: numberOfFingers + }, + { + type: "CGFloat", + value: xOriginStartPercentage + }, + { + type: "CGFloat", + value: yOriginStartPercentage + } + ] }; } @@ -472,37 +722,66 @@ direction from the specified point. @return A GREYAction that performs a multi-finger fast swipe through a view in a specific direction from the specified point. -*/static actionForMultiFingerSwipeFastInDirectionNumberOfFingersXOriginStartPercentageYOriginStartPercentage(direction, numberOfFingers, xOriginStartPercentage, yOriginStartPercentage) { - if (!["left", "right", "up", "down"].some(option => option === direction)) throw new Error("direction should be one of [left, right, up, down], but got " + direction); - if (typeof numberOfFingers !== "number") throw new Error("numberOfFingers should be a number, but got " + (numberOfFingers + (" (" + (typeof numberOfFingers + ")")))); - if (typeof xOriginStartPercentage !== "number") throw new Error("xOriginStartPercentage should be a number, but got " + (xOriginStartPercentage + (" (" + (typeof xOriginStartPercentage + ")")))); - if (typeof yOriginStartPercentage !== "number") throw new Error("yOriginStartPercentage should be a number, but got " + (yOriginStartPercentage + (" (" + (typeof yOriginStartPercentage + ")")))); +*/ static actionForMultiFingerSwipeFastInDirectionNumberOfFingersXOriginStartPercentageYOriginStartPercentage( + direction, + numberOfFingers, + xOriginStartPercentage, + yOriginStartPercentage + ) { + if (!["left", "right", "up", "down"].some(option => option === direction)) + throw new Error( + "direction should be one of [left, right, up, down], but got " + + direction + ); + if (typeof numberOfFingers !== "number") + throw new Error( + "numberOfFingers should be a number, but got " + + (numberOfFingers + (" (" + (typeof numberOfFingers + ")"))) + ); + if (typeof xOriginStartPercentage !== "number") + throw new Error( + "xOriginStartPercentage should be a number, but got " + + (xOriginStartPercentage + + (" (" + (typeof xOriginStartPercentage + ")"))) + ); + if (typeof yOriginStartPercentage !== "number") + throw new Error( + "yOriginStartPercentage should be a number, but got " + + (yOriginStartPercentage + + (" (" + (typeof yOriginStartPercentage + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, - method: "actionForMultiFingerSwipeFastInDirection:numberOfFingers:xOriginStartPercentage:yOriginStartPercentage:", - args: [{ - type: "NSInteger", - value: sanitize_greyDirection(direction) - }, { - type: "NSInteger", - value: numberOfFingers - }, { - type: "CGFloat", - value: xOriginStartPercentage - }, { - type: "CGFloat", - value: yOriginStartPercentage - }] + method: + "actionForMultiFingerSwipeFastInDirection:numberOfFingers:xOriginStartPercentage:yOriginStartPercentage:", + args: [ + { + type: "NSInteger", + value: sanitize_greyDirection(direction) + }, + { + type: "NSInteger", + value: numberOfFingers + }, + { + type: "CGFloat", + value: xOriginStartPercentage + }, + { + type: "CGFloat", + value: yOriginStartPercentage + } + ] }; } /*Returns an action that taps on an element at the activation point of the element. @return A GREYAction to tap on an element. -*/static actionForTap() { +*/ static actionForTap() { return { target: { type: "Class", @@ -520,20 +799,36 @@ element and it's position is relative to the origin of the element, as in (element_width/2, element_height/2) will tap at the center of element. @return A GREYAction to tap on an element at a specific point. -*/static actionForTapAtPoint(point) { - if (typeof point !== "object") throw new Error("point should be a object, but got " + (point + (" (" + (typeof point + ")")))); - if (typeof point.x !== "number") throw new Error("point.x should be a number, but got " + (point.x + (" (" + (typeof point.x + ")")))); - if (typeof point.y !== "number") throw new Error("point.y should be a number, but got " + (point.y + (" (" + (typeof point.y + ")")))); +*/ static actionForTapAtPoint( + point + ) { + if (typeof point !== "object") + throw new Error( + "point should be a object, but got " + + (point + (" (" + (typeof point + ")"))) + ); + if (typeof point.x !== "number") + throw new Error( + "point.x should be a number, but got " + + (point.x + (" (" + (typeof point.x + ")"))) + ); + if (typeof point.y !== "number") + throw new Error( + "point.y should be a number, but got " + + (point.y + (" (" + (typeof point.y + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForTapAtPoint:", - args: [{ - type: "CGPoint", - value: point - }] + args: [ + { + type: "CGPoint", + value: point + } + ] }; } @@ -545,18 +840,26 @@ For Example: @"Helpo\b\bloWorld" will type HelloWorld in Objective-C. "Helpo\u{8}\u{8}loWorld" will type HelloWorld in Swift. @return A GREYAction to type a specific text string in a text field. -*/static actionForTypeText(text) { - if (typeof text !== "string") throw new Error("text should be a string, but got " + (text + (" (" + (typeof text + ")")))); +*/ static actionForTypeText( + text + ) { + if (typeof text !== "string") + throw new Error( + "text should be a string, but got " + + (text + (" (" + (typeof text + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForTypeText:", - args: [{ - type: "NSString", - value: text - }] + args: [ + { + type: "NSString", + value: text + } + ] }; } @@ -565,23 +868,31 @@ For Example: @"Helpo\b\bloWorld" will type HelloWorld in Objective-C. @param text The text to be typed. @return A GREYAction to type a specific text string in a text field. -*/static actionForReplaceText(text) { - if (typeof text !== "string") throw new Error("text should be a string, but got " + (text + (" (" + (typeof text + ")")))); +*/ static actionForReplaceText( + text + ) { + if (typeof text !== "string") + throw new Error( + "text should be a string, but got " + + (text + (" (" + (typeof text + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForReplaceText:", - args: [{ - type: "NSString", - value: text - }] + args: [ + { + type: "NSString", + value: text + } + ] }; } /*@return A GREYAction that clears a text field by injecting back-spaces. -*/static actionForClearText() { +*/ static actionForClearText() { return { target: { type: "Class", @@ -598,25 +909,38 @@ For Example: @"Helpo\b\bloWorld" will type HelloWorld in Objective-C. @param value The value to set the UIPickerView. @return A GREYAction to set the value of a specified column of a UIPickerView. -*/static actionForSetPickerColumnToValue(column, value) { - if (typeof column !== "number") throw new Error("column should be a number, but got " + (column + (" (" + (typeof column + ")")))); - if (typeof value !== "string") throw new Error("value should be a string, but got " + (value + (" (" + (typeof value + ")")))); +*/ static actionForSetPickerColumnToValue( + column, + value + ) { + if (typeof column !== "number") + throw new Error( + "column should be a number, but got " + + (column + (" (" + (typeof column + ")"))) + ); + if (typeof value !== "string") + throw new Error( + "value should be a string, but got " + + (value + (" (" + (typeof value + ")"))) + ); return { target: { type: "Class", value: "GREYActions" }, method: "actionForSetPickerColumn:toValue:", - args: [{ - type: "NSInteger", - value: column - }, { - type: "NSString", - value: value - }] + args: [ + { + type: "NSInteger", + value: column + }, + { + type: "NSString", + value: value + } + ] }; } - } -module.exports = GREYActions; \ No newline at end of file +module.exports = GREYActions; diff --git a/detox/src/ios/earlgreyapi/GREYCondition.js b/detox/src/ios/earlgreyapi/GREYCondition.js index 4db37b6c8a..a925690cb2 100644 --- a/detox/src/ios/earlgreyapi/GREYCondition.js +++ b/detox/src/ios/earlgreyapi/GREYCondition.js @@ -4,8 +4,6 @@ For more information see generation/README.md. */ - - class GREYCondition { /*Waits for the condition to be met until the specified @c seconds have elapsed. @@ -19,18 +17,27 @@ GREYCondition::waitWithTimeout:pollInterval: @param seconds Amount of time to wait for the condition to be met, in seconds. @return @c YES if the condition was met before the timeout, @c NO otherwise. -*/static waitWithTimeout(element, seconds) { - if (typeof seconds !== "number") throw new Error("seconds should be a number, but got " + (seconds + (" (" + (typeof seconds + ")")))); +*/ static waitWithTimeout( + element, + seconds + ) { + if (typeof seconds !== "number") + throw new Error( + "seconds should be a number, but got " + + (seconds + (" (" + (typeof seconds + ")"))) + ); return { target: { type: "Invocation", value: element }, method: "waitWithTimeout:", - args: [{ - type: "CGFloat", - value: seconds - }] + args: [ + { + type: "CGFloat", + value: seconds + } + ] }; } @@ -44,25 +51,39 @@ the condition as close as possible to every @c interval seconds. @param interval The minimum time that should elapse between checking the condition. @return @c YES if the condition was met before the timeout, @c NO otherwise. -*/static waitWithTimeoutPollInterval(element, seconds, interval) { - if (typeof seconds !== "number") throw new Error("seconds should be a number, but got " + (seconds + (" (" + (typeof seconds + ")")))); - if (typeof interval !== "number") throw new Error("interval should be a number, but got " + (interval + (" (" + (typeof interval + ")")))); +*/ static waitWithTimeoutPollInterval( + element, + seconds, + interval + ) { + if (typeof seconds !== "number") + throw new Error( + "seconds should be a number, but got " + + (seconds + (" (" + (typeof seconds + ")"))) + ); + if (typeof interval !== "number") + throw new Error( + "interval should be a number, but got " + + (interval + (" (" + (typeof interval + ")"))) + ); return { target: { type: "Invocation", value: element }, method: "waitWithTimeout:pollInterval:", - args: [{ - type: "CGFloat", - value: seconds - }, { - type: "CGFloat", - value: interval - }] + args: [ + { + type: "CGFloat", + value: seconds + }, + { + type: "CGFloat", + value: interval + } + ] }; } - } -module.exports = GREYCondition; \ No newline at end of file +module.exports = GREYCondition; diff --git a/detox/src/ios/earlgreyapi/GREYConditionDetox.js b/detox/src/ios/earlgreyapi/GREYConditionDetox.js index 991ed45398..881aa680f9 100644 --- a/detox/src/ios/earlgreyapi/GREYConditionDetox.js +++ b/detox/src/ios/earlgreyapi/GREYConditionDetox.js @@ -4,17 +4,19 @@ For more information see generation/README.md. */ - function sanitize_greyElementInteraction(value) { - return { - type: "Invocation", - value - }; -} + return { + type: "Invocation", + value + }; +} class GREYCondition { static detoxConditionForElementMatched(interaction) { if (typeof interaction !== "object") { - throw new Error('interaction should be a GREYElementInteraction, but got ' + JSON.stringify(interaction)); + throw new Error( + "interaction should be a GREYElementInteraction, but got " + + JSON.stringify(interaction) + ); } return { @@ -29,7 +31,10 @@ class GREYCondition { static detoxConditionForNotElementMatched(interaction) { if (typeof interaction !== "object") { - throw new Error('interaction should be a GREYElementInteraction, but got ' + JSON.stringify(interaction)); + throw new Error( + "interaction should be a GREYElementInteraction, but got " + + JSON.stringify(interaction) + ); } return { @@ -41,7 +46,6 @@ class GREYCondition { args: [sanitize_greyElementInteraction(interaction)] }; } - } -module.exports = GREYCondition; \ No newline at end of file +module.exports = GREYCondition; diff --git a/detox/src/ios/earlgreyapi/GREYInteraction.js b/detox/src/ios/earlgreyapi/GREYInteraction.js index 3d2598e7bc..d35a022165 100644 --- a/detox/src/ios/earlgreyapi/GREYInteraction.js +++ b/detox/src/ios/earlgreyapi/GREYInteraction.js @@ -4,8 +4,6 @@ For more information see generation/README.md. */ - - class GREYInteraction { /*Indicates that the current interaction should be performed on a UI element contained inside another UI element that is uniquely matched by @c rootMatcher. @@ -14,9 +12,21 @@ another UI element that is uniquely matched by @c rootMatcher. will be performed on. @return The provided GREYInteraction instance, with an appropriate rootMatcher. -*/static inRoot(element, rootMatcher) { - if (typeof rootMatcher !== "object" || rootMatcher.type !== "Invocation" || typeof rootMatcher.value !== "object" || typeof rootMatcher.value.target !== "object" || rootMatcher.value.target.value !== "GREYMatchers") { - throw new Error('rootMatcher should be a GREYMatcher, but got ' + JSON.stringify(rootMatcher)); +*/ static inRoot( + element, + rootMatcher + ) { + if ( + typeof rootMatcher !== "object" || + rootMatcher.type !== "Invocation" || + typeof rootMatcher.value !== "object" || + typeof rootMatcher.value.target !== "object" || + rootMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "rootMatcher should be a GREYMatcher, but got " + + JSON.stringify(rootMatcher) + ); } return { @@ -50,13 +60,33 @@ performAction:grey_tap()] // This should be separately called for the action. @param matcher The matcher that the element matches. @return The provided GREYInteraction instance, with an appropriate action and matcher. -*/static usingSearchActionOnElementWithMatcher(element, action, matcher) { - if (typeof action !== "object" || action.type !== "Invocation" || typeof action.value !== "object" || typeof action.value.target !== "object" || action.value.target.value !== "GREYActions") { - throw new Error('action should be a GREYAction, but got ' + JSON.stringify(action)); +*/ static usingSearchActionOnElementWithMatcher( + element, + action, + matcher + ) { + if ( + typeof action !== "object" || + action.type !== "Invocation" || + typeof action.value !== "object" || + typeof action.value.target !== "object" || + action.value.target.value !== "GREYActions" + ) { + throw new Error( + "action should be a GREYAction, but got " + JSON.stringify(action) + ); } - if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") { - throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher)); + if ( + typeof matcher !== "object" || + matcher.type !== "Invocation" || + typeof matcher.value !== "object" || + typeof matcher.value.target !== "object" || + matcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "matcher should be a GREYMatcher, but got " + JSON.stringify(matcher) + ); } return { @@ -75,9 +105,20 @@ performAction:grey_tap()] // This should be separately called for the action. @throws NSException if the action fails. @return The provided GREYInteraction instance with an appropriate action. -*/static performAction(element, action) { - if (typeof action !== "object" || action.type !== "Invocation" || typeof action.value !== "object" || typeof action.value.target !== "object" || action.value.target.value !== "GREYActions") { - throw new Error('action should be a GREYAction, but got ' + JSON.stringify(action)); +*/ static performAction( + element, + action + ) { + if ( + typeof action !== "object" || + action.type !== "Invocation" || + typeof action.value !== "object" || + typeof action.value.target !== "object" || + action.value.target.value !== "GREYActions" + ) { + throw new Error( + "action should be a GREYAction, but got " + JSON.stringify(action) + ); } return { @@ -95,9 +136,20 @@ performAction:grey_tap()] // This should be separately called for the action. @param matcher The matcher to be evaluated on the @c element. @return The provided GREYInteraction instance with a matcher to be evaluated on an element. -*/static assertWithMatcher(element, matcher) { - if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") { - throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher)); +*/ static assertWithMatcher( + element, + matcher + ) { + if ( + typeof matcher !== "object" || + matcher.type !== "Invocation" || + typeof matcher.value !== "object" || + typeof matcher.value.target !== "object" || + matcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "matcher should be a GREYMatcher, but got " + JSON.stringify(matcher) + ); } return { @@ -126,21 +178,29 @@ to be selected. @return An interaction (assertion or an action) to be performed on the element at the specified index in the list of matched elements. -*/static atIndex(element, index) { - if (typeof index !== "number") throw new Error("index should be a number, but got " + (index + (" (" + (typeof index + ")")))); +*/ static atIndex( + element, + index + ) { + if (typeof index !== "number") + throw new Error( + "index should be a number, but got " + + (index + (" (" + (typeof index + ")"))) + ); return { target: { type: "Invocation", value: element }, method: "atIndex:", - args: [{ - type: "NSInteger", - value: index - }] + args: [ + { + type: "NSInteger", + value: index + } + ] }; } - } -module.exports = GREYInteraction; \ No newline at end of file +module.exports = GREYInteraction; diff --git a/detox/src/ios/earlgreyapi/GREYMatchers+Detox.js b/detox/src/ios/earlgreyapi/GREYMatchers+Detox.js index c16692efab..13e9f084db 100644 --- a/detox/src/ios/earlgreyapi/GREYMatchers+Detox.js +++ b/detox/src/ios/earlgreyapi/GREYMatchers+Detox.js @@ -4,42 +4,60 @@ For more information see generation/README.md. */ - - class GREYMatchers { static detoxMatcherForText(text) { - if (typeof text !== "string") throw new Error("text should be a string, but got " + (text + (" (" + (typeof text + ")")))); + if (typeof text !== "string") + throw new Error( + "text should be a string, but got " + + (text + (" (" + (typeof text + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "detoxMatcherForText:", - args: [{ - type: "NSString", - value: text - }] + args: [ + { + type: "NSString", + value: text + } + ] }; } static detox_matcherForAccessibilityLabel(label) { - if (typeof label !== "string") throw new Error("label should be a string, but got " + (label + (" (" + (typeof label + ")")))); + if (typeof label !== "string") + throw new Error( + "label should be a string, but got " + + (label + (" (" + (typeof label + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "detox_matcherForAccessibilityLabel:", - args: [{ - type: "NSString", - value: label - }] + args: [ + { + type: "NSString", + value: label + } + ] }; } static detoxMatcherForScrollChildOfMatcher(matcher) { - if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") { - throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher)); + if ( + typeof matcher !== "object" || + matcher.type !== "Invocation" || + typeof matcher.value !== "object" || + typeof matcher.value.target !== "object" || + matcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "matcher should be a GREYMatcher, but got " + JSON.stringify(matcher) + ); } return { @@ -53,8 +71,16 @@ class GREYMatchers { } static detoxMatcherAvoidingProblematicReactNativeElements(matcher) { - if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") { - throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher)); + if ( + typeof matcher !== "object" || + matcher.type !== "Invocation" || + typeof matcher.value !== "object" || + typeof matcher.value.target !== "object" || + matcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "matcher should be a GREYMatcher, but got " + JSON.stringify(matcher) + ); } return { @@ -68,12 +94,30 @@ class GREYMatchers { } static detoxMatcherForBothAnd(firstMatcher, secondMatcher) { - if (typeof firstMatcher !== "object" || firstMatcher.type !== "Invocation" || typeof firstMatcher.value !== "object" || typeof firstMatcher.value.target !== "object" || firstMatcher.value.target.value !== "GREYMatchers") { - throw new Error('firstMatcher should be a GREYMatcher, but got ' + JSON.stringify(firstMatcher)); + if ( + typeof firstMatcher !== "object" || + firstMatcher.type !== "Invocation" || + typeof firstMatcher.value !== "object" || + typeof firstMatcher.value.target !== "object" || + firstMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "firstMatcher should be a GREYMatcher, but got " + + JSON.stringify(firstMatcher) + ); } - if (typeof secondMatcher !== "object" || secondMatcher.type !== "Invocation" || typeof secondMatcher.value !== "object" || typeof secondMatcher.value.target !== "object" || secondMatcher.value.target.value !== "GREYMatchers") { - throw new Error('secondMatcher should be a GREYMatcher, but got ' + JSON.stringify(secondMatcher)); + if ( + typeof secondMatcher !== "object" || + secondMatcher.type !== "Invocation" || + typeof secondMatcher.value !== "object" || + typeof secondMatcher.value.target !== "object" || + secondMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "secondMatcher should be a GREYMatcher, but got " + + JSON.stringify(secondMatcher) + ); } return { @@ -87,12 +131,30 @@ class GREYMatchers { } static detoxMatcherForBothAndAncestorMatcher(firstMatcher, ancestorMatcher) { - if (typeof firstMatcher !== "object" || firstMatcher.type !== "Invocation" || typeof firstMatcher.value !== "object" || typeof firstMatcher.value.target !== "object" || firstMatcher.value.target.value !== "GREYMatchers") { - throw new Error('firstMatcher should be a GREYMatcher, but got ' + JSON.stringify(firstMatcher)); + if ( + typeof firstMatcher !== "object" || + firstMatcher.type !== "Invocation" || + typeof firstMatcher.value !== "object" || + typeof firstMatcher.value.target !== "object" || + firstMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "firstMatcher should be a GREYMatcher, but got " + + JSON.stringify(firstMatcher) + ); } - if (typeof ancestorMatcher !== "object" || ancestorMatcher.type !== "Invocation" || typeof ancestorMatcher.value !== "object" || typeof ancestorMatcher.value.target !== "object" || ancestorMatcher.value.target.value !== "GREYMatchers") { - throw new Error('ancestorMatcher should be a GREYMatcher, but got ' + JSON.stringify(ancestorMatcher)); + if ( + typeof ancestorMatcher !== "object" || + ancestorMatcher.type !== "Invocation" || + typeof ancestorMatcher.value !== "object" || + typeof ancestorMatcher.value.target !== "object" || + ancestorMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "ancestorMatcher should be a GREYMatcher, but got " + + JSON.stringify(ancestorMatcher) + ); } return { @@ -105,13 +167,34 @@ class GREYMatchers { }; } - static detoxMatcherForBothAndDescendantMatcher(firstMatcher, descendantMatcher) { - if (typeof firstMatcher !== "object" || firstMatcher.type !== "Invocation" || typeof firstMatcher.value !== "object" || typeof firstMatcher.value.target !== "object" || firstMatcher.value.target.value !== "GREYMatchers") { - throw new Error('firstMatcher should be a GREYMatcher, but got ' + JSON.stringify(firstMatcher)); + static detoxMatcherForBothAndDescendantMatcher( + firstMatcher, + descendantMatcher + ) { + if ( + typeof firstMatcher !== "object" || + firstMatcher.type !== "Invocation" || + typeof firstMatcher.value !== "object" || + typeof firstMatcher.value.target !== "object" || + firstMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "firstMatcher should be a GREYMatcher, but got " + + JSON.stringify(firstMatcher) + ); } - if (typeof descendantMatcher !== "object" || descendantMatcher.type !== "Invocation" || typeof descendantMatcher.value !== "object" || typeof descendantMatcher.value.target !== "object" || descendantMatcher.value.target.value !== "GREYMatchers") { - throw new Error('descendantMatcher should be a GREYMatcher, but got ' + JSON.stringify(descendantMatcher)); + if ( + typeof descendantMatcher !== "object" || + descendantMatcher.type !== "Invocation" || + typeof descendantMatcher.value !== "object" || + typeof descendantMatcher.value.target !== "object" || + descendantMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "descendantMatcher should be a GREYMatcher, but got " + + JSON.stringify(descendantMatcher) + ); } return { @@ -125,8 +208,16 @@ class GREYMatchers { } static detoxMatcherForNot(matcher) { - if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") { - throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher)); + if ( + typeof matcher !== "object" || + matcher.type !== "Invocation" || + typeof matcher.value !== "object" || + typeof matcher.value.target !== "object" || + matcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "matcher should be a GREYMatcher, but got " + JSON.stringify(matcher) + ); } return { @@ -140,20 +231,25 @@ class GREYMatchers { } static detoxMatcherForClass(aClassName) { - if (typeof aClassName !== "string") throw new Error("aClassName should be a string, but got " + (aClassName + (" (" + (typeof aClassName + ")")))); + if (typeof aClassName !== "string") + throw new Error( + "aClassName should be a string, but got " + + (aClassName + (" (" + (typeof aClassName + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "detoxMatcherForClass:", - args: [{ - type: "NSString", - value: aClassName - }] + args: [ + { + type: "NSString", + value: aClassName + } + ] }; } - } -module.exports = GREYMatchers; \ No newline at end of file +module.exports = GREYMatchers; diff --git a/detox/src/ios/earlgreyapi/GREYMatchers.js b/detox/src/ios/earlgreyapi/GREYMatchers.js index 3ef6ce8cee..4110904210 100644 --- a/detox/src/ios/earlgreyapi/GREYMatchers.js +++ b/detox/src/ios/earlgreyapi/GREYMatchers.js @@ -4,92 +4,91 @@ For more information see generation/README.md. */ - function sanitize_uiAccessibilityTraits(value) { - let traits = 0; - for (let i = 0; i < value.length; i++) { - switch (value[i]) { - case "button": - traits |= 1; - break; - case "link": - traits |= 2; - break; - case "header": - traits |= 4; - break; - case "search": - traits |= 8; - break; - case "image": - traits |= 16; - break; - case "selected": - traits |= 32; - break; - case "plays": - traits |= 64; - break; - case "key": - traits |= 128; - break; - case "text": - traits |= 256; - break; - case "summary": - traits |= 512; - break; - case "disabled": - traits |= 1024; - break; - case "frequentUpdates": - traits |= 2048; - break; - case "startsMedia": - traits |= 4096; - break; - case "adjustable": - traits |= 8192; - break; - case "allowsDirectInteraction": - traits |= 16384; - break; - case "pageTurn": - traits |= 32768; - break; - default: - throw new Error( - `Unknown trait '${ - value[i] - }', see list in https://facebook.github.io/react-native/docs/accessibility.html#accessibilitytraits-ios` - ); - } - } - - return traits; -} + let traits = 0; + for (let i = 0; i < value.length; i++) { + switch (value[i]) { + case "button": + traits |= 1; + break; + case "link": + traits |= 2; + break; + case "header": + traits |= 4; + break; + case "search": + traits |= 8; + break; + case "image": + traits |= 16; + break; + case "selected": + traits |= 32; + break; + case "plays": + traits |= 64; + break; + case "key": + traits |= 128; + break; + case "text": + traits |= 256; + break; + case "summary": + traits |= 512; + break; + case "disabled": + traits |= 1024; + break; + case "frequentUpdates": + traits |= 2048; + break; + case "startsMedia": + traits |= 4096; + break; + case "adjustable": + traits |= 8192; + break; + case "allowsDirectInteraction": + traits |= 16384; + break; + case "pageTurn": + traits |= 32768; + break; + default: + throw new Error( + `Unknown trait '${ + value[i] + }', see list in https://facebook.github.io/react-native/docs/accessibility.html#accessibilitytraits-ios` + ); + } + } + + return traits; +} function sanitize_greyContentEdge(action) { - switch (action) { - case "left": - return 0; - case "right": - return 1; - case "top": - return 2; - case "bottom": - return 3; - - default: - throw new Error( - `GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}` - ); - } -} + switch (action) { + case "left": + return 0; + case "right": + return 1; + case "top": + return 2; + case "bottom": + return 3; + + default: + throw new Error( + `GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}` + ); + } +} class GREYMatchers { /*Matcher for application's key window. @return A matcher for the application's key window. -*/static matcherForKeyWindow() { +*/ static matcherForKeyWindow() { return { target: { type: "Class", @@ -105,18 +104,26 @@ class GREYMatchers { @param label The accessibility label to be matched. @return A matcher for the accessibility label of an accessible element. -*/static matcherForAccessibilityLabel(label) { - if (typeof label !== "string") throw new Error("label should be a string, but got " + (label + (" (" + (typeof label + ")")))); +*/ static matcherForAccessibilityLabel( + label + ) { + if (typeof label !== "string") + throw new Error( + "label should be a string, but got " + + (label + (" (" + (typeof label + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForAccessibilityLabel:", - args: [{ - type: "NSString", - value: label - }] + args: [ + { + type: "NSString", + value: label + } + ] }; } @@ -125,18 +132,26 @@ class GREYMatchers { @param accessibilityID The accessibility ID to be matched. @return A matcher for the accessibility ID of an accessible element. -*/static matcherForAccessibilityID(accessibilityID) { - if (typeof accessibilityID !== "string") throw new Error("accessibilityID should be a string, but got " + (accessibilityID + (" (" + (typeof accessibilityID + ")")))); +*/ static matcherForAccessibilityID( + accessibilityID + ) { + if (typeof accessibilityID !== "string") + throw new Error( + "accessibilityID should be a string, but got " + + (accessibilityID + (" (" + (typeof accessibilityID + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForAccessibilityID:", - args: [{ - type: "NSString", - value: accessibilityID - }] + args: [ + { + type: "NSString", + value: accessibilityID + } + ] }; } @@ -145,18 +160,26 @@ class GREYMatchers { @param value The accessibility value to be matched. @return A matcher for the accessibility value of an accessible element. -*/static matcherForAccessibilityValue(value) { - if (typeof value !== "string") throw new Error("value should be a string, but got " + (value + (" (" + (typeof value + ")")))); +*/ static matcherForAccessibilityValue( + value + ) { + if (typeof value !== "string") + throw new Error( + "value should be a string, but got " + + (value + (" (" + (typeof value + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForAccessibilityValue:", - args: [{ - type: "NSString", - value: value - }] + args: [ + { + type: "NSString", + value: value + } + ] }; } @@ -166,9 +189,11 @@ class GREYMatchers { @return A matcher for the accessibility traits of an accessible element. -*/static matcherForAccessibilityTraits(traits) { - if (typeof traits !== 'object' || !traits instanceof Array) { - throw new Error('traits must be an array, got ' + typeof traits); +*/ static matcherForAccessibilityTraits( + traits + ) { + if (typeof traits !== "object" || !traits instanceof Array) { + throw new Error("traits must be an array, got " + typeof traits); } return { @@ -177,10 +202,12 @@ class GREYMatchers { value: "GREYMatchers" }, method: "matcherForAccessibilityTraits:", - args: [{ - type: "NSInteger", - value: sanitize_uiAccessibilityTraits(traits) - }] + args: [ + { + type: "NSInteger", + value: sanitize_uiAccessibilityTraits(traits) + } + ] }; } @@ -189,25 +216,33 @@ class GREYMatchers { @param hint The accessibility hint to be matched. @return A matcher for the accessibility hint of an accessible element. -*/static matcherForAccessibilityHint(hint) { - if (typeof hint !== "string") throw new Error("hint should be a string, but got " + (hint + (" (" + (typeof hint + ")")))); +*/ static matcherForAccessibilityHint( + hint + ) { + if (typeof hint !== "string") + throw new Error( + "hint should be a string, but got " + + (hint + (" (" + (typeof hint + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForAccessibilityHint:", - args: [{ - type: "NSString", - value: hint - }] + args: [ + { + type: "NSString", + value: hint + } + ] }; } /*Matcher for UI element with accessiblity focus. @return A matcher for the accessibility focus of an accessible element. -*/static matcherForAccessibilityElementIsFocused() { +*/ static matcherForAccessibilityElementIsFocused() { return { target: { type: "Class", @@ -224,25 +259,33 @@ provided @c inputText. @param text The text to be matched in the UI elements. @return A matcher to check for any UI elements with a text field containing the given text. -*/static matcherForText(text) { - if (typeof text !== "string") throw new Error("text should be a string, but got " + (text + (" (" + (typeof text + ")")))); +*/ static matcherForText( + text + ) { + if (typeof text !== "string") + throw new Error( + "text should be a string, but got " + + (text + (" (" + (typeof text + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForText:", - args: [{ - type: "NSString", - value: text - }] + args: [ + { + type: "NSString", + value: text + } + ] }; } /*Matcher for element that is the first responder. @return A matcher that verifies if a UI element is the first responder. -*/static matcherForFirstResponder() { +*/ static matcherForFirstResponder() { return { target: { type: "Class", @@ -256,7 +299,7 @@ provided @c inputText. /*Matcher to check if system alert view is shown. @return A matcher to check if a system alert view is being shown. -*/static matcherForSystemAlertViewShown() { +*/ static matcherForSystemAlertViewShown() { return { target: { type: "Class", @@ -275,18 +318,26 @@ Allowed values for @c percent are [0,1] inclusive. @return A matcher that checks if a UI element has a visible area at least equal to a minimum value. -*/static matcherForMinimumVisiblePercent(percent) { - if (typeof percent !== "number") throw new Error("percent should be a number, but got " + (percent + (" (" + (typeof percent + ")")))); +*/ static matcherForMinimumVisiblePercent( + percent + ) { + if (typeof percent !== "number") + throw new Error( + "percent should be a number, but got " + + (percent + (" (" + (typeof percent + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForMinimumVisiblePercent:", - args: [{ - type: "CGFloat", - value: percent - }] + args: [ + { + type: "CGFloat", + value: percent + } + ] }; } @@ -296,7 +347,7 @@ sufficiently visible. @return A matcher intialized with a visibility percentage that confirms an element is sufficiently visible. -*/static matcherForSufficientlyVisible() { +*/ static matcherForSufficientlyVisible() { return { target: { type: "Class", @@ -310,7 +361,7 @@ sufficiently visible. /*Matcher for UI element that is not visible to the user at all i.e. it has a zero visible area. @return A matcher for verifying if an element is not visible. -*/static matcherForNotVisible() { +*/ static matcherForNotVisible() { return { target: { type: "Class", @@ -328,7 +379,7 @@ satisfy at least the following criteria: is completely visible. @return A matcher that checks if a UI element is interactable. -*/static matcherForInteractable() { +*/ static matcherForInteractable() { return { target: { type: "Class", @@ -342,7 +393,7 @@ is completely visible. /*Matcher to check if a UI element is accessible. @return A matcher that checks if a UI element is accessible. -*/static matcherForAccessibilityElement() { +*/ static matcherForAccessibilityElement() { return { target: { type: "Class", @@ -362,9 +413,20 @@ unimplemented matcher is required, please implement it similar to @c grey_closeT @param comparisonMatcher The matcher with the value to check the progress against. @return A matcher for checking a UIProgessView's value. -*/static matcherForProgress(comparisonMatcher) { - if (typeof comparisonMatcher !== "object" || comparisonMatcher.type !== "Invocation" || typeof comparisonMatcher.value !== "object" || typeof comparisonMatcher.value.target !== "object" || comparisonMatcher.value.target.value !== "GREYMatchers") { - throw new Error('comparisonMatcher should be a GREYMatcher, but got ' + JSON.stringify(comparisonMatcher)); +*/ static matcherForProgress( + comparisonMatcher + ) { + if ( + typeof comparisonMatcher !== "object" || + comparisonMatcher.type !== "Invocation" || + typeof comparisonMatcher.value !== "object" || + typeof comparisonMatcher.value.target !== "object" || + comparisonMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "comparisonMatcher should be a GREYMatcher, but got " + + JSON.stringify(comparisonMatcher) + ); } return { @@ -383,9 +445,20 @@ The given matcher is used to match decendants. @param ancestorMatcher The ancestor UI element whose descendants are to be matched. @return A matcher to check if a UI element is the descendant of another. -*/static matcherForAncestor(ancestorMatcher) { - if (typeof ancestorMatcher !== "object" || ancestorMatcher.type !== "Invocation" || typeof ancestorMatcher.value !== "object" || typeof ancestorMatcher.value.target !== "object" || ancestorMatcher.value.target.value !== "GREYMatchers") { - throw new Error('ancestorMatcher should be a GREYMatcher, but got ' + JSON.stringify(ancestorMatcher)); +*/ static matcherForAncestor( + ancestorMatcher + ) { + if ( + typeof ancestorMatcher !== "object" || + ancestorMatcher.type !== "Invocation" || + typeof ancestorMatcher.value !== "object" || + typeof ancestorMatcher.value.target !== "object" || + ancestorMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "ancestorMatcher should be a GREYMatcher, but got " + + JSON.stringify(ancestorMatcher) + ); } return { @@ -404,9 +477,20 @@ The given matcher is used to match decendants. of the UI element being checked. @return A matcher to check if a the specified element is in a descendant of another UI element. -*/static matcherForDescendant(descendantMatcher) { - if (typeof descendantMatcher !== "object" || descendantMatcher.type !== "Invocation" || typeof descendantMatcher.value !== "object" || typeof descendantMatcher.value.target !== "object" || descendantMatcher.value.target.value !== "GREYMatchers") { - throw new Error('descendantMatcher should be a GREYMatcher, but got ' + JSON.stringify(descendantMatcher)); +*/ static matcherForDescendant( + descendantMatcher + ) { + if ( + typeof descendantMatcher !== "object" || + descendantMatcher.type !== "Invocation" || + typeof descendantMatcher.value !== "object" || + typeof descendantMatcher.value.target !== "object" || + descendantMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "descendantMatcher should be a GREYMatcher, but got " + + JSON.stringify(descendantMatcher) + ); } return { @@ -424,18 +508,26 @@ of the UI element being checked. @param title The title to be checked on the UIButtons being matched. @return A matcher to confirm UIButton titles. -*/static matcherForButtonTitle(title) { - if (typeof title !== "string") throw new Error("title should be a string, but got " + (title + (" (" + (typeof title + ")")))); +*/ static matcherForButtonTitle( + title + ) { + if (typeof title !== "string") + throw new Error( + "title should be a string, but got " + + (title + (" (" + (typeof title + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForButtonTitle:", - args: [{ - type: "NSString", - value: title - }] + args: [ + { + type: "NSString", + value: title + } + ] }; } @@ -445,20 +537,36 @@ of the UI element being checked. matched. @return A matcher to confirm UIScrollView content offset. -*/static matcherForScrollViewContentOffset(offset) { - if (typeof offset !== "object") throw new Error("offset should be a object, but got " + (offset + (" (" + (typeof offset + ")")))); - if (typeof offset.x !== "number") throw new Error("offset.x should be a number, but got " + (offset.x + (" (" + (typeof offset.x + ")")))); - if (typeof offset.y !== "number") throw new Error("offset.y should be a number, but got " + (offset.y + (" (" + (typeof offset.y + ")")))); +*/ static matcherForScrollViewContentOffset( + offset + ) { + if (typeof offset !== "object") + throw new Error( + "offset should be a object, but got " + + (offset + (" (" + (typeof offset + ")"))) + ); + if (typeof offset.x !== "number") + throw new Error( + "offset.x should be a number, but got " + + (offset.x + (" (" + (typeof offset.x + ")"))) + ); + if (typeof offset.y !== "number") + throw new Error( + "offset.y should be a number, but got " + + (offset.y + (" (" + (typeof offset.y + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForScrollViewContentOffset:", - args: [{ - type: "CGPoint", - value: offset - }] + args: [ + { + type: "CGPoint", + value: offset + } + ] }; } @@ -474,9 +582,20 @@ floating point value. If you are using @c grey_closeTo, use delta diff as is required, please implement it similar to @c grey_closeTo. @return A matcher for checking a UISlider's value. -*/static matcherForSliderValueMatcher(valueMatcher) { - if (typeof valueMatcher !== "object" || valueMatcher.type !== "Invocation" || typeof valueMatcher.value !== "object" || typeof valueMatcher.value.target !== "object" || valueMatcher.value.target.value !== "GREYMatchers") { - throw new Error('valueMatcher should be a GREYMatcher, but got ' + JSON.stringify(valueMatcher)); +*/ static matcherForSliderValueMatcher( + valueMatcher + ) { + if ( + typeof valueMatcher !== "object" || + valueMatcher.type !== "Invocation" || + typeof valueMatcher.value !== "object" || + typeof valueMatcher.value.target !== "object" || + valueMatcher.value.target.value !== "GREYMatchers" + ) { + throw new Error( + "valueMatcher should be a GREYMatcher, but got " + + JSON.stringify(valueMatcher) + ); } return { @@ -495,29 +614,43 @@ is required, please implement it similar to @c grey_closeTo. @param value The value that should be set in the column of the UIPickerView. @return A matcher to check the value in a particular column of a UIPickerView. -*/static matcherForPickerColumnSetToValue(column, value) { - if (typeof column !== "number") throw new Error("column should be a number, but got " + (column + (" (" + (typeof column + ")")))); - if (typeof value !== "string") throw new Error("value should be a string, but got " + (value + (" (" + (typeof value + ")")))); +*/ static matcherForPickerColumnSetToValue( + column, + value + ) { + if (typeof column !== "number") + throw new Error( + "column should be a number, but got " + + (column + (" (" + (typeof column + ")"))) + ); + if (typeof value !== "string") + throw new Error( + "value should be a string, but got " + + (value + (" (" + (typeof value + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForPickerColumn:setToValue:", - args: [{ - type: "NSInteger", - value: column - }, { - type: "NSString", - value: value - }] + args: [ + { + type: "NSInteger", + value: column + }, + { + type: "NSString", + value: value + } + ] }; } /*Matcher that verifies whether an element, that is a UIControl, is enabled. @return A matcher for checking whether a UI element is an enabled UIControl. -*/static matcherForEnabledElement() { +*/ static matcherForEnabledElement() { return { target: { type: "Class", @@ -531,7 +664,7 @@ is required, please implement it similar to @c grey_closeTo. /*Matcher that verifies whether an element, that is a UIControl, is selected. @return A matcher for checking whether a UI element is a selected UIControl. -*/static matcherForSelectedElement() { +*/ static matcherForSelectedElement() { return { target: { type: "Class", @@ -545,7 +678,7 @@ is required, please implement it similar to @c grey_closeTo. /*Matcher that verifies whether a view has its userInteractionEnabled property set to @c YES. @return A matcher for checking whether a view' userInteractionEnabled property is set to @c YES. -*/static matcherForUserInteractionEnabled() { +*/ static matcherForUserInteractionEnabled() { return { target: { type: "Class", @@ -559,7 +692,7 @@ is required, please implement it similar to @c grey_closeTo. /*Matcher primarily for asserting that the element is @c nil or not found. @return A matcher to check if a specified element is @c nil or not found. -*/static matcherForNil() { +*/ static matcherForNil() { return { target: { type: "Class", @@ -573,7 +706,7 @@ is required, please implement it similar to @c grey_closeTo. /*Matcher for asserting that the element exists in the UI hierarchy (i.e. not @c nil). @return A matcher to check if a specified element is not @c nil. -*/static matcherForNotNil() { +*/ static matcherForNotNil() { return { target: { type: "Class", @@ -587,7 +720,7 @@ is required, please implement it similar to @c grey_closeTo. /*A Matcher that matches against any object, including @c nils. @return A matcher that matches any object. -*/static matcherForAnything() { +*/ static matcherForAnything() { return { target: { type: "Class", @@ -603,18 +736,25 @@ is required, please implement it similar to @c grey_closeTo. @param edge The content edge UIScrollView should be scrolled to. @return A matcher that matches a UIScrollView scrolled to content @c edge. -*/static matcherForScrolledToContentEdge(edge) { - if (!["left", "right", "top", "bottom"].some(option => option === edge)) throw new Error("edge should be one of [left, right, top, bottom], but got " + edge); +*/ static matcherForScrolledToContentEdge( + edge + ) { + if (!["left", "right", "top", "bottom"].some(option => option === edge)) + throw new Error( + "edge should be one of [left, right, top, bottom], but got " + edge + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForScrolledToContentEdge:", - args: [{ - type: "NSInteger", - value: sanitize_greyContentEdge(edge) - }] + args: [ + { + type: "NSInteger", + value: sanitize_greyContentEdge(edge) + } + ] }; } @@ -623,21 +763,28 @@ is required, please implement it similar to @c grey_closeTo. @param value The text string contained inside the UITextField. @return A matcher that matches the value inside a UITextField. -*/static matcherForTextFieldValue(value) { - if (typeof value !== "string") throw new Error("value should be a string, but got " + (value + (" (" + (typeof value + ")")))); +*/ static matcherForTextFieldValue( + value + ) { + if (typeof value !== "string") + throw new Error( + "value should be a string, but got " + + (value + (" (" + (typeof value + ")"))) + ); return { target: { type: "Class", value: "GREYMatchers" }, method: "matcherForTextFieldValue:", - args: [{ - type: "NSString", - value: value - }] + args: [ + { + type: "NSString", + value: value + } + ] }; } - } -module.exports = GREYMatchers; \ No newline at end of file +module.exports = GREYMatchers; diff --git a/generation/index.js b/generation/index.js index 7d63cde610..21ea38ac50 100755 --- a/generation/index.js +++ b/generation/index.js @@ -1,4 +1,7 @@ #!/usr/bin/env node +const prettier = require("prettier"); +const fs = require("fs"); + const generateIOSAdapters = require("./adapters/ios"); const iosFiles = { "../detox/ios/EarlGrey/EarlGrey/Action/GREYActions.h": @@ -40,3 +43,14 @@ const androidFiles = { "../detox/src/android/espressoapi/DetoxMatcher.js" }; generateAndroidAdapters(androidFiles); + + +// Run prettier over the generated files +const allFiles = [...Object.values(iosFiles), ...Object.values(androidFiles)]; + +allFiles.forEach(file => { + const text = fs.readFileSync(file, "utf8"); + const formatted = prettier.format(text); + fs.writeFileSync(file, formatted); +}); +