question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I produce coverage data with this tool?

See original GitHub issue

Description

Thanks for creating this library - very useful. I cannot understand how should I invoke coverage. Currently running test with detox: npx detox test --configuration ios.debug

What should I do in order to create the coverage for the tests Im running?

Your environment

Detox version: 19.7.1 React Native version: 0.68.0 Node version: 14.x Device model: OS: Test-runner (select one): jest / other

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mikehardycommented, Nov 16, 2022

@chenop there are two types of possible coverage, native code or javascript code coverage

I don’t know how to do native code coverage for iOS (I have tried, but could not get the coverage files to dump 🤷 ) but, for android, you can do this to get native code coverage dumped:

https://github.com/invertase/react-native-firebase/blob/baea413c0a81f75d99d947ba0607737853ad08f4/tests/android/app/src/androidTest/java/com/invertase/testing/DetoxTest.java#L32-L53

That’s useful for module authors that develop native code and need to check things.

For javascript code coverage (most people), you need to instrument the bundle first in a pre-build step, then as the last part of your test, you need to have some logic that you trigger at the javascript level that persists the coverage data (which will be in global variable globals.coverage I think?) to a file on the android emulator file system

Then you may fetch the dumped javascript coverage data file by using adb pull command

There are an infinite number of ways to do it but the same three steps will always apply: 1- instrument the code prior to execution, 2- dump the coverage data post-execution 3- locate/transfer/process the dumped coverage data somehow

1reaction
noomorphcommented, Nov 15, 2022

This is a very untrivial task. You’d need to add source code transformations with Istanbul to the Metro bundler and then extract the test coverage from the inside (e.g., sending to a localhost server for aggregating LCOV reports).

This is technically possible but requires a skilled developer to hack a solution.

Maybe React Native has better solutions, e.g., using built-in V8 code coverage, but I’m unaware of such ones now.

Detox cannot help you gather coverage from your bundled React Native code. This is out of the scope of this project. At least currently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a new coverage—ArcMap | Documentation
A new coverage can be created by using another coverage as a template. Use the Feature Class To Coverage tool to create a...
Read more >
Save coverage data to a file | IntelliJ IDEA Documentation
From the main menu, select Run | Generate Coverage Report, or click the Generate Coverage Report button in the Coverage tool window.
Read more >
How the coverage tool works
The IDE's code coverage tool works in conjunction with the compiler (gcc), the QNX C library (libc), and optionally the remote target agent...
Read more >
Code coverage testing - Visual Studio (Windows)
You can also run code coverage from the Test Explorer tool window. After the tests have run, to see which lines have been...
Read more >
Debug Tool Code Coverage - IBM
Batch facilities are provided so that collection of the code coverage data, using selection criteria to create extracted observations, and report creation can ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found