Jenny M Jenny M - 4 months ago 15
Node.js Question

Run project exsiting HTML file after code coverage finish in grunt

I've node app which use grunt to generate code coverage report
this report is located under and I was able to run it manually

myAPP
-coverage
-index.html


I want that when the task of coverage will finish and the report is generated to run this index.html in the browser,how should I do that?
I found this

https://www.npmjs.com/package/grunt-run

but its not working

I try many ways

grunt.initConfig({
run: {
commands: {
exec: '/coverage/lcov-report/index.html',
}
}
});


or

grunt.initConfig({
run: {
path: '/coverage/lcov-report/index.html',
}

});


Maybe I'm not using it well I just want to run existing html file from my project with some grunt task

Answer

To open a webpage with the browser in NodeJS there are some modules that let's you do that cross-platform.

Luckily for you there's a grunt plugin that integrates with open: grunt-open .

When configuring it tell the URL of the index.html:

grunt.initConfig({
  open : {
    file : {
      // Put here the absolute path of the file
      path : '/path/to/coverage/lcov-report/index.html'
    }
  }
});

grunt.loadNpmTasks('grunt-open');