|
18 | 18 | require('./globals');
|
19 | 19 |
|
20 | 20 | const detox = require('detox');
|
| 21 | +const { execSync } = require('child_process'); |
21 | 22 | const jet = require('jet/platform/node');
|
22 | 23 |
|
23 | 24 | const { detox: config } = require('../package.json');
|
@@ -51,5 +52,29 @@ beforeEach(async function beforeEach() {
|
51 | 52 |
|
52 | 53 | after(async function () {
|
53 | 54 | console.log(' ✨ Tests Complete ✨ ');
|
| 55 | + const isAndroid = detox.device.getPlatform() === 'android'; |
| 56 | + |
| 57 | + // emits 'cleanup' across socket, which goes native, terminates Detox test Looper |
| 58 | + // This returns control to the java code in our instrumented test, and then Instrumentation lifecycle finishes cleanly |
| 59 | + await detox.cleanup(); |
| 60 | + |
| 61 | + // Get the file off the device, into standard location for JaCoCo binary report |
| 62 | + // It will still need processing via gradle jacocoAndroidTestReport task for codecov, but it's available now |
| 63 | + if (isAndroid) { |
| 64 | + const pkg = 'com.invertase.testing'; |
| 65 | + const emuOrig = `/data/data/${pkg}/files/coverage.ec`; |
| 66 | + const emuDest = '/data/local/tmp/detox/coverage.ec'; |
| 67 | + const localDestDir = './android/app/build/output/coverage/'; |
| 68 | + |
| 69 | + try { |
| 70 | + execSync(`adb shell "run-as ${pkg} cat ${emuOrig} > ${emuDest}"`); |
| 71 | + execSync(`mkdir -p ${localDestDir}`); |
| 72 | + execSync(`adb pull ${emuDest} ${localDestDir}/emulator_coverage.ec`); |
| 73 | + console.log(`Coverage data downloaded to: ${localDestDir}/emulator_coverage.ec`); |
| 74 | + } catch (e) { |
| 75 | + console.log('Unable to download coverage data from device: ', e); |
| 76 | + } |
| 77 | + } |
| 78 | + |
54 | 79 | await device.terminateApp();
|
55 | 80 | });
|
0 commit comments