Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
code coverage browserify transform
Suppose we have a test.js:
var test = require('tape');
var foo = require('./foo.js');
test('beep boop', function (t) {
t.plan(1);
foo(function (err, x) {
if (err) deadCode();
t.equal(x * 5, 555);
});
});
and a foo.js:
module.exports = function (cb) {
var i = 0;
var iv = setInterval(function () {
if (i++ === 10 || (false && neverFires())) {
clearInterval(iv);
cb(null, 111);
}
}, 10);
};
Now with browserify and testling we can do:
$ browserify -t coverify example/test.js | testling | coverify; echo EXIT CODE: $?
TAP version 13
# beep boop
ok 1 should be equal
1..1
# tests 1
# pass 1
# ok
# /home/substack/projects/coverify/example/test.js: line 7, column 16-28
if (err) deadCode();
^^^^^^^^^^^
# /home/substack/projects/coverify/example/foo.js: line 3, column 35-48
if (i++ === 10 || (false && neverFires())) {
^^^^^^^^^^^^
EXIT CODE: 1
browserify
compiled our test.js
file, then testling
ran our code in a
local headless browser (we also could have used node
), and then coverify
parsed the test output for code coverage data and printed some nicely formatted
results on stderr. Hooray!
var coverify = require('coverify')
var parse = require('coverify/parse')
Usually you can just do browserify -t coverify
to get code coverage but you
can also use the api directly if you want to use this code directly.
Return a transform stream for file
that will instrument the input source file
using console.log()
.
To use a different function from console.log()
, pass in opts.output
.
Return a transform stream that accepts test output as input and looks for lines
starting with COVERAGE
and COVERED
to generate a coverage report in
cb(err, coverage)
. coverage
is an object that maps filenames from the bundle
files to arrays of coverage data. All of the non-/^(COVERAGE|COVERED)\s/
lines
are passed through from the input to the output.
Here is some example coverage data that you can generate with coverify --json
:
{
"/home/substack/projects/coverify/example/test.js": [
{
"range": [
158,
169
],
"lineNum": 7,
"column": [
16,
28
],
"line": " if (err) deadCode();",
"code": "deadCode();"
}
],
"/home/substack/projects/coverify/example/foo.js": [
{
"range": [
123,
135
],
"lineNum": 3,
"column": [
35,
48
],
"line": " if (i++ === 10 || (false && neverFires())) {",
"code": "neverFires()"
}
]
}
usage: coverify OPTIONS
OPTIONS are:
--json
Suppress normal output and print json coverage data to stdout.
-q, --quiet
Don't print non-coverage input back out to stdout.
--stdout
Always print non-coverage input back out to stdout.
-o FILE, --output FILE
Print coverage data to FILE. Use "@2" for stderr (the default) and "@1" or
"-" for stdout.
With npm do:
npm install coverify
to get the browserify transform module.
When you compile your tests with browserify you can just do:
browserify -t coverify ...
You will also need the coverify
command for parsing the test output:
npm install -g coverify
MIT
FAQs
code coverage browserify transform
The npm package coverify receives a total of 295 weekly downloads. As such, coverify popularity was classified as not popular.
We found that coverify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.