문제

I'm new to Node.js.

module.exports = process.env.EXPRESS_COV
    ? require("./lib-cov/express")
    : require("./lib/express");

I know EXPRESS_COV returns a Boolean value, but what is the difference between lib-cov/express and lib/express?

도움이 되었습니까?

해결책

process.env.EXPRESS_COV would be true when you're running tests and want to see the code coverage of those tests (i.e. how many lines of your codebase are actually executed when the tests are run). Mocha, the test framework used for express, achieves this through the use of jscoverage.

JSCoverage parses through your source code and adds a bunch of lines that look like this:

$_jscoverage[filename][line]++;

Naturally, that's rather confusing to have in one's source code, not to mention adding a lot of bulk. So we'd never want JSCoverage processed files in our codebase. Fortunately, JSCoverage places the modified files in a different directory. In this case, ./lib-cov/ instead of ./lib/. That way, we can see how effective our tests are and not clutter up our code.

For details on how this whole rigamarole runs, see TJ Holowaychuk's article.

If you want to avoid all of this, you can use Istanbul instead, as it's much simpler and doesn't require exceptions in index.js

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top