@@ -13,32 +13,41 @@ const gulpExeca = require('../exec')
1313const TRAVIS_CONFIG = `${ __dirname } /../../.travis.yml`
1414
1515const 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+
2534const 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
3243const NESTED_DIR = `node_modules/${ name } `
44+ // The RegExp needs to account for Windows having different separators.
3345const NESTED_DIR_REGEXP = new RegExp (
3446 `node_modules(\\/|\\\\)${ name } (\\/|\\\\)` ,
3547 'gu' ,
3648)
3749const 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
4352const unitwatch = getWatchTask ( { UNIT : unit } , unit )
4453
0 commit comments