Skip to content

Commit

Permalink
test: modernize uninstall-save
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed May 26, 2017
1 parent 5599538 commit e6db682
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 58 deletions.
1 change: 0 additions & 1 deletion lib/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const npm = require('./npm.js')
const Installer = require('./install.js').Installer
const getSaveType = require('./install/save.js').getSaveType
const removeDeps = require('./install/deps.js').removeDeps
var readShrinkwrap = require('./install/read-shrinkwrap.js')
const log = require('npmlog')
const usage = require('./utils/usage')

Expand Down
96 changes: 39 additions & 57 deletions test/tap/uninstall-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] }

Expand All @@ -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) {
Expand Down

0 comments on commit e6db682

Please sign in to comment.