Replies: 4 comments 4 replies
-
yes, jslint-org/jslint's ci generates coverage-reports using only nodejs with no dependencies. cwd = process.cwd().replace((
/\\/g
), "/") + "/";
await Promise.all(<v8-coverage-object>.map(async function ({
functions,
url
}) {
...
pathname = url.replace((
process.platform === "win32"
? "file:///"
: "file://"
), "").replace((
/\\\\/g
), "/");
// filter out internal-content who's pathname does not begin with <cwd>,
// or pathnames containing "node_modules"
if (
pathname.indexOf(cwd) !== 0 ||
pathname.indexOf(cwd + "[") === 0 ||
pathname.indexOf("/node_modules/") >= 0
) {
return;
}
... you can tool-lessly create your own html-coverage-report with the following simple shell script: #!/bin/sh
curl -L -O https://raw.githubusercontent.com/jslint-org/jslint/v2021.5.23/ci.sh
printf 'console.log(true ? "hello world" : "bye world");' > foo.js
sh ci.sh shRunWithCoverage node foo.js
find .
# stdout/stderr:
# % Total % Received % Xferd Average Speed Time Time Time Current
# Dload Upload Total Spent Left Speed
# 100 30614 100 30614 0 0 57981 0 --:--:-- --:--:-- --:--:-- 57871
# hello world
#
# coverage-report
# +----------------------------------+----------+
# | files covered | lines |
# +----------------------------------+----------+
# | ./ | 0 % |
# | ________________________________ | 0 / 1 |
# +----------------------------------+----------+
# | ./foo.js | 0 % |
# | ________________________________ | 0 / 1 |
# +----------------------------------+----------+
#
# .
# ./.build
# ./.build/coverage
# ./.build/coverage/coverage-badge.svg
# ./.build/coverage/coverage-report.txt
# ./.build/coverage/coverage-v8.json
# ./.build/coverage/foo.js.html
# ./.build/coverage/index.html
# ./ci.sh
# ./foo.js |
Beta Was this translation helpful? Give feedback.
-
First of all, thanks! I'll probably rephrase the question a bit, since, well, I do know that I can read the node's report and filter it out by the URLs of the entries, so that's no brainer. So the question is more about: can we make NodeJS to narrow down the coverage dump in the first place, even before that data touches the hard disk. Another possibility - is it possible to get handle to that coverage object in the memory, say, from parent process (something like this Profiler API of Chromium Dev Tools)? |
Beta Was this translation helpful? Give feedback.
-
I addition to the drill into the details with @kaizhu256 , I'd just like to pause moment on the following thought:
All this might seem like pre-mature optimizations, but i'm dwelling now on some 'coverage-per-test' cross platform scenario and having, say 400-600 tests adding up overhead of: dump of full coverage by Node => read/parse it by test runner => filter out vast majority of that - all those just looks like a case to do some optimization here... |
Beta Was this translation helpful? Give feedback.
-
I hate to necro something that's years old, but wanted to point out a parallel element of code coverage that may or may not be relevant at the low level of v8 coverage, but I think is highly desirable to make the native test runner fully featured enough to support base use cases where coverage is desired. The code coverage report does not currently allow for selecting files to include in the report. This means any files that AREN'T exercised at all don't show up in the report, and the totals are only relevant to those files that are executed. Additionally, it includes coverage for the test files themselves, which is likely not behavior expected by most. I believe that at the node level (not V8), it should be able to either take a directory path to include and filtering options to ignore files in the report OR take a glob pattern of files to include in the report (basically both of the above combined). I think this could be handled in post-processing by node in just reporting the files NOT included in the V8 coverage as zero coverage and ignoring those files according to the above filter. |
Beta Was this translation helpful? Give feedback.
-
It is possible to collect a JS coverage running
node
withNODE_V8_COVERAGE
env variable set.The coverage dumped includes much more than the 'user-land' code, mostly
node
's own internal content.Is it possible (how, if any?) to specify a url pattern that will be taken as a filter to reduce the reported data?
Beta Was this translation helpful? Give feedback.
All reactions