Node Application Testing and LCOV Reporting with Mocha

My group recently started work on a pre-existing Node application written entirely in ES6 (its through a couple of different developers before we worked on it). The app is minimally tested using Mocha and Nyan as reporter for Mocha. The package.json file already contains the following command to run tests:

"test": "node ./node_modules/mocha/bin/mocha  --compilers js:babel-core/register ./test/**/*.spec.js"

      

As part of our deployment cycle, we are using a CI / CD pipeline with Travis and Codacy . As a result, in order to include some of the Codacy code, I needed to make some changes to the application repository and the package.json file. The basic idea was for Mocha to generate a .lcov file, which is then passed to Codacy in the Travis build script.

After some research, I put together the following to successfully generate the lcov file:

    "build-test": "node ./node_modules/mocha/bin/mocha -R mocha-lcov-reporter > coverage/coverage.lcov  --compilers js:babel-core/register ./test/**/*.spec.js --reporter nyan"

      

The problem is I am getting a Codacy parsing error for the .lcov file. I have looked at lcov files for other projects and there seems to be additional data in what I am generating. For reference, here is the generated lcov file:

0
0
0

[4A[5C-
[5C-
[5C-
[5C-
[4A[6C_,------,
[6C_|   /\_/\ 
[6C^|__( - .-) 
[6C  ""  "" 
[4ACONSTRUCTOR
 1
 0
 0

[4A[5C-_
[5C-_
[5C-_
[5C-_
[4A[7C_,------,
[7C_|  /\_/\ 
[7C~|_( ^ .^) 
[7C ""  "" 
[4ACONSTRUCTOR
 2
 0
 0

[4A[5C-_-
[5C-_-
[5C-_-
[5C-_-
[4A[8C_,------,
[8C_|   /\_/\ 
[8C^|__( ^ .^) 
[8C  ""  "" 
[4ACONSTRUCTOR
 3
 0
 0

[4A[5C-_-_
[5C-_-_
[5C-_-_
[5C-_-_
[4A[9C_,------,
[9C_|  /\_/\ 
[9C~|_( ^ .^) 
[9C ""  "" 
[4ACONSTRUCTOR
{"name":"from http://localhost:9200 searcher","hostname":"NCI-01966295-ML","pid":14596,"level":30,"msg":"Active","time":"2017-05-16T23:02:37.746Z","v":0}
{"name":"from http://localhost:9200 searcher","hostname":"NCI-01966295-ML","pid":14596,"level":30,"msg":"Temporarily Closed to Accrual","time":"2017-05-16T23:02:37.747Z","v":0}
 4
 0
 0

[4A[5C-_-_-
[5C-_-_-
[5C-_-_-
[5C-_-_-
[4A[10C_,------,
[10C_|   /\_/\ 
[10C^|__( ^ .^) 
[10C  ""  "" 
[4ACONSTRUCTOR
 5
 0
 0

[4A[5C-_-_-_
[5C-_-_-_
[5C-_-_-_
[5C-_-_-_
[4A[11C_,------,
[11C_|  /\_/\ 
[11C~|_( ^ .^) 
[11C ""  "" 
[4ACONSTRUCTOR
 6
 0
 0

[4A[5C-_-_-_-
[5C-_-_-_-
[5C-_-_-_-
[5C-_-_-_-
[4A[12C_,------,
[12C_|   /\_/\ 
[12C^|__( ^ .^) 
[12C  ""  "" 
[4ACONSTRUCTOR
 7
 0
 0

[4A[5C-_-_-_-_
[5C-_-_-_-_
[5C-_-_-_-_
[5C-_-_-_-_
[4A[13C_,------,
[13C_|  /\_/\ 
[13C~|_( ^ .^) 
[13C ""  "" 
[4ACONSTRUCTOR
 8
 0
 0

[4A[5C-_-_-_-_-
[5C-_-_-_-_-
[5C-_-_-_-_-
[5C-_-_-_-_-
[4A[14C_,------,
[14C_|   /\_/\ 
[14C^|__( ^ .^) 
[14C  ""  "" 
[4ACONSTRUCTOR
 9
 0
 0

[4A[5C-_-_-_-_-_
[5C-_-_-_-_-_
[5C-_-_-_-_-_
[5C-_-_-_-_-_
[4A[15C_,------,
[15C_|  /\_/\ 
[15C~|_( ^ .^) 
[15C ""  "" 
[4A




  9 passing (20ms)

      

I noticed a few things about npm scripts (test and build-test):

  • the test is working correctly, telling me that 9 tests are passing.
  • If I run build-test without "--reporter nyan" it says "no coverage data, make sure your code is installed correctly"
  • Anything in the test line of code is required.

I'm out of my mind, to be honest. I don't know why the .lcov file is having parsing problems. All I really need is to use mocha with mocha-lcov-reporter to generate a valid .lcov file. It doesn't seem like it's supposed to be that hard.

Thank you for your help. I appreciate it.

+3


source to share





All Articles