You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deno currently supports collecting raw V8 coverage data through the --coverage flag, which is fantastic.
As a result, we have the opportunity to use third-party tools to directly convert from raw V8 coverage data and generate various other coverage reports, not just the lcov and simple html provided by the official.
With raw V8 coverage data, more types of common coverage reports, such as V8 coverage reports, can be generated directly, and custom coverage reports are also supported.
With raw V8 coverage data, it can be merged with other V8 coverage reports, such as e2e test (Playwright/Puppeteer) coverage, and even Node.js (Jest V8 provider) or Istanbul (v8-to-istanbul) coverage.
The problem
However, Deno's V8 coverage data does not include transpiled code and sourcemap, or we can not get the transpiled code and sourcemap for these V8 coverage data.
The startOffset and endOffset in the coverage data are matched to the position of the transpiled code. Without the transpiled code, the position cannot be matched.
Without a sourcemap, the position of the original code cannot be found.
For example, after providing the transpiled code and sourcemap, the coverage json could be following
{"scriptId": "310","url": "file:///E:/workspace/deno-coverage-reports/src/main.ts","source": "<the transpiled source code>","sourceMap": "<the sourcemap for the transpiled source code>","functions": [
...
]}
Expectation
In fact, the transpiled code and sourcemap should be separated because multiple coverage data may exist for the same file. For example, we expect to get the coverage files like following:
-coverage// coverage dir-coverage-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json// coverage data 1 for source file 1-coverage-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json// coverage data 2 for source file 1-coverage-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json// coverage data 3 for source file 2-source-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json// source file 1, include transpiled code and sourcemap -source-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json// source file 2, include transpiled code and sourcemap
// coverage-report.jsimportMCRfrom"npm:monocart-coverage-reports@latest";import{fileURLToPath}from"node:url";constmcr=MCR({//logging: "debug",name: "My Deno Coverage Report",outputDir: "./coverage-reports/",reports: ["v8","console-details"],});constcoverageList=[];constcoverageDataDir="coverage";for(constdirEntryofDeno.readDirSync(coverageDataDir)){constdata=Deno.readTextFileSync(`${coverageDataDir}/${dirEntry.name}`);constfileCoverage=JSON.parse(data);if(fileCoverage.url.startsWith("file://")){constsource=Deno.readTextFileSync(fileURLToPath(fileCoverage.url));// NOTE: It requires transpiled source code and sourcemap. Unfortunately, Deno doesn't provide.// The source is original code not transpiled code.// Because of the offset in coverage is mapping to transpiled code. So, the source is wrong here.fileCoverage.source=source;coverageList.push(fileCoverage);}}awaitmcr.add(coverageList);awaitmcr.generate();
CLI
deno run --allow-env --allow-read --allow-sys --allow-write tasks/coverage-report.js
Deno currently supports collecting raw V8 coverage data through the
--coverage
flag, which is fantastic.As a result, we have the opportunity to use third-party tools to directly convert from raw V8 coverage data and generate various other coverage reports, not just the
lcov
and simplehtml
provided by the official.The problem
However, Deno's V8 coverage data does not include transpiled code and sourcemap, or we can not get the transpiled code and sourcemap for these V8 coverage data.
startOffset
andendOffset
in the coverage data are matched to the position of the transpiled code. Without the transpiled code, the position cannot be matched.For example, after providing the transpiled code and sourcemap, the coverage json could be following
Expectation
In fact, the transpiled code and sourcemap should be separated because multiple coverage data may exist for the same file. For example, we expect to get the coverage files like following:
Attempt
I tried to use the tool MCR to generate native V8 coverage reports from Deno's coverage data, but due to the above problem, it was unsuccessful. For details, refer to the repo:
https://github.com/cenfun/deno-coverage-reports
CLI
Related issues
#21325
#18147
#21582
#20007
#16626
The text was updated successfully, but these errors were encountered: