Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create @istanbul/nyc-config-hook-run-in-this-context. (#332)
This base configuration helps enable `hook-run-in-this-context` in a way that instruments files loaded via `require()` only once regardless of node.js version.
- Loading branch information
1 parent
7f90f57
commit 3111b9d
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Copyright 2019 Contributors | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# nyc-config-hook-run-in-this-context | ||
|
||
Handy configuration for instrumenting with hook-run-in-this-context enabled. | ||
|
||
Prior to node.js 11.11.0 `require()` was implemented using `vm.runInThisContext()`. | ||
This meant that running with `hook-run-in-this-context` enabled required disabling | ||
`hook-require`. Starting with node 11.11.0 `require()` is no longer implemented | ||
with `vm.runInThisContext()`, so `hook-require` still needs to be enabled. This | ||
base configuration enables `hook-run-in-this-context` and provides the correct | ||
setting for `hook-require` to ensure that modules loaded by `require()` are | ||
instrumented once. | ||
|
||
First install the dependencies: | ||
|
||
`npm i nyc @istanbuljs/nyc-config-hook-run-in-this-context --save-dev` | ||
|
||
## .nycrc | ||
|
||
And write a `.nycrc` that looks like this: | ||
|
||
```json | ||
{ | ||
"extends": "@istanbuljs/nyc-config-hook-run-in-this-context", | ||
/* add custom settings */ | ||
} | ||
``` | ||
|
||
## License | ||
|
||
ISC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
const semver = require('semver'); | ||
|
||
module.exports = { | ||
'hook-require': !semver.lt(process.version, '11.11.0'), | ||
'hook-run-in-this-context': true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@istanbuljs/nyc-config-hook-run-in-this-context", | ||
"version": "0.1.0", | ||
"description": "nyc configuration for hook-run-in-this-context", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/istanbuljs/istanbuljs.git" | ||
}, | ||
"keywords": [ | ||
"hook", | ||
"config", | ||
"nyc", | ||
"test", | ||
"coverage" | ||
], | ||
"author": "Corey Farrell <git@cfware.com>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/istanbuljs/istanbuljs/issues" | ||
}, | ||
"homepage": "https://istanbul.js.org/", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/nyc-config-hook-run-in-this-context/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* global describe, it */ | ||
|
||
const assert = require('chai').assert; | ||
const index = require('../index'); | ||
|
||
describe('external interface', () => { | ||
it('exports the correct interface', () => { | ||
assert.equal(typeof index, 'object'); | ||
assert.ok('hook-require' in index); | ||
assert.equal(index['hook-run-in-this-context'], true); | ||
}); | ||
}); |