Skip to content

Commit

Permalink
test: rewrite shrinkwrap-dev-dependency as common.npm
Browse files Browse the repository at this point in the history
Reviewed-By: @zkat
Credit: @iarna
PR-URL: npm#12851
  • Loading branch information
iarna authored and zkat committed May 26, 2016
1 parent cac0038 commit fbec9fd
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions test/tap/shrinkwrap-dev-dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,13 @@ var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')
var npm = npm = require('../../')

var pkg = path.resolve(__dirname, 'shrinkwrap-dev-dependency')

test("shrinkwrap doesn't strip out the dependency", function (t) {
t.plan(1)

mr({port: common.port}, function (er, s) {
setup(function (err) {
if (err) return t.fail(err)

npm.install('.', function (err) {
if (err) return t.fail(err)

npm.commands.shrinkwrap([], true, function (err, results) {
if (err) return t.fail(err)

t.deepEqual(results, desired)
s.close()
t.end()
})
})
})
})
})

test('cleanup', function (t) {
cleanup()
t.end()
})
var opts = [
'--cache', path.resolve(pkg, 'cache'),
'--registry', common.registry
]

var desired = {
name: 'npm-test-shrinkwrap-dev-dependency',
Expand Down Expand Up @@ -69,20 +46,48 @@ var json = {
}
}

function setup (cb) {
function setup () {
cleanup()
mkdirp.sync(pkg)
fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
process.chdir(pkg)

var opts = {
cache: path.resolve(pkg, 'cache'),
registry: common.registry
}
npm.load(opts, cb)
}

function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
}

test('setup', function (t) {
setup()
t.end()
})

test("shrinkwrap doesn't strip out the dependency", function (t) {
t.plan(3)
setup()

mr({port: common.port}, function (er, s) {
common.npm(opts.concat(['install', '.']), {stdio: [0, 'pipe', 2]}, function (err, code) {
if (err) throw err
if (!t.is(code, 0)) return (s.close(), t.end())
common.npm(opts.concat(['shrinkwrap']), {stdio: [0, 2, 2]}, function (err, code) {
if (err) throw err
t.is(code, 0)
try {
var results = JSON.parse(fs.readFileSync(path.join(pkg, 'npm-shrinkwrap.json')))
} catch (ex) {
t.comment(ex)
}
t.deepEqual(results, desired)
s.close()
t.end()
})
})
})
})

test('cleanup', function (t) {
cleanup()
t.end()
})

0 comments on commit fbec9fd

Please sign in to comment.