Repository: istanbuljs/nyc
Pull request #1006 (2019-02-28 04:15:49)

feat: add `es-modules` option to instrument command
This is pretty straightforward, allow the es-modules option to flow through to the instrumenter when running the standalone instrument command.

Tests adapted from the existing tests for the regular es-modules command.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/21896519/badge)](https://coveralls.io/builds/21896519)

Coverage remained the same at 96.639% when pulling **aa36ab24728ad0cfbd2193cf0707c38b24c3bb78 on AndrewFinlay:instrument-es-modules-option** into **b64d921ee15a57779e54f7ea14102c79ebf7498b on istanbuljs:master**.


Patch:
diff --git a/.gitignore b/.gitignore
index 397b8d1..2e5568e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,6 @@ coverage
 node_modules
 test/build/
 .self_coverage
-*.covered.js
+self-coverage/
 *.swp
 needs-transpile.js
diff --git a/README.md b/README.md
index 8906b4a..9ed35e7 100644
--- a/README.md
+++ b/README.md
@@ -195,52 +195,78 @@ Install custom reporters as a development dependency and you can use the `--repo
 nyc report --reporter=<custom-reporter-name>
 ```
 
-## Excluding files
+## Selecting files for coverage
 
-You can tell nyc to exclude specific files and directories by adding
-an `nyc.exclude` array to your `package.json`. Each element of
-the array is a glob pattern indicating which paths should be omitted.
+By default, nyc only collects coverage for source files that are visited during a test.
+It does this by watching for files that are `require()`'d during the test.
+Only source files that are visited during a test will appear in the coverage report and contribute to coverage statistics.
 
-Globs are matched using [minimatch](https://www.npmjs.com/package/minimatch).
+nyc will instrument all files if the `--all` flag is set.
+In this case all files will appear in the coverage report and contribute to coverage statistics.
 
-For example, the following config will exclude any files with the extension `.spec.js`,
-and anything in the `build` directory:
+nyc will only collect coverage for files that are located under `cwd`, and then only `*.js` files or files with extensions listed in in the `extension` array.
 
-```json
-{
-  "nyc": {
-    "exclude": [
-      "**/*.spec.js",
-      "build"
-    ]
-  }
-}
-```
-> Note: Since version 9.0 files under `node_modules/` are excluded by default.
-  add the exclude rule `!**/node_modules/` to stop this.
+You can reduce the set of covered files by adding `include` and `exclude` filter arrays to your config.
+These allow you to shape the set of covered files by specifying glob patterns that can filter files from the covered set.
+The `exclude` array may also use exclude negated glob patterns, these are specified with a `!` prefix, and can restore sub-paths of excluded paths.
+
+Globs are matched using [minimatch](https://www.npmjs.com/package/minimatch).
 
-> Note: exclude defaults to `['coverage/**', 'test/**', 'test{,-*}.js', '**/*.test.js', '**/__tests__/**', '**/node_modules/**']`,
-which would exclude `test`/`__tests__` directories as well as `test.js`, `*.test.js`,
-and `test-*.js` files. Specifying your own exclude property overrides these defaults.
+We use the following process to remove files from consideration:
+ 1. Limit the set of covered files to those files in paths listed in the `include` array.
+ 2. Remove any files that are found in the `exclude` array.
+ 3. Restore any exclude negated files that have been excluded in the second step.
+
+
+### Using include and exclude arrays
+
+If there are paths specified in the `include` array, then the set of covered files will be limited to eligible files found in those paths.
+If the `include` array is left undefined all eligible files will be included, equivalent to setting `include: ['**']`.
+Include options can be specified on the command line with the `-n` switch.
+
+If there are paths specified in the `exclude` array, then the set of covered files will not feature eligible files found in those paths.
+You can also specify negated paths in the `exclude` array, by prefixing them with a `!`.
+Negated paths can restore paths that have been already been excluded in the `exclude` array.
+Exclude options can be specified on the command line with the `-x` switch.
+
+The `exclude` option has the following defaults settings:
+```js
+[
+  'coverage/**',
+  'packages/*/test/**',
+  'test/**',
+  'test{,-*}.js',
+  '**/*{.,-}test.js',
+  '**/__tests__/**',
+  '**/node_modules/**',
+  '**/babel.config.js'
+]
+```
+These settings exclude `test` and `__tests__` directories as well as `test.js`, `*.test.js`, and `test-*.js` files.
+Specifying your own exclude property completely replaces these defaults.
 
-## Including files
+**Note:** The exclude list always implicitly contains `**/node_modules/**`, even if not explicitly specified in an overriding `exclude` array.
+To reverse this you must add the negated exclude rule `!**/node_modules/`.
 
-As an alternative to providing a list of files to `exclude`, you can provide
-an `include` key with a list of globs to specify specific files that should be covered:
+For example, the following config will collect coverage for every file in the `src` directory regardless of whether it is `require()`'d in a test.
+It will also exclude any files with the extension `.spec.js`.
 
 ```json
 {
   "nyc": {
-    "include": ["**/build/umd/moment.js"]
+    "all": true,
+    "include": [
+      "src/**/*.js"
+    ],
+    "exclude": [
+      "**/*.spec.js"
+    ]
   }
 }
 ```
 
-> `nyc` uses minimatch for glob expansions, you can read its documentation [here](https://www.npmjs.com/package/minimatch).
-
-> Note: include defaults to `['**']`
-
-> ### Use the `--all` flag to include files that have not been required in your tests.
+**Note:** Be wary of automatic OS glob expansion when specifying include/exclude globs with the CLI.
+To prevent this, wrap each glob in single quotes.
 
 ## Require additional modules
 
diff --git a/bin/nyc.js b/bin/nyc.js
index 2a06906..c285c5a 100755
--- a/bin/nyc.js
+++ b/bin/nyc.js
@@ -2,12 +2,7 @@
 
 const configUtil = require('../lib/config-util')
 const foreground = require('foreground-child')
-var NYC
-try {
-  NYC = require('../index.covered.js')
-} catch (e) {
-  NYC = require('../index.js')
-}
+const NYC = require('../index.js')
 const processArgs = require('../lib/process-args')
 
 const sw = require('spawn-wrap')
diff --git a/bin/wrap.js b/bin/wrap.js
index 0ec3cb0..b4c9161 100644
--- a/bin/wrap.js
+++ b/bin/wrap.js
@@ -1,10 +1,5 @@
 var sw = require('spawn-wrap')
-var NYC
-try {
-  NYC = require('../index.covered.js')
-} catch (e) {
-  NYC = require('../index.js')
-}
+var NYC = require('../index.js')
 
 var parentPid = process.env.NYC_PARENT_PID || '0'
 process.env.NYC_PARENT_PID = process.pid
diff --git a/build-self-coverage.js b/build-self-coverage.js
index bc8c2b6..6526d01 100644
--- a/build-self-coverage.js
+++ b/build-self-coverage.js
@@ -1,21 +1,43 @@
-var istanbul = require('istanbul-lib-instrument')
-var fs = require('fs')
-var path = require('path')
-
-;[
-  'index.js',
-  'lib/process.js'
-].forEach(function (name) {
-  var indexPath = path.join(__dirname, name)
-  var source = fs.readFileSync(indexPath, 'utf8')
-
-  var instrumentor = istanbul.createInstrumenter({
-    coverageVariable: '___NYC_SELF_COVERAGE___',
-    esModules: true
-  })
+const path = require('path')
+const fs = require('fs')
+const istanbul = require('istanbul-lib-instrument')
+const makeDir = require('make-dir')
+const glob = require('glob')
+
+const instrumenter = istanbul.createInstrumenter({
+  coverageVariable: '___NYC_SELF_COVERAGE___',
+  esModules: true
+})
+
+function instrumentFile (name) {
+  const indexPath = path.join(__dirname, name)
+  const outputPath = path.join(__dirname, 'self-coverage', name)
 
-  var instrumentedSource = instrumentor.instrumentSync(source, indexPath)
+  const source = fs.readFileSync(indexPath, 'utf8')
+  const instrumentedSource = name === 'package.json' ? source : instrumenter.instrumentSync(source, indexPath)
 
-  var outputPath = path.join(__dirname, name.replace(/\.js$/, '.covered.js'))
+  makeDir.sync(path.dirname(outputPath))
   fs.writeFileSync(outputPath, instrumentedSource)
-})
+}
+
+function instrumentGlob (pattern) {
+  const result = glob.sync(pattern, {
+    cwd: __dirname,
+    nodir: true
+  })
+
+  result.forEach(file => {
+    instrumentFile(file)
+  })
+}
+
+function instrumentAll () {
+  /* package.json is just being copied so the instrumented copy of lib/hash.js can find it. */
+  const globPatterns = ['package.json', 'index.js', 'bin/*.js', 'lib/**/*.js']
+
+  globPatterns.forEach(pattern => {
+    instrumentGlob(pattern)
+  })
+}
+
+instrumentAll()
diff --git a/index.js b/index.js
index dc6a461..80198b2 100755
--- a/index.js
+++ b/index.js
@@ -24,17 +24,11 @@ const api = require('istanbul-api')
 
 const debugLog = util.debuglog('nyc')
 
-var ProcessInfo
-try {
-  ProcessInfo = require('./lib/process.covered.js')
-} catch (e) {
-  /* istanbul ignore next */
-  ProcessInfo = require('./lib/process.js')
-}
+const ProcessInfo = require('./lib/process.js')
 
 /* istanbul ignore next */
-if (/index\.covered\.js$/.test(__filename)) {
-  require('./lib/self-coverage-helper')
+if (/self-coverage/.test(__dirname)) {
+  require('../self-coverage-helper')
 }
 
 function NYC (config) {
@@ -218,7 +212,7 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) {
     }
 
     if (transform) {
-      code = transform(code, { filename: filename, relFile: inFile })
+      code = transform(code, { filename: inFile, relFile: inFile })
     }
 
     if (!output) {
diff --git a/lib/commands/check-coverage.js b/lib/commands/check-coverage.js
index c12667b..746c347 100644
--- a/lib/commands/check-coverage.js
+++ b/lib/commands/check-coverage.js
@@ -1,9 +1,4 @@
-var NYC
-try {
-  NYC = require('../../index.covered.js')
-} catch (e) {
-  NYC = require('../../index.js')
-}
+const NYC = require('../../index.js')
 
 exports.command = 'check-coverage'
 
diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js
index 7c098d9..fc49089 100644
--- a/lib/commands/instrument.js
+++ b/lib/commands/instrument.js
@@ -1,9 +1,4 @@
-var NYC
-try {
-  NYC = require('../../index.covered.js')
-} catch (e) {
-  NYC = require('../../index.js')
-}
+const NYC = require('../../index.js')
 
 exports.command = 'instrument <input> [output]'
 
@@ -51,6 +46,11 @@ exports.builder = function (yargs) {
       type: 'boolean',
       description: 'should nyc exit when an instrumentation failure occurs?'
     })
+    .option('es-modules', {
+      default: true,
+      type: 'boolean',
+      description: 'tell the instrumenter to treat files as ES Modules'
+    })
     .example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
 }
 
@@ -68,6 +68,7 @@ exports.handler = function (argv) {
     require: argv.require,
     compact: argv.compact,
     preserveComments: argv.preserveComments,
+    esModules: argv.esModules,
     exitOnError: argv.exitOnError
   })
 
diff --git a/lib/commands/merge.js b/lib/commands/merge.js
index 3f76248..072cfc4 100644
--- a/lib/commands/merge.js
+++ b/lib/commands/merge.js
@@ -3,12 +3,7 @@ const fs = require('fs')
 const path = require('path')
 const makeDir = require('make-dir')
 
-var NYC
-try {
-  NYC = require('../../index.covered.js')
-} catch (e) {
-  NYC = require('../../index.js')
-}
+const NYC = require('../../index.js')
 
 exports.command = 'merge <input-directory> [output-file]'
 
diff --git a/lib/commands/report.js b/lib/commands/report.js
index 0b48d86..410058c 100644
--- a/lib/commands/report.js
+++ b/lib/commands/report.js
@@ -1,9 +1,4 @@
-var NYC
-try {
-  NYC = require('../../index.covered.js')
-} catch (e) {
-  NYC = require('../../index.js')
-}
+const NYC = require('../../index.js')
 
 exports.command = 'report'
 
diff --git a/package-lock.json b/package-lock.json
index 8ffc3f5..175be85 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,13 +13,13 @@
       }
     },
     "@babel/generator": {
-      "version": "7.3.2",
-      "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.3.2.tgz",
-      "integrity": "sha512-f3QCuPppXxtZOEm5GWPra/uYUjmNQlu9pbAD8D/9jze4pTY83rTtB1igTBSwvkeNlC5gR24zFFkz+2WHLFQhqQ==",
+      "version": "7.3.3",
+      "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.3.3.tgz",
+      "integrity": "sha512-aEADYwRRZjJyMnKN7llGIlircxTCofm3dtV5pmY6ob18MSIuipHpA2yZWkPlycwu5HJcx/pADS3zssd8eY7/6A==",
       "requires": {
-        "@babel/types": "^7.3.2",
+        "@babel/types": "^7.3.3",
         "jsesc": "^2.5.1",
-        "lodash": "^4.17.10",
+        "lodash": "^4.17.11",
         "source-map": "^0.5.0",
         "trim-right": "^1.0.1"
       }
@@ -61,9 +61,9 @@
       }
     },
     "@babel/parser": {
-      "version": "7.3.2",
-      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.3.2.tgz",
-      "integrity": "sha512-QzNUC2RO1gadg+fs21fi0Uu0OuGNzRKEmgCxoLNzbCdoprLwjfmZwzUrpUNfJPaVRwBpDY47A17yYEGWyRelnQ=="
+      "version": "7.3.3",
+      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.3.3.tgz",
+      "integrity": "sha512-xsH1CJoln2r74hR+y7cg2B5JCPaTh+Hd+EbBRk9nWGSNspuo6krjhX0Om6RnRQuIvFq8wVXCLKH3kwKDYhanSg=="
     },
     "@babel/template": {
       "version": "7.2.2",
@@ -92,12 +92,12 @@
       }
     },
     "@babel/types": {
-      "version": "7.3.2",
-      "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.3.2.tgz",
-      "integrity": "sha512-3Y6H8xlUlpbGR+XvawiH0UXehqydTmNmEpozWcXymqwcrwYAl5KMvKtQ+TF6f6E08V6Jur7v/ykdDSF+WDEIXQ==",
+      "version": "7.3.3",
+      "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.3.3.tgz",
+      "integrity": "sha512-2tACZ80Wg09UnPg5uGAOUvvInaqLk3l/IAhQzlxLQOIXacr6bMsra5SH6AWw/hIDRCSbCdHP2KzSOD+cT7TzMQ==",
       "requires": {
         "esutils": "^2.0.2",
-        "lodash": "^4.17.10",
+        "lodash": "^4.17.11",
         "to-fast-properties": "^2.0.0"
       }
     },
