diff options
author | Rebecca Turner <me@re-becca.org> | 2015-08-12 08:58:27 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-08-14 22:25:45 +0300 |
commit | 797d3ca59e74b26a2466c80ed2d519a070f7a194 (patch) | |
tree | cc41ef2902d34095cb7d1a52e40eef91fe4f7247 /test | |
parent | 6e9a8650516a42a6a45a65dada761f5f8d1f5a0a (diff) |
test: Ensure we only remove bins owned by the mod being removed
PR-URL: https://github.com/npm/npm/pull/9198
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/do-not-remove-other-bins.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/test/tap/do-not-remove-other-bins.js b/test/tap/do-not-remove-other-bins.js new file mode 100644 index 000000000..af6de6230 --- /dev/null +++ b/test/tap/do-not-remove-other-bins.js @@ -0,0 +1,131 @@ +'use strict' +var fs = require('fs') +var path = require('path') + +var mkdirp = require('mkdirp') +var osenv = require('osenv') +var rimraf = require('rimraf') +var test = require('tap').test + +var common = require('../common-tap') + +var base = path.resolve(__dirname, path.basename(__filename, '.js')) +var installPath = path.resolve(base, 'install') +var installBin = path.resolve(installPath, 'node_modules', '.bin') +var packageApath = path.resolve(base, 'packageA') +var packageBpath = path.resolve(base, 'packageB') + +var packageA = { + name: 'a', + version: '1.0.0', + description: 'x', + repository: 'x', + license: 'MIT', + bin: { + testbin: './testbin.js' + } +} +var packageB = { + name: 'b', + version: '1.0.0', + description: 'x', + repository: 'x', + license: 'MIT', + bin: { + testbin: './testbin.js' + } +} + +var EXEC_OPTS = { + cwd: installPath +} + +test('setup', function (t) { + cleanup() + mkdirp.sync(path.join(installPath, 'node_modules')) + mkdirp.sync(packageApath) + fs.writeFileSync( + path.join(packageApath, 'package.json'), + JSON.stringify(packageA, null, 2) + ) + fs.writeFileSync( + path.join(packageApath, packageA.bin.testbin), + '' + ) + mkdirp.sync(packageBpath) + fs.writeFileSync( + path.join(packageBpath, 'package.json'), + JSON.stringify(packageB, null, 2) + ) + fs.writeFileSync( + path.join(packageBpath, packageB.bin.testbin), + '' + ) + t.end() +}) + +test('npm install A', function (t) { + process.chdir(installPath) + common.npm([ + 'install', packageApath + ], EXEC_OPTS, function (err, code, stdout, stderr) { + console.log(stdout, stderr) + t.ifErr(err, 'install finished successfully') + t.notOk(code, 'exit ok') + t.notOk(stderr, 'Should not get data on stderr: ' + stderr) + t.end() + }) +}) + +test('npm install B', function (t) { + process.chdir(installPath) + common.npm([ + 'install', packageBpath + ], EXEC_OPTS, function (err, code, stdout, stderr) { + t.ifErr(err, 'install finished successfully') + t.notOk(code, 'exit ok') + t.notOk(stderr, 'Should not get data on stderr: ' + stderr) + t.end() + }) +}) + +test('verify bins', function (t) { + var bin = path.dirname( + path.resolve( + installBin, + fs.readlinkSync(path.join(installBin, 'testbin')))) + t.is(bin, path.join(installPath, 'node_modules', 'b')) + t.end() +}) + +test('rm install A', function (t) { + process.chdir(installPath) + common.npm([ + 'rm', packageApath + ], EXEC_OPTS, function (err, code, stdout, stderr) { + t.ifErr(err, 'install finished successfully') + t.notOk(code, 'exit ok') + t.notOk(stderr, 'Should not get data on stderr: ' + stderr) + t.end() + }) +}) + +test('verify postremoval bins', function (t) { + var bin = path.dirname( + path.resolve( + installBin, + fs.readlinkSync(path.join(installBin, 'testbin')))) + t.is(bin, path.join(installPath, 'node_modules', 'b')) + t.end() +}) + +test('cleanup', function (t) { + cleanup() + t.pass('cleaned up') + t.end() +}) + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(base) +} |