Git Product home page Git Product logo

test-exclude's Introduction

IstanbulJS

Build Status Conventional Commits community slack

Having problems? want to contribute? join our community slack.

Everyone's favorite JS code coverage tool.

About this Repo

This monorepo contains the nuts and bolts utility libraries that facilitate IstanbulJS test coverage; Why a monorepo?

  • it allows us to more easily test API changes across coupled modules, e.g., changes to istanbul-lib-coverage potentially have an effect on istanbul-lib-instrument.
  • it gives us a centralized repo for discussions about bugs and upcoming features.

Where Should I Start

You're probably actually looking for one of the following repos:

  • nyc: the IstanbulJS 2.0 command line interface, providing painless coverage support for most popular testing frameworks.
  • babel-plugin-istanbul: a babel plugin for instrumenting your ES2015+ code with Istanbul compatible coverage tracking.
  • istanbul: the legacy 1.0 IstanbulJS interface (you should now consider instead using nyc or babel-plugin-istanbul).

Contributing

Contributing to the packages contained in this repo is easy:

  1. after checking out, run npm install (this will run the lerna build).
  2. to run all tests, simply run npm test in the root directory.
  3. to run tests for a single package cd package/:name and run npm test within the package's folder.

test-exclude's People

Contributors

aaronabramov avatar bcoe avatar coreyfarrell avatar greenkeeper[bot] avatar greenkeeperio-bot avatar hershmire avatar jakxz avatar linusu avatar lukeapage avatar mojavelinux avatar popomore avatar schutm avatar shernshiou avatar shinnn avatar temyers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

test-exclude's Issues

Windows: undefined path resolution for directory junctions

This case is from istanbuljs/nyc#554. Reopened here as suggested by @bcoe. Anything mentioned there applies. All files listings and version info located at Gist. More specifics follows:

Problem: directory junctions on windows systems do not excluded from paths correctly.

Description & Case:

First, a structure example. Here, dir is simple directory, while junc is junction to dir (made with mklink /j junc dir)

`-- expr
  +-- dir
  | `-- foo.js
  +-- junc >> dir
  +-- main.js
  `-- package.json

main.js is simple test:

const assert = require('assert')

const exclude = require('test-exclude')

const junctionOnly = exclude({
  exclude: ['dir/']
})

assert.strictEqual(false, junctionOnly.shouldInstrument('dir/foo.js')) // GOOD
assert.strictEqual(true, junctionOnly.shouldInstrument('junc/foo.js')) // GOOD

const plainDirOnly = exclude({
  exclude: ['foo/']
})

assert.strictEqual(true, plainDirOnly.shouldInstrument('dir/foo.js')) // GOOD
assert.strictEqual(false, plainDirOnly.shouldInstrument('junc/foo.js')) // BAD

You can see that assert fails at excluding junctioned path.

option to not exclude anything

i wonder why there has to be a check for a not-empty array over here
https://github.com/istanbuljs/test-exclude/blob/master/index.js#L21

  if (!this.exclude || (Array.isArray(this.exclude) && !this.exclude.length)) {
    this.exclude = [
      'test/**',
      'test{,-*}.js',
      '**/*.test.js',
      '**/__tests__/**'
    ]
  }

i'm trying to test the instrumentation code and obviously it gets excluded :)
All i'm trying to do is to configure the babel-plugin-istanbul to not exclude anything

babel.transform(content, {
  filename,
  plugins: [[babelPluginIstanbul, {exclude: []}]],
}).code;

but because of this check, the excludes get their default value.

can it be just

if (!Array.isArray(this.exclude)) {
  //  this.exclude = ...
}

`options.cwd` should use the canonical pathname

TextExclude.shouldInstrument(filename) returns false when options.relativePath is true and filename is not inside options.cwd.

However:

  • when options.cwd is a symlink and is passed with its symlink unresolved
  • but filename resolves the symlink (through fs.realpath() for example)
  • then shouldInstrument() will return false even though it should return true.

This is likely to happen since:

  • the filename passed by nyc always has symlinks resolved because that's how module._compile() works
  • however nyc user might pass a options.cwd that has an unresolved symlink.

Real-life example: running the following on Travis on Mac OS:

const os = require('os');
const execa = require('execa');

const cwd = os.tmpdir();
await execa.shell(`nyc --cwd ${cwd}`)

Travis Mac OS environment:

  • returns /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T with os.tmpdir()
  • but this directory is a symlink for /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T
  • as a consequence all filename passed to testExclude.shouldInstrument() will start with /private/var/..., while options.cwd() will start with /var/..., even though it's the same folder.

One possible solution would be to run fs.realpath() on both filename and options.cwd() before comparing them.

Support Glob 10.

Hello,
text-exclude currently requires Glob 7, which includes Inflight, which has a security issue: CWE-772. Inflight will not be fixed and the developer encourages everyone to upgrade to Glob 9 or 10, which don't have the dependency. Currently, overriding Glob to use 10 causes test-exclude to throw an error when used in Jest.

TypeError: The "original" argument must be of type function. Received an instance of Object

      at Object.<anonymous> (node_modules/test-exclude/index.js:5:14)
      at Object.<anonymous> (node_modules/babel-plugin-istanbul/lib/index.js:18:43)

This would cause tests in Jest to break if developers try to mitigate the security bulletin.
Using Glob 9 currently works, but then other packages break, so it would be great if test-exclude could use the latest.

The filename field should be compatible?

in the 'index.js' file
in the function shouldInstrument

if (
      this.extension &&
      !this.extension.some(ext => filename.endsWith(ext))
  ) {
      return false;
  }

sometimes filename is undefined then report error

image

Can it be changed to !this.extension.some(ext => filename && filename.endsWith(ext))

test-exclude: README issues

  • The first argument of shouldInstrument needs to be an absolute filename.
  • Need to document excludeNodeModules: false as the preferred method of not excluding node_modules.
  • Overall need more complete API documentation. Can we use JS docs or something to generate documentation?

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

Using node:latest and "nyc": "^15.1.0" bumps into the following error due to your library:

./node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/.bin/mocha tests --timeout 10000 --recursive --check-leaks --exit  --reporter mocha-junit-reporter --reporter-options mochaFile=test_reports/mocha/test-results.xml
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module 'read-pkg-up'
Require stack:
- /root/workspace/node_modules/test-exclude/index.js
- /root/workspace/node_modules/nyc/lib/config-util.js
- /root/workspace/node_modules/nyc/bin/nyc.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/root/workspace/node_modules/test-exclude/index.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/root/workspace/node_modules/test-exclude/index.js',
    '/root/workspace/node_modules/nyc/lib/config-util.js',
    '/root/workspace/node_modules/nyc/bin/nyc.js'
  ]
}

Exited with code exit status 1
./node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/.bin/mocha tests --timeout 10000 --recursive --check-leaks --exit  --reporter mocha-junit-reporter --reporter-options mochaFile=test_reports/mocha/test-results.xml
node:internal/modules/cjs/loader:1109
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /root/workspace/node_modules/read-pkg-up/index.js
require() of ES modules is not supported.
require() of /root/workspace/node_modules/read-pkg-up/index.js from /root/workspace/node_modules/test-exclude/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /root/workspace/node_modules/read-pkg-up/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /root/workspace/node_modules/read-pkg-up/package.json.

    at new NodeError (node:internal/errors:329:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1109:13)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/root/workspace/node_modules/test-exclude/index.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32) {
  code: 'ERR_REQUIRE_ESM'
}

Exited with code exit status 1

Any advice and insight is appreciated. sindresorhus/read-package-up#18

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.