@@ -124,9 +124,9 @@
       "dev": true
     },
     "ajv": {
-      "version": "6.9.1",
-      "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.9.1.tgz",
-      "integrity": "sha512-XDN92U311aINL77ieWHmqCcNlwjoP5cHXDxIxbf2MaPYuCXOHS7gHH8jktxeK5omgd52XbSTX6a4Piwd1pQmzA==",
+      "version": "6.9.2",
+      "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.9.2.tgz",
+      "integrity": "sha512-4UFy0/LgDo7Oa/+wOAlj44tp9K78u38E5/359eSrqEp1Z5PdVfimCcs7SluXMP755RUQu6d2b4AvF0R1C9RZjg==",
       "dev": true,
       "requires": {
         "fast-deep-equal": "^2.0.1",
@@ -292,7 +292,7 @@
         },
         "chalk": {
           "version": "1.1.3",
-          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "dev": true,
           "requires": {
@@ -311,7 +311,7 @@
         },
         "strip-ansi": {
           "version": "3.0.1",
-          "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
+          "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
           "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
           "dev": true,
           "requires": {
@@ -747,14 +747,25 @@
       }
     },
     "caching-transform": {
-      "version": "3.0.1",
-      "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-3.0.1.tgz",
-      "integrity": "sha512-Y1KTLNwSPd4ljsDrFOtyXVmm7Gnk42yQitNq43AhE+cwUR/e4T+rmOHs1IPtzBg8066GBJfTOj1rQYFSWSsH2g==",
+      "version": "3.0.2",
+      "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-3.0.2.tgz",
+      "integrity": "sha512-Mtgcv3lh3U0zRii/6qVgQODdPA4G3zhG+jtbCWj39RXuUFTMzH0vcdMtaJS1jPowd+It2Pqr6y3NJMQqOqCE2w==",
       "requires": {
         "hasha": "^3.0.0",
-        "make-dir": "^1.3.0",
+        "make-dir": "^2.0.0",
         "package-hash": "^3.0.0",
-        "write-file-atomic": "^2.3.0"
+        "write-file-atomic": "^2.4.2"
+      },
+      "dependencies": {
+        "make-dir": {
+          "version": "2.0.0",
+          "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.0.0.tgz",
+          "integrity": "sha512-DCZvJtCxpfY3a0Onp57Jm0PY9ggZENfVtBMsPdXFZDrMSHU5kYCMJkJesLr0/UrFdJKuDUYoGxCpc93n4F3Z8g==",
+          "requires": {
+            "pify": "^4.0.1",
+            "semver": "^5.6.0"
+          }
+        }
       }
     },
     "caller-path": {
@@ -1043,7 +1054,7 @@
         },
         "load-json-file": {
           "version": "1.1.0",
-          "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
+          "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
           "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
           "dev": true,
           "requires": {
@@ -1266,6 +1277,12 @@
             "pinkie-promise": "^2.0.0"
           }
         },
+        "get-stdin": {
+          "version": "4.0.1",
+          "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
+          "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=",
+          "dev": true
+        },
         "indent-string": {
           "version": "2.1.0",
           "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-2.1.0.tgz",
@@ -1277,7 +1294,7 @@
         },
         "load-json-file": {
           "version": "1.1.0",
-          "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
+          "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
           "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
           "dev": true,
           "requires": {
@@ -1314,7 +1331,7 @@
         },
         "minimist": {
           "version": "1.2.0",
-          "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
           "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
           "dev": true
         },
@@ -1425,9 +1442,9 @@
       "dev": true
     },
     "coveralls": {
-      "version": "3.0.2",
-      "resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.2.tgz",
-      "integrity": "sha512-Tv0LKe/MkBOilH2v7WBiTBdudg2ChfGbdXafc/s330djpF3zKOmuehTeRwjXWc7pzfj9FrDUTA7tEx6Div8NFw==",
+      "version": "3.0.3",
+      "resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.3.tgz",
+      "integrity": "sha512-viNfeGlda2zJr8Gj1zqXpDMRjw9uM54p7wzZdvLRyOgnAfCe974Dq4veZkjJdxQXbmdppu6flEajFYseHYaUhg==",
       "dev": true,
       "requires": {
         "growl": "~> 1.10.0",
@@ -1435,12 +1452,12 @@
         "lcov-parse": "^0.0.10",
         "log-driver": "^1.2.7",
         "minimist": "^1.2.0",
-        "request": "^2.85.0"
+        "request": "^2.86.0"
       },
       "dependencies": {
         "minimist": {
           "version": "1.2.0",
-          "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
           "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
           "dev": true
         }
@@ -1586,9 +1603,9 @@
       "dev": true
     },
     "diff": {
-      "version": "3.5.0",
-      "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
-      "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
+      "version": "1.4.0",
+      "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz",
+      "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=",
       "dev": true
     },
     "doctrine": {
@@ -1977,7 +1994,7 @@
         },
         "load-json-file": {
           "version": "2.0.0",
-          "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
+          "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
           "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
           "dev": true,
           "requires": {
@@ -2136,9 +2153,9 @@
       "dev": true
     },
     "esm": {
-      "version": "3.2.4",
-      "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.4.tgz",
-      "integrity": "sha512-wOuWtQCkkwD1WKQN/k3RsyGSSN+AmiUzdKftn8vaC+uV9JesYmQlODJxgXaaRz0LaaFIlUxZaUu5NPiUAjKAAA==",
+      "version": "3.2.5",
+      "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.5.tgz",
+      "integrity": "sha512-rukU6Nd3agbHQCJWV4rrlZxqpbO3ix8qhUxK1BhKALGS2E465O0BFwgCOqJjNnYfO/I2MwpUBmPsW8DXoe8tcA==",
       "dev": true
     },
     "espree": {
@@ -2228,7 +2245,7 @@
     },
     "external-editor": {
       "version": "2.2.0",
-      "resolved": "http://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz",
+      "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz",
       "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==",
       "dev": true,
       "requires": {
@@ -2327,7 +2344,7 @@
     },
     "foreground-child": {
       "version": "1.5.6",
-      "resolved": "http://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz",
+      "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz",
       "integrity": "sha1-T9ca0t/elnibmApcCilZN8svXOk=",
       "requires": {
         "cross-spawn": "^4",
@@ -2439,6 +2456,12 @@
             "pinkie-promise": "^2.0.0"
           }
         },
+        "get-stdin": {
+          "version": "4.0.1",
+          "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
+          "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=",
+          "dev": true
+        },
         "indent-string": {
           "version": "2.1.0",
           "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-2.1.0.tgz",
@@ -2450,7 +2473,7 @@
         },
         "load-json-file": {
           "version": "1.1.0",
-          "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
+          "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
           "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
           "dev": true,
           "requires": {
@@ -2487,7 +2510,7 @@
         },
         "minimist": {
           "version": "1.2.0",
-          "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
           "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
           "dev": true
         },
@@ -2584,9 +2607,9 @@
       }
     },
     "get-stdin": {
-      "version": "4.0.1",
-      "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
-      "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=",
+      "version": "6.0.0",
+      "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz",
+      "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==",
       "dev": true
     },
     "get-stream": {
@@ -2885,7 +2908,7 @@
     },
     "is-obj": {
       "version": "1.0.1",
-      "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
+      "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
       "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=",
       "dev": true
     },
@@ -2981,9 +3004,9 @@
       "dev": true
     },
     "istanbul-api": {
-      "version": "2.1.0",
-      "resolved": "https://registry.npmjs.org/istanbul-api/-/istanbul-api-2.1.0.tgz",
-      "integrity": "sha512-+Ygg4t1StoiNlBGc6x0f8q/Bv26FbZqP/+jegzfNpU7Q8o+4ZRoJxJPhBkgE/UonpAjtxnE4zCZIyJX+MwLRMQ==",
+      "version": "2.1.1",
+      "resolved": "https://registry.npmjs.org/istanbul-api/-/istanbul-api-2.1.1.tgz",
+      "integrity": "sha512-kVmYrehiwyeBAk/wE71tW6emzLiHGjYIiDrc8sfyty4F8M02/lrgXSm+R1kXysmF20zArvmZXjlE/mg24TVPJw==",
       "requires": {
         "async": "^2.6.1",
         "compare-versions": "^3.2.1",
@@ -2993,7 +3016,7 @@
         "istanbul-lib-instrument": "^3.1.0",
         "istanbul-lib-report": "^2.0.4",
         "istanbul-lib-source-maps": "^3.0.2",
-        "istanbul-reports": "^2.1.0",
+        "istanbul-reports": "^2.1.1",
         "js-yaml": "^3.12.0",
         "make-dir": "^1.3.0",
         "minimatch": "^3.0.4",
@@ -3188,6 +3211,13 @@
         "parse-json": "^4.0.0",
         "pify": "^3.0.0",
         "strip-bom": "^3.0.0"
+      },
+      "dependencies": {
+        "pify": {
+          "version": "3.0.0",
+          "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
+          "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
+        }
       }
     },
     "locate-path": {
@@ -3274,6 +3304,13 @@
       "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
       "requires": {
         "pify": "^3.0.0"
+      },
+      "dependencies": {
+        "pify": {
+          "version": "3.0.0",
+          "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
+          "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
+        }
       }
     },
     "make-error": {
@@ -3344,7 +3381,7 @@
         },
         "minimist": {
           "version": "1.2.0",
-          "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
           "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
           "dev": true
         },
@@ -3429,7 +3466,7 @@
     },
     "minimist": {
       "version": "0.0.10",
-      "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
+      "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
       "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8="
     },
     "minimist-options": {
@@ -3462,7 +3499,7 @@
     },
     "mkdirp": {
       "version": "0.5.1",
-      "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
+      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
       "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
       "requires": {
         "minimist": "0.0.8"
@@ -3470,7 +3507,7 @@
       "dependencies": {
         "minimist": {
           "version": "0.0.8",
-          "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
           "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
         }
       }
@@ -4775,6 +4812,13 @@
       "integrity": "sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==",
       "requires": {
         "pify": "^3.0.0"
+      },
+      "dependencies": {
+        "pify": {
+          "version": "3.0.0",
+          "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
+          "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
+        }
       }
     },
     "pathval": {
@@ -4790,9 +4834,9 @@
       "dev": true
     },
     "pify": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
-      "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
+      "version": "4.0.1",
+      "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz",
+      "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g=="
     },
     "pinkie": {
       "version": "2.0.4",
@@ -4963,9 +5007,9 @@
       "dev": true
     },
     "react-is": {
-      "version": "16.8.2",
-      "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.2.tgz",
-      "integrity": "sha512-D+NxhSR2HUCjYky1q1DwpNUD44cDpUXzSmmFyC3ug1bClcU/iDNy0YNn1iwme28fn+NFhpA13IndOd42CrFb+Q==",
+      "version": "16.8.3",
+      "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.3.tgz",
+      "integrity": "sha512-Y4rC1ZJmsxxkkPuMLwvKvlL1Zfpbcu+Bf4ZigkHup3v9EfdYhAlWAaVyA19olXq2o2mGn0w+dFKvk3pVVlYcIA==",
       "dev": true
     },
     "read-pkg": {
@@ -4989,7 +5033,7 @@
     },
     "readable-stream": {
       "version": "2.3.6",
-      "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
+      "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
       "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
       "dev": true,
       "requires": {
@@ -5348,15 +5392,9 @@
         "pkg-conf": "^2.0.0"
       },
       "dependencies": {
-        "get-stdin": {
-          "version": "6.0.0",
-          "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz",
-          "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==",
-          "dev": true
-        },
         "minimist": {
           "version": "1.2.0",
-          "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+          "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
           "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
           "dev": true
         }
@@ -5398,7 +5436,7 @@
         },
         "chalk": {
           "version": "1.1.3",
-          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "dev": true,
           "requires": {
@@ -5510,7 +5548,7 @@
         },
         "load-json-file": {
           "version": "2.0.0",
-          "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
+          "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
           "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
           "dev": true,
           "requires": {
@@ -5621,7 +5659,7 @@
         },
         "strip-ansi": {
           "version": "3.0.1",
-          "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
+          "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
           "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
           "dev": true,
           "requires": {
@@ -5749,9 +5787,9 @@
       }
     },
     "tap": {
-      "version": "12.5.2",
-      "resolved": "https://registry.npmjs.org/tap/-/tap-12.5.2.tgz",
-      "integrity": "sha512-r1uXuQ39+EnnR4hqWDTKw854+2ZSGR6QUEZwVRfabqcnhoNmkPQfiJCaVyhw+DILuMcJyT2/VRTVzn6puxkJ6w==",
+      "version": "12.5.3",
+      "resolved": "https://registry.npmjs.org/tap/-/tap-12.5.3.tgz",
+      "integrity": "sha512-st6Tkj4iL2dqucFngl82IK+mUrY/FQETNCWMN2Kfred38vznzjDTUXrpivE1RegzwwyXetJLCHgdycpSVTiMsw==",
       "dev": true,
       "requires": {
         "bind-obj-methods": "^2.0.0",
@@ -5770,7 +5808,7 @@
         "js-yaml": "^3.12.1",
         "minipass": "^2.3.5",
         "mkdirp": "^0.5.1",
-        "nyc": "^13.2.0",
+        "nyc": "^13.3.0",
         "opener": "^1.5.1",
         "os-homedir": "^1.0.2",
         "own-or": "^1.0.0",
@@ -5791,9 +5829,9 @@
       }
     },
     "tap-mocha-reporter": {
-      "version": "3.0.7",
-      "resolved": "https://registry.npmjs.org/tap-mocha-reporter/-/tap-mocha-reporter-3.0.7.tgz",
-      "integrity": "sha512-GHVXJ38C3oPRpM3YUc43JlGdpVZYiKeT1fmAd3HH2+J+ZWwsNAUFvRRdoGsXLw9+gU9o+zXpBqhS/oXyRQYwlA==",
+      "version": "3.0.9",
+      "resolved": "https://registry.npmjs.org/tap-mocha-reporter/-/tap-mocha-reporter-3.0.9.tgz",
+      "integrity": "sha512-VO07vhC9EG27EZdOe7bWBj1ldbK+DL9TnRadOgdQmiQOVZjFpUEQuuqO7+rNSO2kfmkq5hWeluYXDWNG/ytXTQ==",
       "dev": true,
       "requires": {
         "color-support": "^1.1.0",
@@ -5816,12 +5854,6 @@
             "ms": "2.0.0"
           }
         },
-        "diff": {
-          "version": "1.4.0",
-          "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz",
-          "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=",
-          "dev": true
-        },
         "ms": {
           "version": "2.0.0",
           "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@@ -5877,7 +5909,7 @@
     },
     "through": {
       "version": "2.3.8",
-      "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
+      "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
       "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
       "dev": true
     },
@@ -5972,6 +6004,14 @@
         "make-error": "^1.1.1",
         "source-map-support": "^0.5.6",
         "yn": "^3.0.0"
+      },
+      "dependencies": {
+        "diff": {
+          "version": "3.5.0",
+          "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
+          "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
+          "dev": true
+        }
       }
     },
     "tsame": {
@@ -6017,9 +6057,9 @@
       "dev": true
     },
     "typescript": {
-      "version": "3.3.3",
-      "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.3.tgz",
-      "integrity": "sha512-Y21Xqe54TBVp+VDSNbuDYdGw0BpoR/Q6wo/+35M8PAU0vipahnyduJWirxxdxjsAkS7hue53x2zp8gz7F05u0A==",
+      "version": "3.3.3333",
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.3333.tgz",
+      "integrity": "sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw==",
       "dev": true
     },
     "uglify-js": {
@@ -6064,7 +6104,7 @@
         },
         "strip-ansi": {
           "version": "3.0.1",
-          "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
+          "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
           "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
           "dev": true,
           "requires": {
@@ -6145,7 +6185,7 @@
     },
     "wrap-ansi": {
       "version": "2.1.0",
-      "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
+      "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
       "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=",
       "requires": {
         "string-width": "^1.0.1",
@@ -6177,7 +6217,7 @@
         },
         "strip-ansi": {
           "version": "3.0.1",
-          "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
+          "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
           "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
           "requires": {
             "ansi-regex": "^2.0.0"
diff --git a/package.json b/package.json
index 2325124..cb85361 100644
--- a/package.json
+++ b/package.json
@@ -5,11 +5,12 @@
   "main": "index.js",
   "scripts": {
     "bundle": "bundle-dependencies update",
+    "pretest": "npm run clean && npm run instrument",
+    "test": "tap -t360 --no-cov -b ./test/*.js && npm run report",
     "posttest": "standard",
-    "test": "npm run clean && npm run instrument && tap -t360 --no-cov -b ./test/*.js && npm run report",
-    "clean": "rimraf ./.nyc_output ./node_modules/.cache ./.self_coverage ./test/fixtures/.nyc_output ./test/fixtures/node_modules/.cache *covered.js ./lib/*covered.js",
+    "clean": "rimraf ./.nyc_output ./node_modules/.cache ./.self_coverage ./test/fixtures/.nyc_output ./test/fixtures/node_modules/.cache ./self-coverage",
     "instrument": "node ./build-self-coverage.js",
-    "report": "node ./bin/nyc  --temp-dir ./.self_coverage/ -r text -r lcov report",
+    "report": "node ./self-coverage/bin/nyc report --temp-dir ./.self_coverage/ -r text -r lcov",
     "release": "standard-version"
   },
   "bin": {
@@ -18,22 +19,19 @@
   "files": [
     "index.js",
     "bin/*.js",
-    "lib/*.js",
-    "lib/commands/*.js",
-    "lib/instrumenters/*.js",
-    "!**/*covered.js"
+    "lib/**/*.js"
   ],
   "nyc": {
     "exclude": [
       "node_modules",
       "bin",
       "coverage",
+      "self-coverage",
       "test/fixtures/coverage.js",
       "test/build/*",
       "test/src/*",
       "test/nyc.js",
       "test/process-args.js",
-      "index.covered.js",
       "test/fixtures/_generateCoverage.js"
     ]
   },
diff --git a/lib/self-coverage-helper.js b/self-coverage-helper.js
similarity index 88%
rename from lib/self-coverage-helper.js
rename to self-coverage-helper.js
index d4d2d2c..9eeeb68 100644
--- a/lib/self-coverage-helper.js
+++ b/self-coverage-helper.js
@@ -10,7 +10,7 @@ onExit(function () {
   if (typeof ___NYC_SELF_COVERAGE___ === 'object') coverage = ___NYC_SELF_COVERAGE___
   if (!coverage) return
 
-  var selfCoverageDir = path.join(__dirname, '../.self_coverage')
+  var selfCoverageDir = path.join(__dirname, '.self_coverage')
   mkdirp.sync(selfCoverageDir)
   fs.writeFileSync(
     path.join(selfCoverageDir, process.pid + '.json'),


Test patch:
diff --git a/test/nyc-integration.js b/test/nyc-integration.js
index aa6b9a3..37df86a 100644
--- a/test/nyc-integration.js
+++ b/test/nyc-integration.js
@@ -1,8 +1,8 @@
-/* global describe, it, beforeEach */
+/* global describe, it, beforeEach, afterEach */
 
 const _ = require('lodash')
 const path = require('path')
-const bin = path.resolve(__dirname, '../bin/nyc')
+const bin = path.resolve(__dirname, '../self-coverage/bin/nyc')
 const fixturesCLI = path.resolve(__dirname, './fixtures/cli')
 const fixturesHooks = path.resolve(__dirname, './fixtures/hooks')
 const fixturesSourceMaps = path.resolve(__dirname, './fixtures/source-maps')
@@ -480,7 +480,7 @@ describe('the nyc cli', function () {
 
         proc.on('close', function (code) {
           code.should.equal(0)
-          stdout.should.match(/path:"\.\/half-covered\.js"/)
+          stdout.should.contain(`path:${JSON.stringify(path.resolve(fixturesCLI, 'half-covered.js'))}`)
           done()
         })
       })
@@ -600,6 +600,53 @@ describe('the nyc cli', function () {
           done()
         })
       })
+
+      describe('es-modules', function () {
+        afterEach(function () {
+          rimraf.sync(path.resolve(fixturesCLI, './output'))
+        })
+
+        it('instruments file with `package` keyword when es-modules is disabled', function (done) {
+          const args = [bin, 'instrument', '--no-es-modules', './not-strict.js', './output']
+
+          const proc = spawn(process.execPath, args, {
+            cwd: fixturesCLI,
+            env: env
+          })
+
+          proc.on('close', function (code) {
+            code.should.equal(0)
+            const subdirExists = fs.existsSync(path.resolve(fixturesCLI, './output'))
+            subdirExists.should.equal(true)
+            const files = fs.readdirSync(path.resolve(fixturesCLI, './output'))
+            files.should.include('not-strict.js')
+            done()
+          })
+        })
+
+        it('fails on file with `package` keyword when es-modules is enabled', function (done) {
+          const args = [bin, 'instrument', '--exit-on-error', './not-strict.js', './output']
+
+          const proc = spawn(process.execPath, args, {
+            cwd: fixturesCLI,
+            env: env
+          })
+
+          let stderr = ''
+          proc.stderr.on('data', function (chunk) {
+            stderr += chunk
+          })
+
+          proc.on('close', function (code) {
+            code.should.equal(1)
+            stdoutShouldEqual(stderr, `
+              Failed to instrument ./not-strict.js`)
+            const subdirExists = fs.existsSync(path.resolve(fixturesCLI, './output'))
+            subdirExists.should.equal(false)
+            done()
+          })
+        })
+      })
     })
   })
 
diff --git a/test/src/nyc-tap.js b/test/src/nyc-tap.js
index ac31015..1cf3843 100644
--- a/test/src/nyc-tap.js
+++ b/test/src/nyc-tap.js
@@ -8,12 +8,7 @@ const configUtil = require('../../lib/config-util')
 const fs = require('fs')
 const enableCache = false
 
-let _NYC
-try {
-  _NYC = require('../../index.covered.js')
-} catch (e) {
-  _NYC = require('../../')
-}
+const _NYC = require('../../self-coverage')
 
 function NYC (opts) {
   opts = opts || {}
@@ -29,7 +24,7 @@ var rimraf = require('rimraf')
 var isWindows = require('is-windows')()
 var spawn = require('child_process').spawn
 var fixtures = path.resolve(__dirname, '../fixtures')
-var bin = path.resolve(__dirname, '../../bin/nyc')
+var bin = path.resolve(__dirname, '../../self-coverage/bin/nyc')
 
 // beforeEach
 glob.sync('**/*/{.nyc_output,.cache}').forEach(function (path) {
@@ -41,6 +36,8 @@ delete process.env.NYC_CWD
 require('chai').should()
 require('tap').mochaGlobals()
 
+const transpileHook = path.resolve(process.cwd(), './test/fixtures/transpile-hook')
+
 describe('nyc', function () {
   describe('cwd', function () {
     it('sets cwd to process.cwd() if no environment variable is set', function () {
@@ -402,7 +399,7 @@ describe('nyc', function () {
         'utf-8'
       )
 
-      var nyc = (new NYC(configUtil.buildYargs(fixtures).parse(['--require', './test/fixtures/transpile-hook'])))
+      var nyc = (new NYC(configUtil.buildYargs(fixtures).parse(['--require', transpileHook])))
       nyc.reset()
       nyc.addAllFiles()
 
@@ -428,7 +425,7 @@ describe('nyc', function () {
       )
 
       var nyc = (new NYC(configUtil.buildYargs(fixtures).parse([
-        '--require=./test/fixtures/transpile-hook',
+        `--require=${transpileHook}`,
         '--extension=.do-not-transpile',
         '--include=needs-transpile.do-not-transpile'
       ])))
@@ -448,7 +445,7 @@ describe('nyc', function () {
     )
 
     var nyc = (new NYC(configUtil.buildYargs(fixtures).parse([
-      '--require=./test/fixtures/transpile-hook',
+      `--require=${transpileHook}`,
       '--extension=.whatever'
     ])))