Skip to content

Commit 8288dbb

Browse files
committed
Add comments
1 parent 925e1ba commit 8288dbb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

gulp/tasks/unit.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,41 @@ const gulpExeca = require('../exec')
1313
const TRAVIS_CONFIG = `${__dirname}/../../.travis.yml`
1414

1515
const unit = async function() {
16+
// In CI, we use `pack`, but not locally since it is slow.
17+
// Also, in CI we do test coverage and send it to Coveralls.
1618
if (!isCi) {
1719
return gulpExeca('ava')
1820
}
1921

22+
// When using `pack`, tested files will be inside `node_modules`
23+
// By default `nyc` ignore those, so we need to add them to `--include``
24+
// Even after this, `node_modules` are still ignored by `nyc` unless using
25+
// a negated `--exclude`
2026
await pack(`nyc --include ${NESTED_DIR} --exclude !${NESTED_DIR} ava`)
2127

2228
await sendToCoveralls()
2329
}
2430

31+
// eslint-disable-next-line fp/no-mutation
32+
unit.description = 'Run unit tests'
33+
2534
const sendToCoveralls = async function() {
35+
// We strip `node_modules/PACKAGE/` from test coverage reports so it looks
36+
// like source files were in the same directory (not inside `node_modules`).
2637
const covMap = await promisify(readFile)(COVMAP_PATH, { encoding: 'utf-8' })
2738
const covMapA = covMap.replace(NESTED_DIR_REGEXP, '')
2839

2940
await gulpExeca('coveralls', { input: covMapA })
3041
}
3142

3243
const NESTED_DIR = `node_modules/${name}`
44+
// The RegExp needs to account for Windows having different separators.
3345
const NESTED_DIR_REGEXP = new RegExp(
3446
`node_modules(\\/|\\\\)${name}(\\/|\\\\)`,
3547
'gu',
3648
)
3749
const COVMAP_PATH = './coverage/lcov.info'
3850

39-
// eslint-disable-next-line fp/no-mutation
40-
unit.description = 'Run unit tests'
41-
4251
// We have to use this to debug Ava test files with Chrome devtools
4352
const unitwatch = getWatchTask({ UNIT: unit }, unit)
4453

0 commit comments

Comments
 (0)