Closed robkinyon closed 8 years ago
Thanks for the issue, Rob. Could you let me know which plugin of this repo you are using, the framework
or preprocessor
? Perhaps give me an example of your karma config file.
module.exports = (config)->
'use strict'
config.set
preprocessors:
'test/**/*.coffee': ['coffee']
'app/scripts/**/*.coffee': ['coffee-coverage']
That basic idea. On Linux/OSX, that works exactly as expected. On Windows, it does not.
When you say "breaks", what exactly is breaking? I setup a dummy project on a windows 10 VM to simulate your setup. My karma config looks like this:
// Karma configuration
// Generated on Mon Mar 07 2016 10:06:20 GMT-0800 (Pacific Standard Time)
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: ['mocha'],
// list of files / patterns to load in the browser
files: [
'test/**/*Test.js',
'app/scripts/**/*.coffee'
],
// 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/scripts/**/*.coffee': ['coffee-coverage']
},
coffeeCoverage: {
preprocessor: {
instrumentor: 'istanbul'
}
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage'],
// 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'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
The tests run, and I do get coverage reported accurately.
I do see that some coverage HTML reports do end up in app/scripts/...
. I am not sure why that is, but that part is done by karma-coverage
, as karma-coffee-coverage
, in this case, is just transforming the coffee
files into js
files with instrumentation.
The first problem is the generation of the coverage HTML files in app/
. This causes issues for all sorts of reasons, two being:
grunt test
when a file matching app/**/*.html
changes (because your views are HTML files), this can cause your test watcher to enter an infinite loop. (You run the test, that changes an HTML file, which causes the watcher to run the test ...)The second problem is when you open test/coverage/report-html/index.html
, you cannot navigate to those files (incorrectly generated in app/
) because the URLs are the filepaths.
Also, I doubt the problem is with karma-coverage because it doesn't have this problem when doing coverage on JS files using the standard karma-coverage plugin. This only happens with the karma-coffee-coverage plugin.
Yep, you are right; it is my fault. It seems like passing in file.originalPath
here ends up putting in a path that istanbul has a hard time with. By wrapping with path.resolve(file.originalPath)
, everything seems to work out well.
I created a branch, fix-windows-paths
. Would it be possible for you to test it out? Once verified I can merge and publish a new version.
I've asked the members of the team I work with to test this out. We should have a response in the next couple days.
Thank you so much for being so responsive.
Confirmed that this fix addresses the problem in all of our testing. Thanks again!
Excellent. Merged and published as v1.1.2
via d9d277384a89109bf5f44126bcc892675baa8b5f
When we hook this up on windows, the file paths created (
C:\foo\bar\baz
) are assumed to be usable as URIs (file://<path>
). This assumption is okay for OSX and Linux, but not Windows.The coverage files are also created within the
app/
directory, not thetest/coverage
directory where they are created on OSX and Linux.I discovered this when working with a mixed team (1 on Ubuntu, 5 on OSX, 3 on Windows). We had to disable karma-coffee-coverage and go back to normal karma-coverage on the generated JS files.