Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hacky script to process Detox failure output
if (process.argv.length !== 3) {
console.error("Expects exactly one argument");
return;
}
const path = process.argv[2];
console.log(path + "\n");
const lineReader = require('readline').createInterface({
input: require('fs').createReadStream(path)
});
lineReader.on('line', function (line) {
const prefix = line.substr(0, line.indexOf("<")); // indentation
if (!prefix) return;
const element = line.substr(line.indexOf("<") + 1, line.indexOf(":") - line.indexOf("<") - 1); // e.g., RCTView
const label = getAttributeValue(line, "AX.label"); // text, if available
const id = getAttributeValue(line, "AX.id"); // testID prop, if provided
console.log(`${prefix} <${element}> \t\t ${label ? label : ""} ${id ? `[ID=${id}]` : ""}`);
});
const getAttributeValue = (line, attr) => {
// attr='value' ---> returns value
const index = line.indexOf(attr + "='");
if (index === -1) return "";
const l = line.substr(index + attr.length + 2);
return l.substr(0, l.indexOf("'"));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.