Skip to content

Commit

Permalink
Update snapshot and address review concerns
Browse files Browse the repository at this point in the history
The instrument --in-place test now runs in a copy of the instrument in place test directory, this means that running tests locally doesn't change your local environment.
  • Loading branch information
Andrew Finlay committed Jul 22, 2019
1 parent 6cfbdbb commit bfd6e62
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/instrument.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For example, `nyc instrument . ./output` will produce instrumented versions of a

The `--delete` option will remove the existing output directory before instrumenting.

The '--in-place' option will allow you to run the instrument command
The `--in-place` option will allow you to run the instrument command.

The `--complete-copy` option will copy all remaining files from the `input` directory to the `output` directory.
When using `--complete-copy` nyc will not copy the contents of a `.git` folder to the output directory.
Expand Down
9 changes: 8 additions & 1 deletion tap-snapshots/test-nyc-integration.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ All files | 0 | 0 | 0 | 0 |
test.js | 0 | 0 | 0 | 0 |
cli/fakebin | 0 | 100 | 100 | 0 |
npm-template.js | 0 | 100 | 100 | 0 | 2,3,4,7,9
cli/instrument-inplace | 0 | 100 | 0 | 0 |
file1.js | 0 | 100 | 0 | 0 | 2,5
file2.js | 0 | 100 | 0 | 0 | 2,5
cli/nyc-config-js | 0 | 0 | 100 | 0 |
ignore.js | 0 | 100 | 100 | 0 | 1
index.js | 0 | 0 | 100 | 0 | 1,3,5,7,8,9,10
Expand All @@ -126,7 +129,7 @@ exports[`test/nyc-integration.js TAP --ignore-class-method skips methods that ma
---------------------------------|---------|----------|---------|---------|-------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------------|---------|----------|---------|---------|-------------------------
All files | 1.49 | 0 | 5.56 | 1.96 |
All files | 1.45 | 0 | 5 | 1.89 |
cli | 2.08 | 0 | 5.56 | 3.13 |
args.js | 0 | 100 | 100 | 0 | 1
by-arg2.js | 0 | 0 | 100 | 0 | 1,2,3,4,5,7
Expand All @@ -144,6 +147,9 @@ All files | 1.49 | 0 | 5.56 | 1.96 |
skip-full.js | 0 | 100 | 100 | 0 | 1,2
cli/fakebin | 0 | 100 | 100 | 0 |
npm-template.js | 0 | 100 | 100 | 0 | 2,3,4,7,9
cli/instrument-inplace | 0 | 100 | 0 | 0 |
file1.js | 0 | 100 | 0 | 0 | 2,5
file2.js | 0 | 100 | 0 | 0 | 2,5
cli/nyc-config-js | 0 | 0 | 100 | 0 |
ignore.js | 0 | 100 | 100 | 0 | 1
index.js | 0 | 0 | 100 | 0 | 1,3,5,7,8,9,10
Expand Down Expand Up @@ -753,6 +759,7 @@ Failed to instrument ./not-strict.js
`

exports[`test/nyc-integration.js TAP nyc instrument fails on file with \`package\` keyword when es-modules is enabled > stdout 1`] = `
Running nyc from .
`

Expand Down
38 changes: 20 additions & 18 deletions test/nyc-integration-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fixturesCLI = path.resolve(__dirname, './fixtures/cli')
const fakebin = path.resolve(fixturesCLI, 'fakebin')
const fs = require('fs')
const isWindows = require('is-windows')()
const cpFile = require('cp-file')
const rimraf = require('rimraf')
const makeDir = require('make-dir')
const { spawn } = require('child_process')
Expand Down Expand Up @@ -325,11 +326,11 @@ describe('the nyc cli', function () {
})

it('aborts if trying to write files in place', function (done) {
const args = [bin, 'instrument', '--delete', './', './']
const args = [bin, 'instrument', './', './']

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

let stderr = ''
Expand All @@ -345,27 +346,28 @@ describe('the nyc cli', function () {
})

it('can write files in place with --in-place switch', function (done) {
const args = [bin, 'instrument', '--in-place', '--include', '*/file1.js', './instrument-inplace']
const args = [bin, 'instrument', '--in-place', '--include', '*/file1.js', './test-instrument-inplace']

const sourceDir = path.resolve(fixturesCLI, 'instrument-inplace')
const destDir = path.resolve(fixturesCLI, 'test-instrument-inplace')
makeDir.sync(destDir)
cpFile.sync(path.join(sourceDir, 'file1.js'), path.join(destDir, 'file1.js'))
cpFile.sync(path.join(sourceDir, 'file2.js'), path.join(destDir, 'file2.js'))

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
})

let stderr = ''
proc.stderr.on('data', function (chunk) {
stderr += chunk
env: env
})

proc.on('close', function (code) {
console.log(`stderr: ${stderr}`)
code.should.equal(0)
const file1 = path.resolve(fixturesCLI, 'instrument-inplace', 'file1.js')
const file1 = path.resolve(destDir, 'file1.js')
fs.readFileSync(file1, 'utf8')
.should.match(/var cov_/)
const file2 = path.resolve(fixturesCLI, 'instrument-inplace', 'file2.js')
const file2 = path.resolve(destDir, 'file2.js')
fs.readFileSync(file2, 'utf8')
.should.not.match(/var cov_/)
rimraf.sync(destDir)
done()
})
})
Expand All @@ -375,7 +377,7 @@ describe('the nyc cli', function () {

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

let stderr = ''
Expand All @@ -395,7 +397,7 @@ describe('the nyc cli', function () {

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

let stderr = ''
Expand All @@ -420,7 +422,7 @@ describe('the nyc cli', function () {

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

proc.on('close', function (code) {
Expand All @@ -439,7 +441,7 @@ describe('the nyc cli', function () {

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

proc.on('close', function (code) {
Expand All @@ -457,7 +459,7 @@ describe('the nyc cli', function () {

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

let stderr = ''
Expand All @@ -477,7 +479,7 @@ describe('the nyc cli', function () {

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
env: env
})

let stderr = ''
Expand Down

0 comments on commit bfd6e62

Please sign in to comment.