From bfd6e62e01dbc819926cbe5a9184ae895749def4 Mon Sep 17 00:00:00 2001 From: Andrew Finlay Date: Tue, 23 Jul 2019 08:42:05 +1000 Subject: [PATCH] Update snapshot and address review concerns 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. --- docs/instrument.md | 2 +- .../test-nyc-integration.js-TAP.test.js | 9 ++++- test/nyc-integration-old.js | 38 ++++++++++--------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/docs/instrument.md b/docs/instrument.md index 3467832df..bce1a3b4c 100644 --- a/docs/instrument.md +++ b/docs/instrument.md @@ -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. diff --git a/tap-snapshots/test-nyc-integration.js-TAP.test.js b/tap-snapshots/test-nyc-integration.js-TAP.test.js index 46353911f..1dc835a78 100644 --- a/tap-snapshots/test-nyc-integration.js-TAP.test.js +++ b/tap-snapshots/test-nyc-integration.js-TAP.test.js @@ -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 @@ -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 @@ -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 @@ -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 . ` diff --git a/test/nyc-integration-old.js b/test/nyc-integration-old.js index 0acb1660c..40041876f 100644 --- a/test/nyc-integration-old.js +++ b/test/nyc-integration-old.js @@ -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') @@ -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 = '' @@ -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() }) }) @@ -375,7 +377,7 @@ describe('the nyc cli', function () { const proc = spawn(process.execPath, args, { cwd: fixturesCLI, - env + env: env }) let stderr = '' @@ -395,7 +397,7 @@ describe('the nyc cli', function () { const proc = spawn(process.execPath, args, { cwd: fixturesCLI, - env + env: env }) let stderr = '' @@ -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) { @@ -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) { @@ -457,7 +459,7 @@ describe('the nyc cli', function () { const proc = spawn(process.execPath, args, { cwd: fixturesCLI, - env + env: env }) let stderr = '' @@ -477,7 +479,7 @@ describe('the nyc cli', function () { const proc = spawn(process.execPath, args, { cwd: fixturesCLI, - env + env: env }) let stderr = ''