forked from wix/Detox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Android) Friendly-fail test runner is app crashes on launch
- Loading branch information
Showing
13 changed files
with
280 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const INSTRUMENTATION_LOGS_PREFIX = 'INSTRUMENTATION_STATUS'; | ||
const STACKTRACE_PREFIX_TEXT = INSTRUMENTATION_LOGS_PREFIX + ': stack='; | ||
|
||
class InstrumentationLogsParser { | ||
hasStackTraceLog(logsDump) { | ||
return logsDump.includes(STACKTRACE_PREFIX_TEXT); | ||
} | ||
|
||
getStackTrace(logsDump) { | ||
const logLines = logsDump.split('\n'); | ||
|
||
const index = this._findStackTraceLog(logLines); | ||
const stackTrace = this._extractStackTrace(logLines, index); | ||
return stackTrace; | ||
} | ||
|
||
_findStackTraceLog(logLines) { | ||
let i; | ||
for (i = 0; i < logLines.length && !logLines[i].includes(STACKTRACE_PREFIX_TEXT); i++) {} | ||
return i; | ||
} | ||
|
||
_extractStackTrace(logLines, i) { | ||
if (i < logLines.length) { | ||
logLines[i] = logLines[i].replace(STACKTRACE_PREFIX_TEXT, ''); | ||
} | ||
|
||
let stackTrace = ''; | ||
for ( | ||
; i < logLines.length | ||
&& logLines[i].trim() | ||
&& !logLines[i].includes(INSTRUMENTATION_LOGS_PREFIX) | ||
; i++) { | ||
stackTrace = stackTrace.concat(logLines[i], '\n'); | ||
} | ||
return stackTrace; | ||
} | ||
} | ||
|
||
module.exports = { | ||
InstrumentationLogsParser | ||
}; |
48 changes: 48 additions & 0 deletions
48
detox/src/devices/drivers/InstrumentationLogsParser.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
describe('Instrumentation logs parser', () => { | ||
describe('stack trace parser', () => { | ||
let uut; | ||
beforeEach(() => { | ||
const { InstrumentationLogsParser } = require('./InstrumentationLogsParser'); | ||
uut = new InstrumentationLogsParser(); | ||
}); | ||
|
||
it('should query stacktrace for false for a no-string', () => { | ||
const logsDump = ''; | ||
expect(uut.hasStackTraceLog(logsDump)).toEqual(false); | ||
}); | ||
|
||
it('should query stacktrace for true for a log matching the stacktrace prefix', () => { | ||
const logsDump = 'INSTRUMENTATION_STATUS: stack='; | ||
expect(uut.hasStackTraceLog(logsDump)).toEqual(true); | ||
}); | ||
|
||
it('should query stacktrack for true for a log that holds the stacktrace prefix alongside other stuff', () => { | ||
const logsDump = [ | ||
'INSTRUMENTATION_STATUS: stream=\ncom.example.DetoxTest', | ||
'INSTRUMENTATION_STATUS: stack=stackFrame1\n stackFrame2', | ||
'INSTRUMENTATION_STATUS: id=AndroidJUnitRunner', | ||
].join('\n'); | ||
expect(uut.hasStackTraceLog(logsDump)).toEqual(true); | ||
}); | ||
|
||
it('should return empty stacktrace for a no-string', () => { | ||
const logsDump = ''; | ||
expect(uut.getStackTrace(logsDump)).toEqual(''); | ||
}); | ||
|
||
it('should return stacktrace for a stack-trace logs dump', () => { | ||
const logsDump = 'INSTRUMENTATION_STATUS: stack=stackFrame1\n stackFrame2\n'; | ||
expect(uut.getStackTrace(logsDump)).toEqual('stackFrame1\n stackFrame2\n'); | ||
}); | ||
|
||
it('should return stacktrace for a multi-content logs dump', () => { | ||
const logsDump = [ | ||
'INSTRUMENTATION_STATUS: stream=\ncom.example.DetoxTest', | ||
'INSTRUMENTATION_STATUS: stack=stackFrame1\n stackFrame2', | ||
'INSTRUMENTATION_STATUS_CODE: 1', | ||
'INSTRUMENTATION_STATUS: id=AndroidJUnitRunner', | ||
].join('\n'); | ||
expect(uut.getStackTrace(logsDump)).toEqual('stackFrame1\n stackFrame2\n'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.