karma-coverage
karma-coverage copied to clipboard
Coverage reported on untested files
I have two source files : sign-up.js and login.js, and only one test: login.spec.js.
Expected result:
- login.js : 100% lines covered
- sign-up.js : 0% lines covered
Actual result:
- login.js : 100% lines covered
- sign-up.js : 42.86% lines covered
When I'll uncomment all tests. Empty test-suite will report cover of
- login : 42.86%lines covered
- sign-up.js : 42.86%
sign-up.js
angular.module('app.SignUpCtrl', []).controller('SignUpCtrl', SignUpCtrl);
function SignUpCtrl($scope, account, $timeout, $state, facebook) {
$scope.signUp = signUp;
$scope.loginWithFacebook = loginWithFacebook;
function signUp(email, password, playerName) {
account.signUp(email, password, playerName, {
success: signUpSuccess,
fail: showError
});
}
function loginWithFacebook() {
facebook.login(function (response) {
signUpSuccess();
});
}
function signUpSuccess() {
$state.go('home');
}
function showError(user, error) {
$timeout(function () { // avoid existing digest
$scope.error = error.message;
});
}
}
login.js
angular .module('app.LoginCtrl', []) .controller('LoginCtrl', LoginCtrl);
function LoginCtrl($scope, account, $timeout, $state, facebook) {
$scope.loginWithFacebook = loginWithFacebook;
$scope.login = login;
function loginWithFacebook() {
facebook.login(function (response) {
loginSuccess();
});
}
function login(email, password) {
account.signIn(email, password, {
success: loginSuccess,
fail: showError
});
}
function loginSuccess() {
$state.go('home');
}
function showError(user, error) {
$timeout(function () { // avoid existing digest
$scope.error = error.message;
});
}
}
My config:
preprocessors: {
// source files, that you wanna generate coverage for
'../../app/*/!(*.spec).js' : ['coverage']
},
If the modules are getting imported at all, it makes sense that the signature(s) and top-level statements would be "covered".
You can try setting the config flag for DEBUG logging to see which files are being preprocessed to add coverage instrumentation as a check on you config.