asciidisco / grunt-qunit-istanbul

Run QUnit unit tests in a headless PhantomJS instance & generate some nice code coverage metrics using Istanbul.
MIT License
33 stars 21 forks source link

Quick question about "src" config in "coverage" #21

Closed tylyccn closed 10 years ago

tylyccn commented 10 years ago

Hi,

To configure the source javascript files to be tested, I have 3 seperated directories need be configured, see below: 'web-content/partner-manager/*/.js', 'web-content/partner/**/_.js', 'web-content/service-supplier/_/.js', and I tried for a long time for this but failed.

Can anyone tell me how to set this in the "grunt.initConfig" section in my grunt file?

Thx!

jgerigmeyer commented 10 years ago

You should be able to use a standard array of strings. For example:

    qunit: {
      options: {
        coverage: {
          src: [
            'web-content/partner-manager/**/*.js',
            'web-content/partner/**/*.js',
            'web-content/service-supplier/**/*.js'
          ],
          instrumentedFiles: 'jscov_temp/',
          htmlReport: 'jscov/'
        }
      },
      files: ['jstests/html/**/*.html']
    },

See http://gruntjs.com/configuring-tasks#compact-format for more information on how to configure grunt tasks.

tylyccn commented 10 years ago

Hi,

Thanks for your reply. I did try that, like this (my GruntFile.js):

  1 module.exports = function(grunt) {
  2 
  3   grunt.initConfig({
  4     pkg: grunt.file.readJSON('package.json'),
  5 
  6     qunit: {
  7       options: {
  8         timeout: 30000,
  9         "--web-security": "no",
 10         coverage: {
 11           src: [
 12             'web-content/partner-manager/**/*.js',
 13             'web-content/partner/**/*.js',
 14             'web-content/service-supplier/**/*.js'
 15           ],
 16           instrumentedFiles: "/home/liren/tmp/temp",
 17           htmlReport: '/home/liren/tmp/report/coverage',
 18           coberturaReport: '/home/liren/tmp/report/',
 19           linesThresholdPct: 60
 20         }
 21       },
 22       files: ["web-content/test/**/*.html"]
 23     },
 24   });
 25 
 26   grunt.loadNpmTasks("grunt-qunit-istanbul");
 27 
 28   grunt.registerTask('unit-test', ['qunit']);
 29 
 30   grunt.registerTask('default', ['qunit']);
 31 
 32 };

But when I execute grunt, below error is triggered:

$ grunt --gruntfile ../Gruntfile.js
Running "qunit:files" (qunit) task
Warning: Line 11: Unexpected token } Use --force to continue.

Aborted due to warnings.

And this error doesn't occurs if src is configured as:

src: ['web-content/partner-manager/**/*.js'],

I also notice below warnings when I tried to install grunt-qunit-istanbul, and not sure whether it matters:

npm WARN engine cryptiles@0.1.3: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.26","npm":"1.3.15"})
npm WARN engine sntp@0.1.4: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.26","npm":"1.3.15"})
npm WARN engine hoek@0.7.6: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.26","npm":"1.3.15"})
npm WARN engine boom@0.3.8: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.26","npm":"1.3.15"})

Thx!

jgerigmeyer commented 10 years ago

Hm, that should work. Can you link to a sample repo, or post the output of grunt --verbose? I notice you have a trailing comma on line 23, but I doubt that would be throwing an error.

tylyccn commented 10 years ago

Hi,

This is the output of command grunt --verbose:

[liren@testBedRenlin node_modules]$ grunt --verbose Initializing Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks. Reading package.json...OK Parsing package.json...OK Initializing config...OK

Registering "grunt-qunit-istanbul" local Npm module tasks. Reading /home/liren/Software/portal/node_modules/grunt-qunit-istanbul/package.json...OK Parsing /home/liren/Software/portal/node_modules/grunt-qunit-istanbul/package.json...OK Loading "qunit.js" tasks...OK

No tasks specified, running default tasks. Running tasks: default

Running "default" task

Running "qunit" task

Running "qunit:files" (qunit) task Verifying property qunit.files exists in config...OK Files: web-content/test/partner-manager/test-patner-manager.html -> files Options: timeout=30000, inject="/home/liren/Software/portal/nodemodules/grunt-qunit-istanbul/phantomjs/bridge.js", urls=[], force=false, coverage={"src":["web-content/partner-manager/*/.js","web-content/partner/**/.js","web-content/service-supplier/_/.js"],"instrumentedFiles":"/home/liren/tmp/temp","htmlReport":"/home/liren/tmp/report/coverage","coberturaReport":"/home/liren/tmp/report/","linesThresholdPct":60}, --web-security="no" Warning: Line 11: Unexpected token } Use --force to continue.

Aborted due to warnings.

I deleted the comma in line 23, and the warning is still here, so we can ignore that, I think.

Thx!

tylyccn commented 10 years ago

And also, I tried grunt --stack command, and see below output:

grunt --stack Running "qunit:files" (qunit) task Warning: Line 11: Unexpected token } Use --force to continue. Error: Line 11: Unexpected token } at throwError (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:1823:21) at throwUnexpected (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:1881:9) at expect (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:1890:13) at parseArguments (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2206:17) at parseLeftHandSideExpressionAllowCall (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2269:24) at parsePostfixExpression (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2317:16) at parseUnaryExpression (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2346:20) at parseBinaryExpression (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2461:16) at parseConditionalExpression (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2525:16) at parseAssignmentExpression (/home/liren/Software/portal/node_modules/grunt-qunit-istanbul/node_modules/istanbul/node_modules/esprima/esprima.js:2551:23)

Aborted due to warnings.

Maybe this can help some?

Thx

jgerigmeyer commented 10 years ago

That looks to me like a JS syntax error in one of your src files. Are you linting your JS with jshint? If you configure src with only 'web-content/partner/**/*.js' or only 'web-content/service-supplier/**/*.js' does it throw an error?

tylyccn commented 10 years ago

We're not using jshint so far, and I have a quick trial a moment ago and find out hundreds of warnings and errors:) And considering that my current target is code coverage tool investigation (I've never touched the JS before~~~), do you have any suggestions to narrow down the syntax-errored JS file? I searched the errors reported by JSHint but didn't find any errors in line 11...

And, does it make sense that the error information "Warning: Line 11: Unexpected token }" indicates an error in line 11 in one of the JS files?

Thx!

tylyccn commented 10 years ago

Ah, I got it! Please ignore my previous question, and thanks very much for your generous help on my issue!