test-exclude
Advanced tools
Comparing version 5.2.3 to 6.0.0-alhpa.3
@@ -1,6 +0,57 @@ | ||
# Change Log | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## [6.0.0-alhpa.3](https://github.com/istanbuljs/test-exclude/compare/v6.0.0-alpha.2...v6.0.0-alhpa.3) (2019-12-08) | ||
### Bug Fixes | ||
* Ignore options that are explicitly set undefined. ([#40](https://github.com/istanbuljs/test-exclude/issues/40)) ([b57e936](https://github.com/istanbuljs/test-exclude/commit/b57e9368aacdd548981ffd2ab6447bbd2c1e7de0)) | ||
## [6.0.0-alpha.2](https://github.com/istanbuljs/test-exclude/compare/v6.0.0-alpha.1...v6.0.0-alpha.2) (2019-12-07) | ||
### ⚠ BREAKING CHANGES | ||
* `test-exclude` now exports a class so it is necessary | ||
to use `new TestExclude()` when creating an instance. | ||
### Bug Fixes | ||
* Directly export class, document API. ([#39](https://github.com/istanbuljs/test-exclude/issues/39)) ([3acc196](https://github.com/istanbuljs/test-exclude/commit/3acc196482e03be734effd110aa83a4e78d3ebde)), closes [#33](https://github.com/istanbuljs/test-exclude/issues/33) | ||
* Pull default settings from @istanbuljs/schema ([#38](https://github.com/istanbuljs/test-exclude/issues/38)) ([ffca696](https://github.com/istanbuljs/test-exclude/commit/ffca6968175c9030cebf018fb86d2c0386a61620)) | ||
## [6.0.0-alpha.1](https://github.com/istanbuljs/test-exclude/compare/v6.0.0-alpha.0...v6.0.0-alpha.1) (2019-09-24) | ||
### Features | ||
* Add async glob function ([#30](https://github.com/istanbuljs/test-exclude/issues/30)) ([e45ac10](https://github.com/istanbuljs/test-exclude/commit/e45ac10)) | ||
# [6.0.0-alpha.0](https://github.com/istanbuljs/istanbuljs/compare/test-exclude@5.2.3...test-exclude@6.0.0-alpha.0) (2019-06-19) | ||
### Bug Fixes | ||
* **win32:** Detect files on different drive as outside project ([#422](https://github.com/istanbuljs/istanbuljs/issues/422)) ([5b4ee88](https://github.com/istanbuljs/istanbuljs/commit/5b4ee88)), closes [#418](https://github.com/istanbuljs/istanbuljs/issues/418) | ||
* Ignore tests matching *.cjs, *.mjs and *.ts by default ([#381](https://github.com/istanbuljs/istanbuljs/issues/381)) ([0f077c2](https://github.com/istanbuljs/istanbuljs/commit/0f077c2)) | ||
### Features | ||
* ignore files under test**s** directories by default ([#419](https://github.com/istanbuljs/istanbuljs/issues/419)) ([8ad5fd2](https://github.com/istanbuljs/istanbuljs/commit/8ad5fd2)) | ||
* Remove configuration loading functionality ([#398](https://github.com/istanbuljs/istanbuljs/issues/398)) ([f5c93c3](https://github.com/istanbuljs/istanbuljs/commit/f5c93c3)), closes [#392](https://github.com/istanbuljs/istanbuljs/issues/392) | ||
* Update dependencies, require Node.js 8 ([#401](https://github.com/istanbuljs/istanbuljs/issues/401)) ([bf3a539](https://github.com/istanbuljs/istanbuljs/commit/bf3a539)) | ||
### BREAKING CHANGES | ||
* Node.js 8 is now required | ||
* Remove configuration loading functionality | ||
## [5.2.3](https://github.com/istanbuljs/istanbuljs/compare/test-exclude@5.2.2...test-exclude@5.2.3) (2019-04-24) | ||
@@ -7,0 +58,0 @@ |
87
index.js
@@ -0,24 +1,24 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const { promisify } = require('util'); | ||
const glob = promisify(require('glob')); | ||
const minimatch = require('minimatch'); | ||
const readPkgUp = require('read-pkg-up'); | ||
const requireMainFilename = require('require-main-filename'); | ||
const { defaults } = require('@istanbuljs/schema'); | ||
const isOutsideDir = require('./is-outside-dir'); | ||
class TestExclude { | ||
constructor(opts) { | ||
constructor(opts = {}) { | ||
Object.assign( | ||
this, | ||
{ | ||
cwd: process.cwd(), | ||
include: false, | ||
relativePath: true, | ||
configKey: null, // the key to load config from in package.json. | ||
configPath: null, // optionally override requireMainFilename. | ||
configFound: false, | ||
excludeNodeModules: true, | ||
extension: false | ||
}, | ||
opts | ||
{relativePath: true}, | ||
defaults.testExclude | ||
); | ||
for (const [name, value] of Object.entries(opts)) { | ||
if (value !== undefined) { | ||
this[name] = value; | ||
} | ||
} | ||
if (typeof this.include === 'string') { | ||
@@ -34,17 +34,6 @@ this.include = [this.include]; | ||
this.extension = [this.extension]; | ||
} else if ( | ||
!Array.isArray(this.extension) || | ||
this.extension.length === 0 | ||
) { | ||
} else if (this.extension.length === 0) { | ||
this.extension = false; | ||
} | ||
if (!this.include && !this.exclude && this.configKey) { | ||
Object.assign(this, this.pkgConf(this.configKey, this.configPath)); | ||
} | ||
if (!this.exclude || !Array.isArray(this.exclude)) { | ||
this.exclude = exportFunc.defaultExclude; | ||
} | ||
if (this.include && this.include.length > 0) { | ||
@@ -103,3 +92,3 @@ this.include = prepGlobPatterns([].concat(this.include)); | ||
// Don't instrument files that are outside of the current working directory. | ||
if (/^\.\./.test(path.relative(this.cwd, filename))) { | ||
if (isOutsideDir(this.cwd, filename)) { | ||
return false; | ||
@@ -119,15 +108,2 @@ } | ||
pkgConf(key, path) { | ||
const cwd = path || requireMainFilename(require); | ||
const obj = readPkgUp.sync({ cwd }); | ||
if (obj.pkg && obj.pkg[key] && typeof obj.pkg[key] === 'object') { | ||
this.configFound = true; | ||
return obj.pkg[key]; | ||
} | ||
return {}; | ||
} | ||
globSync(cwd = this.cwd) { | ||
@@ -146,2 +122,15 @@ const globPatterns = getExtensionPattern(this.extension || []); | ||
} | ||
async glob(cwd = this.cwd) { | ||
const globPatterns = getExtensionPattern(this.extension || []); | ||
const globOptions = { cwd, nodir: true, dot: true }; | ||
/* If we don't have any excludeNegated then we can optimize glob by telling | ||
* it to not iterate into unwanted directory trees (like node_modules). */ | ||
if (this.excludeNegated.length === 0) { | ||
globOptions.ignore = this.exclude; | ||
} | ||
const list = await glob(globPatterns, globOptions); | ||
return list.filter(file => this.shouldInstrument(path.resolve(cwd, file))); | ||
} | ||
} | ||
@@ -176,16 +165,2 @@ | ||
const exportFunc = opts => new TestExclude(opts); | ||
const devConfigs = ['ava', 'babel', 'jest', 'nyc', 'rollup', 'webpack']; | ||
exportFunc.defaultExclude = [ | ||
'coverage/**', | ||
'packages/*/test/**', | ||
'test/**', | ||
'test{,-*}.js', | ||
'**/*{.,-}test.js', | ||
'**/__tests__/**', | ||
`**/{${devConfigs.join()}}.config.js` | ||
]; | ||
module.exports = exportFunc; | ||
module.exports = TestExclude; |
{ | ||
"name": "test-exclude", | ||
"version": "5.2.3", | ||
"description": "test for inclusion or exclusion of paths using pkg-conf and globs", | ||
"version": "6.0.0-alhpa.3", | ||
"description": "test for inclusion or exclusion of paths using globs", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js" | ||
"*.js", | ||
"!nyc.config.js" | ||
], | ||
"scripts": { | ||
"test": "mocha" | ||
"release": "standard-version", | ||
"test": "nyc tap", | ||
"snap": "npm test -- --snapshot" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/istanbuljs/istanbuljs.git" | ||
"url": "git+https://github.com/istanbuljs/test-exclude.git" | ||
}, | ||
@@ -26,15 +29,18 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/istanbuljs/istanbuljs/issues" | ||
"url": "https://github.com/istanbuljs/test-exclude/issues" | ||
}, | ||
"homepage": "https://istanbul.js.org/", | ||
"dependencies": { | ||
"glob": "^7.1.3", | ||
"minimatch": "^3.0.4", | ||
"read-pkg-up": "^4.0.0", | ||
"require-main-filename": "^2.0.0" | ||
"@istanbuljs/schema": "^0.1.2", | ||
"glob": "^7.1.4", | ||
"minimatch": "^3.0.4" | ||
}, | ||
"devDependencies": { | ||
"nyc": "^14.1.1", | ||
"standard-version": "^7.0.0", | ||
"tap": "=14.10.2-unbundled" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"gitHead": "90e60cc47833bb780680f916488ca24f0be36ca2" | ||
"node": ">=8" | ||
} | ||
} |
# test-exclude | ||
The file include/exclude logic used by [nyc](https://github.com/istanbuljs/nyc). | ||
The file include/exclude logic used by [nyc] and [babel-plugin-istanbul]. | ||
@@ -13,3 +13,4 @@ [![Build Status](https://travis-ci.org/istanbuljs/test-exclude.svg)](https://travis-ci.org/istanbuljs/test-exclude) | ||
```js | ||
const exclude = require('test-exclude'); | ||
const TestExclude = require('test-exclude'); | ||
const exclude = new TestExclude(); | ||
if (exclude().shouldInstrument('./foo.js')) { | ||
@@ -20,39 +21,78 @@ // let's instrument this file for test coverage! | ||
_you can load configuration from a key in package.json:_ | ||
### TestExclude(options) | ||
_package.json_ | ||
The test-exclude constructor accepts an options object. The defaults are taken from | ||
[@istanbuljs/schema]. | ||
```json | ||
{ | ||
"name": "awesome-module", | ||
"test": { | ||
"include": ["**/index.js"] | ||
} | ||
} | ||
``` | ||
#### options.cwd | ||
_app.js_ | ||
This is the base directory by which all comparisons are performed. Files outside `cwd` | ||
are not included. | ||
```js | ||
const exclude = require('test-exclude'); | ||
if (exclude({ configKey: 'test' }).shouldInstrument('./index.js')) { | ||
// let's instrument this file for test coverage! | ||
} | ||
``` | ||
Default: `process.cwd()` | ||
## Including node_modules folder | ||
#### options.exclude | ||
by default the `node_modules` folder is added to all groups of | ||
exclude rules. In the rare case that you wish to instrument files | ||
stored in `node_modules`, a negative glob can be used: | ||
Array of path globs to be ignored. Note this list does not include `node_modules` which | ||
is added separately. See [@istanbuljs/schema/default-excludes.js] for default list. | ||
#### options.excludeNodeModules | ||
By default `node_modules` is excluded. Setting this option `true` allows `node_modules` | ||
to be included. | ||
#### options.include | ||
Array of path globs that can be included. By default this is unrestricted giving a result | ||
similar to `['**']` but more optimized. | ||
#### options.extension | ||
Array of extensions that can be included. This ensures that nyc only attempts to process | ||
files which it might understand. Note use of some formats may require adding parser | ||
plugins to your nyc or babel configuration. | ||
Default: `['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx']` | ||
### TestExclude#shouldInstrument(filename): boolean | ||
Test if `filename` matches the rules of this test-exclude instance. | ||
```js | ||
const exclude = require('test-exclude'); | ||
const e = exclude({ | ||
exclude: ['!**/node_modules/**'] | ||
}); | ||
const exclude = new TestExclude(); | ||
exclude.shouldInstrument('index.js'); // true | ||
exclude.shouldInstrument('test.js'); // false | ||
exclude.shouldInstrument('README.md'); // false | ||
exclude.shouldInstrument('node_modules/test-exclude/index.js'); // false | ||
``` | ||
## License | ||
In this example code: | ||
* `index.js` is true because it matches the default `options.extension` list | ||
and is not part of the default `options.exclude` list. | ||
* `test.js` is excluded because it matches the default `options.exclude` list. | ||
* `README.md` is not matched by the default `options.extension` | ||
* `node_modules/test-exclude/index.js` is excluded because `options.excludeNodeModules` | ||
is true by default. | ||
ISC | ||
### TestExculde#globSync(cwd = options.cwd): Array[string] | ||
This synchronously retrieves a list of files within `cwd` which should be instrumented. | ||
Note that setting `cwd` to a parent of `options.cwd` is ineffective, this argument can | ||
only be used to further restrict the result. | ||
### TestExclude#glob(cwd = options.cwd): Promise<Array[string]> | ||
This function does the same as `TestExclude#globSync` but does so asynchronously. The | ||
Promise resolves to an Array of strings. | ||
## `test-exclude` for enterprise | ||
Available as part of the Tidelift Subscription. | ||
The maintainers of `test-exclude` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-test-exclude?utm_source=npm-test-exclude&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) | ||
[nyc]: https://github.com/istanbuljs/nyc | ||
[babel-plugin-istanbul]: https://github.com/istanbuljs/babel-plugin-istanbul | ||
[@istanbuljs/schema]: https://github.com/istanbuljs/schema | ||
[@istanbuljs/schema/default-excludes.js]: https://github.com/istanbuljs/schema/blob/master/default-exclude.js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23203
3
8
97
3
151
1
+ Added@istanbuljs/schema@^0.1.2
+ Added@istanbuljs/schema@0.1.3(transitive)
- Removedread-pkg-up@^4.0.0
- Removedrequire-main-filename@^2.0.0
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@3.0.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedread-pkg@3.0.0(transitive)
- Removedread-pkg-up@4.0.0(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
Updatedglob@^7.1.4