Search code examples
javascriptpromisecode-coveragebluebirdistanbul

Why does Istanbul show coverage for everything in a promise chain regardless of whether or not there's a test for it?


My code has:

.then((data) => {
  let providerId = data[1].name;
  console.log(providerId);

  return global.db.Transcription.create({
    ConferenceId: foundConference.id
  })
    .then(() => {
      return {
        providerId
      };
    });
})
.then((dbTranscription) => {
  return factory.checkTranscription({
    Body: JSON.stringify({
      providerId: dbTranscription.providerId
    })
  });
})

Istanbul shows: enter image description here

However, I have no specific test for the checkTranscription being called, etc. I'd rather not show that as covered. Is there anyway to do that?


Solution

  • Istanbul will provide coverage for the code within any file that satisfies the glob you provide for the include property. You can also specify an exclude glob that can be used to exclude specific files (like your test files themselves). The only way to get istanbul to ignore a specific function's implementation is to move that function (in this case (dbTransciption) => { return factory.checkTranscription(...); }) to its own module and exclude that file from test coverage.

    Somewhere in your codebase that is being tested, it is calling that promise chain and eventually calling that function. You can see that because of the 1x on line 71.

    The question is though, why exclude that from coverage?