karma-runner / karma-runner/karma-coverage

karma-coverage and requirejs not outputing coverage for files

Open
#305 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
771
Forks
242
PR merge metrics
No merged PRs in 30d

Description

So, what I'm facing is: The coverage report is coming out empty, it feels like it does not grab anything
under the ` {pattern: 'js/**/*.js', included: false, served: true},` I know this because I tried to use `*.js` to be preprocessed by the coverage and the only file it came out was the `test-main.js` (which isn't inside a patter object).

Tests are running, and passing.

What I'm thinking that's happening is that since the whole shebang is wrapped on a requirejs module, coverage doesn't understand it and never even sees the file - but I'm completly at loss on how to make karma-coverage understand it.

`karma.conf.js`

```js
// Karma configuration
// Generated on Wed Mar 29 2017 13:54:25 GMT+0100 (Hora de Verão de GMT)

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', 'requirejs'],

// list of files / patterns to load in the browser
files: [
{pattern: 'lib/**/!(*Spec|spec|test).js', included: false},
{pattern: 'js/**/*.js', included: false, served: true},
{pattern: 'unit-testing/**/*.js', included: false},
'test-main.js',
],

// list of files to exclude
exclude: [],

reporters: ['dots', 'coverage'],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'**/js/*.js': 'coverage'
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter

coverageReporter: {
type : 'html',
dir : 'report/'
},

// 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: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
````

`test-main.js`

```js
var allTestFiles = []
var TEST_REGEXP = /(spec|test)\.js$/i

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function (file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
// If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
// then do not normalize the paths
var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '')
allTestFiles.push(normalizedTestModule)
}
})

require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base',

// dynamically load all test files
deps: allTestFiles,

paths: {
'angular': 'lib/angularjs/angular',
},

// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
})
```

Contributor guide

Open the contributing guide

Research direction

Start with karma.conf.js, comparing the files patterns and coverage preprocessor pattern, then trace how test-main.js loads RequireJS modules through window.__karma__.files. Run the existing Karma suite with coverage enabled and confirm that the JavaScript files under the intended pattern produce coverage output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.