aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/InternalModuleRegistry.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-08-06 06:30:23 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-06 06:30:23 -0700
commit14624454196370e08309d4f0b0463b494e4df9ca (patch)
tree538421bfffc3d804807a4ec70a1323fbcbe3416f /src/bun.js/bindings/InternalModuleRegistry.cpp
parentecdf2ffa6c615d8a431c2919c0b9bdc4cbe2c4f0 (diff)
downloadbun-14624454196370e08309d4f0b0463b494e4df9ca.tar.gz
bun-14624454196370e08309d4f0b0463b494e4df9ca.tar.zst
bun-14624454196370e08309d4f0b0463b494e4df9ca.zip
Code coverage for `bun test` (#3975)
* WIP code coverage initial commit * almost works * one approach * Code Coverage * Update WebKit * it works but is not yet accurate * skip double ascii check * wrapper * it works but i'm not sure what to do about blocks * hide blocks for now * Update ZigSourceProvider.cpp * Create coverage.md * Update nav.ts --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/InternalModuleRegistry.cpp')
-rw-r--r--src/bun.js/bindings/InternalModuleRegistry.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/bun.js/bindings/InternalModuleRegistry.cpp b/src/bun.js/bindings/InternalModuleRegistry.cpp
index e6b574d7b..841360502 100644
--- a/src/bun.js/bindings/InternalModuleRegistry.cpp
+++ b/src/bun.js/bindings/InternalModuleRegistry.cpp
@@ -12,6 +12,20 @@
namespace Bun {
+extern "C" bool BunTest__shouldGenerateCodeCoverage(BunString sourceURL);
+extern "C" void ByteRangeMapping__generate(BunString sourceURL, BunString code, int sourceID);
+
+static void maybeAddCodeCoverage(JSC::VM& vm, const JSC::SourceCode& code)
+{
+#ifdef BUN_DEBUG
+ bool isCodeCoverageEnabled = !!vm.controlFlowProfiler();
+ bool shouldGenerateCodeCoverage = isCodeCoverageEnabled && BunTest__shouldGenerateCodeCoverage(Bun::toString(code.provider()->sourceURL()));
+ if (shouldGenerateCodeCoverage) {
+ ByteRangeMapping__generate(Bun::toString(code.provider()->sourceURL()), Bun::toString(code.provider()->source().toStringWithoutCopying()), code.provider()->asID());
+ }
+#endif
+}
+
// The `INTERNAL_MODULE_REGISTRY_GENERATE` macro handles inlining code to compile and run a
// JS builtin that acts as a module. In debug mode, we use a different implementation that reads
// from the developer's filesystem. This allows reloading code without recompiling bindings.
@@ -20,7 +34,7 @@ namespace Bun {
auto throwScope = DECLARE_THROW_SCOPE(vm); \
auto&& origin = SourceOrigin(WTF::URL(makeString("builtin://"_s, moduleName))); \
SourceCode source = JSC::makeSource(SOURCE, origin, moduleName); \
- \
+ maybeAddCodeCoverage(vm, source); \
JSFunction* func \
= JSFunction::create( \
vm, \