jimivdw / grunt-mutation-testing

JavaScript Mutation Testing as grunt plugin. Tests your tests by mutating the code.
MIT License
51 stars 11 forks source link

Using Karma does not seem to run any tests #31

Closed redboul closed 9 years ago

redboul commented 9 years ago

Hi all,

I used to make 0.5.1 work last year and I wanted to use the mutation test again with the new version. I succeeded in having the grunt task set up but it seems nothing is tested. Here is the task definition I used :

mutationTest: {
      options: {
        karma: {
          configFile: 'karma.conf.js',
          fileSpecs: 'test/spec/mapping.spec.json',
          waitForRunnerTime: 10
        },
        reporters: {
          html:{
            dir: 'reports/grunt-mutation-testing',
            successThreshold: 90
          },
          console: true
        }
      },
      all: {
        options: {
          code: [
            'main/common/**/*.js',
            'main/features/**/*.js',
            'test/spec/**/*.js'
          ],
          specs: '**/*.spec.js',
          mutate: 'main/common/services/feature-manager.js',
          logLevel: 'ALL'
        }
      }
    }

where the test/spec/mapping.spec.json looks like this :

{
  "main/common/services/i18n.js" : ["test/spec/common/services/i18n.spec.js"],
  "main/common/services/feature-manager.js" : ["test/spec/common/services/feature-manager.spec.js"]
}

The karma.conf.js is correct because when I run karma the 500 tests pass (it uses jasmine test framework by the way).

Can you give me hint about this?

I will update the Readme consequently.

Thx

paysdoc commented 9 years ago

Hi Julien, sorry to hear about the trouble you're having. I'll look into it on Friday (my day off for working on projects like this one). Or are you in a hurry?

paysdoc commented 9 years ago

Can't see much wrong there. Could you send your karma.conf file?

jimivdw commented 9 years ago

Hi Julien,

When nothing seems to be tested, but no errors are shown either, there is usually something wrong with the configuration of your spec files. I do not know exactly what is causing the problem here, but you could try a few things:

Could you also provide us with the output of running npm ls -depth 1 in your project root, and maybe even the full output of running grunt mutationTest:all? And are you using the latest and greatest version (1.1.0), or a slightly older one?

Thanks! -Jimi

redboul commented 9 years ago

Hi,

thx for your time.

yes, I'm using the 1.1.0 version of the project.

here is the result of the npm ls -depth 1 : npm.ls.out

here is the output of the grunt mutationTest:all command: grunt.mutationTest.all.out

the full project is available here bonita-portal-js - branch mutation test

I will try to inspect code to check what is done (if I find enough time)...

BR

Julien

jimivdw commented 9 years ago

Hi Julien,

Sorry for not responding earlier. We haven't really had a lot of time to work on the project lately.

I quickly looked at your project though, and first thing I noticed was that, even without mutations, some tests were failing. Maybe I did something wrong, but in order for grunt-mutation-testing to work properly, all tests need to be passing without applying mutations.

Secondly, I found that there is also a problem with the generation of the Karma coverage files. I haven't been able to pinpoint exactly what's wrong, but that problem might have something to do with the order in which you load/specify your javascript files in the configuration object.

-Jimi

redboul commented 9 years ago

ok, thanks for your answer (been busy too, sorry). I cleaned up the project from my test settings and now all tests pass using grunt test (it seems that using Chrome with karma makes tests fail)

I updated the branch from the master and now karma test files are injected using wiredep. Maybe the order is cleaner now.

jimivdw commented 9 years ago

Hi Julien,

I finally figured it out! At first, nothing seemed wrong with your confguration; you configured the location of your code files, your spec files, and a file you wished to mutate. The only thing you are missing here is the libraries that are needed to run your code (i.e. bower dependencies). Basically, the code configuration option should contain all files needed to run your project, which is usually the content of the files configuration option in your Karma config file minus the spec files. Copying over that configuration and removing the spec files, I got the mutation testing working for your project.

Now, of course, we should have something in place to warn you about an incomplete configuration. I have created issue #37 to fix this (as we should already have that in place, but apparently it's not working anymore or has never really worked at all).

This issue will now be closed, as the specific case has been solved and the underlying cause will be tracked in a different issue.

-Jimi