karma-coverage icon indicating copy to clipboard operation
karma-coverage copied to clipboard

Coverage reported on untested files

Open mrt123 opened this issue 9 years ago • 2 comments

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

mrt123 avatar Jul 11 '16 15:07 mrt123

If the modules are getting imported at all, it makes sense that the signature(s) and top-level statements would be "covered".

skyl avatar May 04 '18 19:05 skyl

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.

johnjbarton avatar May 04 '18 23:05 johnjbarton