devongovett / browserify-istanbul Goto Github PK
View Code? Open in Web Editor NEWA browserify transform for the istanbul code coverage tool
A browserify transform for the istanbul code coverage tool
I use babel-istanbul
, but since this library calls require('istanbul')
at the beginning, I'm forced to install "istanbul" even if I'm not using it.
I suggest the change I made in the "index.js" file of the #29.
Hello,
I'm looking to use your project in setting up Karma for code coverage with Istanbul on a project which uses Browserify. There's a directory which contains vendor packages which I'm looking to exclude from the source code coverage report. I'm having trouble figuring out how to configure this. How can this be configure using your project? If it can't be configured using your project, is it possible to configure it using karma-coverage?
I know there's .istanbul.yml file which contains settings for exclusion of source files, however it appears that the .istanbul.yml in the root of my project is not having an impact on results.
Also, in your README example, what is "browserifyBundle"?
Thank you!
Hello,
I'd like to use istanbul-traceur (https://www.npmjs.org/package/istanbul-traceur) with browserify-istanbul.
The modificiation could be very small to browserify-istanbul code, as we could pass the instrumenter as an option.
Would you accept a PR in this direction ?
var instrumenter = instrumenter in options ? options.instrumenter : new istanbul.Instrumenter();
Cheers
I 'm using your module with karma-coverage to generate coverage analysis when I launch my tests.
karma-coverage has been upgraded to use istanbul 0.3.x. It isn't compatible with Istanbul 0.2.8.
Could you upgrade your dependencies to use Istanbul 0.3.x?
Thank you and good job.
I was very excited about this module because I need to get karma coverage working in a browserify project; as I understand it, options can only be supplied when the module API is used (i.e. there is no package.json configuration like in i.e. browserify-shim)? The default ignore patterns only match directory based test setups; when the tests are in the same directory as the implementations, I see no way to hook this into the karma configuration.
This could be easily fixed by adding something like '*_/__test.js' to the default patterns.
Cf. https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub#h.j5rabwh55y7k
After upgrading browserify-istanbul from version 2.0.0 to version 3.0.1 I get the following exception during karma test execution:
TypeError: (options.instrumenter || require(...)).createInstrumenter is not a function
at transform (/home/cfinckle/lhotse-repos/sharing/node_modules/browserify-istanbul/index.js:42:83)
at module.exports (/home/cfinckle/lhotse-repos/sharing/node_modules/browserify-istanbul/index.js:23:12)
at nr (/home/cfinckle/lhotse-repos/sharing/node_modules/module-deps/index.js:301:23)
at onfile (/home/cfinckle/lhotse-repos/sharing/node_modules/resolve/lib/async.js:56:21)
at onex (/home/cfinckle/lhotse-repos/sharing/node_modules/resolve/lib/async.js:104:32)
at /home/cfinckle/lhotse-repos/sharing/node_modules/resolve/lib/async.js:24:24
at /home/cfinckle/lhotse-repos/sharing/node_modules/async-listener/glue.js:188:31
at FSReqWrap.oncomplete (fs.js:153:5)
I have the following main dependencies included:
"browserify": "14.5.0",
"browserify-istanbul": "3.0.1",
"isparta": "4.0.0",
"karma": "1.7.1",
"karma-browserify": "5.1.2",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.1",
I am using node 8.9.1.
Here is my karma config:
'use strict';
const isparta = require('isparta');
const os = require('os');
module.exports = (config) => {
const testJsAssetsDir = '../../test/client/';
config.set({
basePath: '',
frameworks: [
'browserify',
'jasmine-jquery',
'jasmine'
],
files: [
// fixtures
{
pattern: './fixture/**/*',
included: false
},
// globals
'https://develop.otto.de/static/global-resources/js/latest/testing/private_testing_min.js',
'https://develop.otto.de/static/global-pattern/js/latest/testing/private_testing_min.js',
// testUtil
${testJsAssetsDir}util/initUtil.js
,
// specs
${testJsAssetsDir}js/**/*.test.js
],
exclude: [],
preprocessors: {
[${testJsAssetsDir}js/**/*.test.js
]: ['browserify']
},
browserify: {
debug: true,
transform: [
[
'browserify-istanbul',
{
instrumenter: isparta
}
],
'babelify'
]
},
reporters: [
'kjhtml',
'mocha',
'coverage'
],
coverageReporter: {
type: 'lcov',
dir: '../../target/coverage/client'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
browserConsoleLogOptions: {
level: 'log',
terminal: true
},
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false,
concurrency: os.cpus().length
});
};
Do you have an Idea, what causes the problem?
where is browserifyBundle? where are you putting that js?
Hi
I'm trying to use karma-jamine for unit testing an Angular project which leverages browserify. However is seems, the karma.config either runs the tests or generates the coverage report using karma-istanbul. In the scenario that the tests run (karma.config.js as below) the coverage report shows 100% no matter what. If I include istanbul (commented in the code below) it shows bundle error and test don't run, the report therefore shows 0% for all tests. Please could you help.
`
// Karma configuration
'use strict';
var istanbul = require('browserify-istanbul');
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: './',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine','browserify'],
// list of files / patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js', // for angular.mock.module and inject.
'app/**/*.js'
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'app/**/*.js':['browserify','coverage'],
'app/*.spec.js':['browserify']
},
// karma-browserify configuration
browserify: {
debug: true,
transform: ['debowerify','partialify', istanbul({
'ignore': ['./**/*.spec.js', './bower_components/**']
})],
//transform: ['debowerify','partialify'],
// don't forget to register the extensions
extensions: ['.js']
},
// test results reporter to use
// possible values: 'dots', 'progress', 'spec'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['spec', 'coverage'],
coverageReporter: {
//type: 'text',
//dir: './reports/coverage'
reporters: [
{ type: 'html', dir: 'reports/coverage'}
// { type: 'text' },
],
instrumenterOptions: {
istanbul: {
noCompact: true
}
},
instrumenter: {
'app/*.spec.js': 'istanbul'
},
includeAllSources: true
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'Chrome'
// 'PhantomJS'
],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
`
I've been trying to get browserify-istanbul to work with the latest unstable Istanbul version for more accurate ES6 coverage reports.
Currently stuck on the fact that neither [email protected] or the version specified in istanbul-instrumenter package seem to support ES6 module syntax. This is bizarre to me, but when running against my codebase I get:
14 05 2016 14:47:00.671:ERROR [karma]: { [Error: Line 6: Unexpected token] index: 122, lineNumber: 6, description: 'Unexpected token' }
Error: Line 6: Unexpected token
Which correlates to:
export class TransitionStateError extends Error {
So unless we can figure out why this isn't parsing to a correct AST, I'm blocked on further progress :-/
It seems like this transform doesn’t read configuration defined in .istanbul.yml
. Is this intentional?
i get red for the execution of the module even though it's required. here's the code for requiring:
util = require('@grid/util');
this works because i have a symlink from node_modules/@grid to the modules directory which contains util. this pattern is very nice for requiring without using brittle paths but istanbul doesn't seem to be able to map it back. any thoughts?
Much like the instrumenterConfig
option we can have a minimatchOptions
option
It seems like there is no way to create a lcov report.
Recently, i found an ambiguous issue for creating coverage report. the problem is report created successfully on local pc but the CI server can't ignore ignore
option's files.
So html reporter meet handlebars files and throw error while creating report.
I found problem of issue almost 10 hours. it is rough time.
CI server's root directory is hidden directory. So
local PC: ~/project/drive/{sources}
CI: ~/.jenkins/jobs/drive/workspace/{sources}
In this case. minimatch
can not distinct ignore files because of hidden directory. so i add minimatchOptions: {dot: true}
then problem solved.
As a result, if you don't mind... i want sugesting minimatchOptions set {dot: true} because of module's usability.
I think module works properly in any path of disk drive.
I'm trying to get this to work with 6to5ify, but am running into an issue:
If I add 'browserify-istanbul' to my list of browserify transform in my karma.conf.js, I can only apply it to all files (including my specs, because they need to be run through browserify as well). This is my karma.conf.js:
module.exports = function(karma){
karma.set({
frameworks: ["browserify", "mocha", "chai-sinon"],
browserify: {
debug: true,
extensions: [".js", ".hbs"],
transform: ["6to5ify", "hbsfy", "browserify-istanbul"]
},
reporters: ["dots", "osx", "junit", "coverage"],
coverageReporter: {
type: "text"
},
junitReporter: {
outputFile: "spec/reports/test-results.xml"
},
preprocessors: {
"src/javascript/**/*": ["browserify"],
"spec/**/*": ["browserify"]
},
browsers: ["PhantomJS"],
files: ["spec/unit/**/*Spec.js"],
logLevel: "LOG_DEBUG",
autoWatch: true
});
};
I'm sure I'm doing something wrong here, but I can't figure out the proper way of instrumenting in this case.
https://github.com/peter-mouland/browserify-coverage
I have a tiny example project which uses browserify and karma. The problem is coverage is always 100% as it seems to be instrumenting the wrong files or something? Does this mean the transform has not been applied correctly?
Are you able to either take a look, or put up a tiny example project that works in your repo?
Ok so I've dropped in browserify-istanbul in to my transform and it's throwing the following error:
TypeError: undefined is not an object (evaluating '__cov_6Holy$lJRi8fuZorzSBmWQ.b['2'][0]')
at /var/folders/bm/0q_ysbdn2p9g8_mvhhvklrj00000gn/T/5ee93f4e9129b3ef96de996e5c6b3be4.browserify:14564
My transform is step like so:
bundle.transform(istanbul({
ignore: ['../spec/*'],
instrumenterConfig: { embedSource: true }
}));
I'm running browserify 13.0.0, karma with karma coverage and babelify.
The version of istanbul
that is used is quite a bit out-of-date. There are also npm install warnings that go away if you update the latest version.
npm WARN prefer global [email protected] should be installed with -g
First, thanks for a great tool. It's solved an issue that I've spent days on - how to get code coverage of the source files versus the browserified ones.
I'm using http://theintern.io as the testing framework for our application. It uses a custom coverageVariable
of __internCoverage
, and also uses the noCompact: true
option. I'd like to be able to pass those directly to browserify-istanbul as configuration params, but the current format doesn't allow it.
Would you be open to a change/pull request that creates the instrumenter inside the transform function, so that options such as the coverageVariable
could then be passed through to the istanbul.Instrumenter instantiation call?
is there an occasion when you would want to instrument bower_components?
Am i right in thinking these are external dependencies, or do people user bower for other use cases?
I suggest this because i get a timeout with my tests when using this transform within karma without using:
istanbul({ ignore: ['**/bower_components/**'] })
Unfortunately I am finding that the directive /* istanbul ignore next */
does nothing, unlike in the standard version of Istanbul.
I want to use it to ignore require statements like I would in Istanbul since they are messing with my code coverage.
Here is the documentation for ignoring code in Istanbul's repo.
Here is my transform in karma.conf
transform: [ 'rewireify', babelify, istanbul({
ignore: [
'**/spec/**',
'**/node_modules/**',
'**/app/js/config.js'
],
}) ],
And here is what I'm attempting to do
'use strict';
/* istanbul ignore next */
var CardView = require('./card');
I'd love to have this feature, as it is really useful in large apps.
Without it it becomes very difficult to figure out what is and is not actually covered in the file itself as opposed to what is not covered inside the required-in files.
Since the instrumenter can be specified using the instrumenter
option, istanbul
should not be a required dependency.
I had been searching for a way to get file specific coverage for about an hour or 6. We use CommonJS and browserify, so up until now we just had coverage of our bundle. Finally, I found your post here, and through there I found this repo. Changing about 10 lines in my Gruntfile gave me what I have been looking for, so I would really like to thank you for making the world a better place! Feel free to close or delete this issue, since it's not really an issue, however I can imagine there are more people who's day you have made or will in the future, so yeah. Anyways, thanks!
Thank you for the merge of #11. Will you be releasing a tag and a version to npm (0.1.4) with your changes plus that one? Although I often use a direct git reference in package.json
, having a new npm version would be ideal.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.