Skip to content

Commit

Permalink
Split PR such that this only handles `nyc instrument --include --excl…
Browse files Browse the repository at this point in the history
…ude`

Previously this was adding `nyc instrument` full copy of `src` to `dst` as well as `include`/`exclude`
The full copy work was proving troublesome so it's been moved to it's own branch/PR
This commit removes the full copy, removes now unused dependencies, and updates tests accordingly
  • Loading branch information
Andrew Finlay committed Apr 4, 2019
1 parent 6852bbf commit 8903365
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 57 deletions.
8 changes: 0 additions & 8 deletions index.js
Expand Up @@ -6,9 +6,7 @@ const arrify = require('arrify')
const cachingTransform = require('caching-transform')
const util = require('util')
const findCacheDir = require('find-cache-dir')
const { copySync } = require('fs-extra')
const fs = require('fs')
const glob = require('glob')
const Hash = require('./lib/hash')
const libCoverage = require('istanbul-lib-coverage')
const libHook = require('istanbul-lib-hook')
Expand Down Expand Up @@ -198,12 +196,6 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) {
if (stats.isDirectory()) {
inputDir = input
this.walkAllFiles(input, visitor)

if (output) {
const globOptions = { dot: true, ignore: ['**/.git', `**/${path.basename(output)}`] }
glob.sync(`${path.resolve(input)}/*`, globOptions)
.forEach(src => copySync(src, path.join(output, path.relative(input, src)), { overwrite: false }))
}
} else {
visitor(input)
}
Expand Down
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -74,8 +74,6 @@
"find-cache-dir": "^2.1.0",
"find-up": "^3.0.0",
"foreground-child": "^1.5.6",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"istanbul-lib-coverage": "^2.0.4",
"istanbul-lib-hook": "^2.0.5",
"istanbul-lib-instrument": "^3.1.2",
Expand All @@ -97,6 +95,7 @@
"any-path": "^1.3.0",
"chai": "^4.2.0",
"coveralls": "^3.0.3",
"glob": "^7.1.3",
"is-windows": "^1.0.2",
"lodash": "^4.17.11",
"newline-regex": "^0.2.1",
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/cli/subdir/input-dir/include-me/exclude-me.js
@@ -0,0 +1,2 @@
'use strict';
console.log('Hello, World!')
2 changes: 2 additions & 0 deletions test/fixtures/cli/subdir/input-dir/include-me/include-me.js
@@ -0,0 +1,2 @@
'use strict';
console.log('Hello, World!')
40 changes: 16 additions & 24 deletions test/nyc-integration.js
Expand Up @@ -687,8 +687,8 @@ describe('the nyc cli', function () {
const files = fs.readdirSync(path.resolve(fixturesCLI, './output'))
files.should.include('index.js')
files.should.include('ignore.js')
files.should.include('package.json')
files.should.include('node_modules')
files.should.not.include('package.json')
files.should.not.include('node_modules')
done()
})
})
Expand Down Expand Up @@ -738,13 +738,10 @@ describe('the nyc cli', function () {
code.should.equal(0)
const files = fs.readdirSync(path.resolve(fixturesCLI, './output'))
files.length.should.not.equal(0)
files.should.include('exclude-me')
files.should.include('node_modules')
files.should.not.include('exclude-me')
files.should.not.include('node_modules')
files.should.include('index.js')
files.should.include('bad.js')
const excludeTarget = path.resolve(fixturesCLI, 'output', 'exclude-me', 'index.js')
fs.readFileSync(excludeTarget, 'utf8')
.should.not.match(/var cov_/)
const includeTarget = path.resolve(fixturesCLI, 'output', 'index.js')
fs.readFileSync(includeTarget, 'utf8')
.should.match(/var cov_/)
Expand All @@ -764,16 +761,13 @@ describe('the nyc cli', function () {
code.should.equal(0)
const files = fs.readdirSync(path.resolve(fixturesCLI, './output'))
files.length.should.not.equal(0)
files.should.include('exclude-me')
const target = path.resolve(fixturesCLI, 'output', 'exclude-me', 'index.js')
fs.readFileSync(target, 'utf8')
.should.not.match(/var cov_/)
files.should.not.include('exclude-me')
done()
})
})

it('allows specifying a single sub-directory to be included', function (done) {
const args = [bin, 'instrument', '--include', '**/exclude-me/**', './subdir/input-dir', './output']
const args = [bin, 'instrument', '--include', '**/include-me/**', './subdir/input-dir', './output']

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
Expand All @@ -784,19 +778,16 @@ describe('the nyc cli', function () {
code.should.equal(0)
const files = fs.readdirSync(path.resolve(fixturesCLI, './output'))
files.length.should.not.equal(0)
files.should.include('exclude-me')
const instrumented = path.resolve(fixturesCLI, 'output', 'exclude-me', 'index.js')
files.should.include('include-me')
const instrumented = path.resolve(fixturesCLI, 'output', 'include-me', 'include-me.js')
fs.readFileSync(instrumented, 'utf8')
.should.match(/var cov_/)
const uninstrumented = path.resolve(fixturesCLI, 'output', 'index.js')
fs.readFileSync(uninstrumented, 'utf8')
.should.not.match(/var cov_/)
done()
})
})

it('allows a file to be excluded from an included directory', function (done) {
const args = [bin, 'instrument', '--exclude', '**/index.js', '--include', '**/exclude-me/**', './subdir/input-dir', './output']
const args = [bin, 'instrument', '--exclude', '**/exclude-me.js', '--include', '**/include-me/**', './subdir/input-dir', './output']

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
Expand All @@ -807,13 +798,14 @@ describe('the nyc cli', function () {
code.should.equal(0)
const files = fs.readdirSync(path.resolve(fixturesCLI, './output'))
files.length.should.not.equal(0)
files.should.include('exclude-me')
const instrumented = path.resolve(fixturesCLI, 'output', 'exclude-me', 'index.js')
files.should.include('include-me')
const includeMeFiles = fs.readdirSync(path.resolve(fixturesCLI, 'output', 'include-me'))
includeMeFiles.length.should.not.equal(0)
includeMeFiles.should.include('include-me.js')
includeMeFiles.should.not.include('exclude-me.js')
const instrumented = path.resolve(fixturesCLI, 'output', 'include-me', 'include-me.js')
fs.readFileSync(instrumented, 'utf8')
.should.not.match(/var cov_/)
const uninstrumented = path.resolve(fixturesCLI, 'output', 'index.js')
fs.readFileSync(uninstrumented, 'utf8')
.should.not.match(/var cov_/)
.should.match(/var cov_/)
done()
})
})
Expand Down

0 comments on commit 8903365

Please sign in to comment.