Skip to content

Commit

Permalink
chore: Lazy load modules that are rarely/never needed in test process…
Browse files Browse the repository at this point in the history
…es. (#1232)
  • Loading branch information
coreyfarrell authored Nov 19, 2019
1 parent 7307626 commit 28ed746
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ const Hash = require('./lib/hash')
const libCoverage = require('istanbul-lib-coverage')
const libHook = require('istanbul-lib-hook')
const { ProcessInfo, ProcessDB } = require('istanbul-lib-processinfo')
const libReport = require('istanbul-lib-report')
const mkdirp = require('make-dir')
const Module = require('module')
const onExit = require('signal-exit')
const path = require('path')
const reports = require('istanbul-reports')
const resolveFrom = require('resolve-from')
const rimraf = promisify(require('rimraf'))
const SourceMaps = require('./lib/source-maps')
const testExclude = require('test-exclude')
Expand Down Expand Up @@ -127,10 +124,11 @@ class NYC {
}

_loadAdditionalModules () {
if (!this.config.useSpawnWrap) {
if (!this.config.useSpawnWrap || this.require.length === 0) {
return
}

const resolveFrom = require('resolve-from')
this.require.forEach(requireModule => {
// Attempt to require the module relative to the directory being instrumented.
// Then try other locations, e.g. the nyc node_modules folder.
Expand Down Expand Up @@ -430,6 +428,9 @@ class NYC {
}

async report () {
const libReport = require('istanbul-lib-report')
const reports = require('istanbul-reports')

const context = libReport.createContext({
dir: this.reportDirectory(),
watermarks: this.config.watermarks,
Expand Down

0 comments on commit 28ed746

Please # to comment.