From e6db6822588e11e309ce7f4c34ac4f7c7c5e678b Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 25 May 2017 04:08:25 -0700 Subject: test: modernize uninstall-save --- test/tap/uninstall-save.js | 96 +++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 57 deletions(-) (limited to 'test') diff --git a/test/tap/uninstall-save.js b/test/tap/uninstall-save.js index 47cffdb52..9bf342d7c 100644 --- a/test/tap/uninstall-save.js +++ b/test/tap/uninstall-save.js @@ -10,7 +10,7 @@ var test = require('tap').test var common = require('../common-tap.js') var server -var pkg = path.join(__dirname, 'uninstall-save') +var pkg = path.join(__dirname, path.basename(__filename, '.js')) var EXEC_OPTS = { cwd: pkg, stdio: [0, 'ignore', 2] } @@ -29,62 +29,44 @@ test('setup', function (t) { }) test('uninstall --save removes rm-ed package from package.json', function (t) { - common.npm( - [ - '--registry', common.registry, - '--loglevel', 'error', - '--save-prefix', '^', - '--save', - 'install', 'underscore@latest' - ], - EXEC_OPTS, - function (err, code) { - t.ifError(err, 'npm install ran without issue') - t.notOk(code, 'npm install exited with code 0') - - var p = path.join(pkg, 'node_modules', 'underscore', 'package.json') - t.ok(JSON.parse(fs.readFileSync(p))) - - var pkgJson = JSON.parse(fs.readFileSync( - path.join(pkg, 'package.json'), - 'utf8' - )) - t.deepEqual( - pkgJson.dependencies, - { 'underscore': '^1.5.1' }, - 'got expected save prefix and version of 1.5.1' - ) - - var installed = path.join(pkg, 'node_modules', 'underscore') - rimraf.sync(installed) - - common.npm( - [ - '--registry', common.registry, - '--loglevel', 'debug', - '--save', - 'uninstall', 'underscore' - ], - EXEC_OPTS, - function (err, code) { - t.ifError(err, 'npm uninstall ran without issue') - - var pkgJson = JSON.parse(fs.readFileSync( - path.join(pkg, 'package.json'), - 'utf8' - )) - - t.deepEqual( - pkgJson.dependencies, - { }, - 'dependency removed as expected' - ) - - t.end() - } - ) - } - ) + var config = [ + '--registry', common.registry, + '--save-prefix', '^', + '--save', + '--loglevel=error' + ] + return common.npm(config.concat(['install', 'underscore@latest']), EXEC_OPTS).spread((code) => { + t.notOk(code, 'npm install exited with code 0') + + var p = path.join(pkg, 'node_modules', 'underscore', 'package.json') + t.ok(JSON.parse(fs.readFileSync(p))) + + var pkgJson = JSON.parse(fs.readFileSync( + path.join(pkg, 'package.json'), + 'utf8' + )) + t.deepEqual( + pkgJson.dependencies, + { 'underscore': '^1.5.1' }, + 'got expected save prefix and version of 1.5.1' + ) + + var installed = path.join(pkg, 'node_modules', 'underscore') + rimraf.sync(installed) + + return common.npm(config.concat(['uninstall', 'underscore']), EXEC_OPTS) + }).spread((code) => { + var pkgJson = JSON.parse(fs.readFileSync( + path.join(pkg, 'package.json'), + 'utf8' + )) + + t.deepEqual( + pkgJson.dependencies, + { }, + 'dependency removed as expected' + ) + }) }) test('cleanup', function (t) { -- cgit v1.2.3