Skip to content

Commit fbab915

Browse files
committed
test(detox): cleanly close the test session, fetch coverage file
prior to this the app was never requested to close, so the Activity hung until killed, with no control given to the app and no ability to finish up (or dump coverage) after the run we need to fetch the native coverage file for further processing
1 parent 6ef437c commit fbab915

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/e2e/init.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
require('./globals');
1919

2020
const detox = require('detox');
21+
const { execSync } = require('child_process');
2122
const jet = require('jet/platform/node');
2223

2324
const { detox: config } = require('../package.json');
@@ -51,5 +52,29 @@ beforeEach(async function beforeEach() {
5152

5253
after(async function () {
5354
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+
5479
await device.terminateApp();
5580
});

0 commit comments

Comments
 (0)