Skip to content

Commit

Permalink
feat: Remove configuration loading functionality (#398)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove configuration loading functionality

Fixes #392
  • Loading branch information
coreyfarrell committed May 10, 2019
1 parent e6f40bb commit f5c93c3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 161 deletions.
22 changes: 0 additions & 22 deletions packages/test-exclude/README.md
Expand Up @@ -16,28 +16,6 @@ if (exclude().shouldInstrument('./foo.js')) {
}
```

_you can load configuration from a key in package.json:_

_package.json_

```json
{
"name": "awesome-module",
"test": {
"include": ["**/index.js"]
}
}
```

_app.js_

```js
const exclude = require('test-exclude');
if (exclude({ configKey: 'test' }).shouldInstrument('./index.js')) {
// let's instrument this file for test coverage!
}
```

## Including node_modules folder

by default the `node_modules` folder is added to all groups of
Expand Down
22 changes: 0 additions & 22 deletions packages/test-exclude/index.js
Expand Up @@ -3,8 +3,6 @@
const path = require('path');
const glob = require('glob');
const minimatch = require('minimatch');
const readPkgUp = require('read-pkg-up');
const requireMainFilename = require('require-main-filename');
const defaultExclude = require('./default-exclude');

class TestExclude {
Expand All @@ -15,9 +13,6 @@ class TestExclude {
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
},
Expand All @@ -41,10 +36,6 @@ class TestExclude {
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 = defaultExclude;
}
Expand Down Expand Up @@ -117,19 +108,6 @@ class TestExclude {
);
}

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) {
const globPatterns = getExtensionPattern(this.extension || []);
const globOptions = { cwd, nodir: true, dot: true };
Expand Down
6 changes: 2 additions & 4 deletions packages/test-exclude/package.json
@@ -1,7 +1,7 @@
{
"name": "test-exclude",
"version": "5.2.3",
"description": "test for inclusion or exclusion of paths using pkg-conf and globs",
"description": "test for inclusion or exclusion of paths using globs",
"main": "index.js",
"files": [
"*.js"
Expand All @@ -28,9 +28,7 @@
"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"
"minimatch": "^3.0.4"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
114 changes: 1 addition & 113 deletions packages/test-exclude/test/test-exclude.js
@@ -1,6 +1,5 @@
/* global describe, it, context */
/* global describe, it */

const { spawnSync } = require('child_process');
const path = require('path');
const exclude = require('../');

Expand Down Expand Up @@ -236,117 +235,6 @@ describe('testExclude', () => {
]);
});

describe('pkgConf', () => {
it('should load exclude rules from config key', () => {
const e = exclude({
configPath: './test/fixtures/exclude',
configKey: 'a'
});

e.shouldInstrument('foo.js').should.equal(true);
e.shouldInstrument('batman.js').should.equal(false);
e.configFound.should.equal(true);
});

it('should load exclude rules from config key using process location', () => {
/* This needs to be a separate process so we resolve
* the correct package.json instead of trying to look
* at the package.json provided by mocha */
spawnSync(process.argv0, [
path.resolve(__dirname, 'fixtures/subprocess/bin/subprocess.js')
]).status.should.equal(0);
});

it('should load include rules from config key', () => {
const e = exclude({
configPath: './test/fixtures/include',
configKey: 'b'
});

e.shouldInstrument('foo.js').should.equal(false);
e.shouldInstrument('batman.js').should.equal(true);
e.configFound.should.equal(true);
});

it('should only instrument files that are included in subdirs', () => {
const e = exclude({
configPath: './test/fixtures/include-src-only',
configKey: 'c'
});
e.shouldInstrument('bar/baz.js').should.equal(false);
e.shouldInstrument('bad/file.js').should.equal(false);
e.shouldInstrument('foo.js').should.equal(false);

e.shouldInstrument('src/app.test.js').should.equal(false);
e.shouldInstrument('src/app.js').should.equal(true);
});

it('should respect defaultExcludes if no config is given', () => {
const e = exclude({
configPath: './test/fixtures/defaults',
configKey: 'd'
});

e.shouldInstrument('test.js').should.equal(false);
e.shouldInstrument('src/app.test.js').should.equal(false);
e.shouldInstrument('src/app-test.js').should.equal(false);

e.shouldInstrument(
'packages/package-name/test/test-utils.js'
).should.equal(false);

e.shouldInstrument('bar/baz.js').should.equal(true);
e.shouldInstrument('bad/file.js').should.equal(true);
e.shouldInstrument('foo.js').should.equal(true);
e.shouldInstrument('index.js').should.equal(true);
});

it('should not throw if a key is missing', () => {
const e = exclude({
configPath: './test/fixtures/include',
configKey: 'c'
});
e.configFound.should.equal(false);
});

context('when given an object', () => {
it('should use the defaultExcludes if the object is empty', () => {
const e = exclude({
configPath: './test/fixtures/exclude-empty-object',
configKey: 'e'
});

e.shouldInstrument('test.js').should.equal(false);
e.shouldInstrument('src/app.test.js').should.equal(false);

e.shouldInstrument('bar/baz.js').should.equal(true);
e.shouldInstrument('bad/file.js').should.equal(true);
e.shouldInstrument('foo.js').should.equal(true);
e.shouldInstrument('index.js').should.equal(true);
});

it('should use the defaultExcludes if the object is not empty', () => {
const e = exclude({
configPath: './test/fixtures/exclude-object',
configKey: 'e'
});

e.shouldInstrument('test.js').should.equal(false);
e.shouldInstrument('src/app.test.js').should.equal(false);
e.shouldInstrument('src/app-test.js').should.equal(false);

e.shouldInstrument(
'packages/package-name/test/test-utils.js'
).should.equal(false);

e.shouldInstrument('bar/baz.js').should.equal(true);
e.shouldInstrument('bad/file.js').should.equal(true);
e.shouldInstrument('foo.js').should.equal(true);
e.shouldInstrument('index.js').should.equal(true);
});
});
});

describe('globSync', () => {
const cwd = path.resolve(__dirname, 'fixtures/glob');
const extension = '.js';
Expand Down

0 comments on commit f5c93c3

Please sign in to comment.