Skip to content

Commit

Permalink
add tests to raise message for regenerate of lockfile or shrinkwrap w…
Browse files Browse the repository at this point in the history
…hen a dependency has an empty object value; make lint fixes
  • Loading branch information
Danielle Adams committed Jun 11, 2020
1 parent c024dca commit 74305db
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/install/inflate-shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function inflateShrinkwrap (topPath, tree, swdeps, opts) {
const dependencies = sw.dependencies || {}
const requested = realizeShrinkwrapSpecifier(name, sw, topPath)

// if (Object.keys(sw).length === 0) {
// let message = `Object for dependency "${name}" is empty.\n`
// message += 'Something went wrong. Regenerate the package-lock.json with "npm install".\n'
// message += 'If using a shrinkwrap, regenerate with "npm shrinkwrap".'
// return errorHandler(message)
// }
if (Object.keys(sw).length === 0) {
let message = `Object for dependency "${name}" is empty.\n`
message += 'Something went wrong. Regenerate the package-lock.json with "npm install".\n'
message += 'If using a shrinkwrap, regenerate with "npm shrinkwrap".'
return errorHandler(message)
}

return inflatableChild(
onDisk[name], name, topPath, tree, sw, requested, opts
Expand Down
68 changes: 68 additions & 0 deletions test/tap/lockfile-empty-dep-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict'

const common = require('../common-tap.js')
const path = require('path')
const test = require('tap').test

const Tacks = require('tacks')
const File = Tacks.File
const Dir = Tacks.Dir

const basedir = common.pkg
const testdir = path.join(basedir, 'testdir')

const fixture = new Tacks(Dir({
cache: Dir(),
global: Dir(),
tmp: Dir(),
testdir: Dir({
'package-lock.json': File({
name: 'http-locks',
version: '1.0.0',
lockfileVersion: 1,
requires: true,
dependencies: {
minimist: {}
}
}),
'package.json': File({
name: 'http-locks',
version: '1.0.0',
dependencies: {
minimist: common.registry + '/minimist/-/minimist-0.0.5.tgz'
}
})
})
}))

function setup () {
cleanup()
fixture.create(basedir)
}

function cleanup () {
fixture.remove(basedir)
}

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

test('raises error to regenerate the lock file', function (t) {
common.npm(['install'], {cwd: testdir}, function (err, code, stdout, stderr) {
if (err) throw err
t.match(
stderr,
'npm ERR! Something went wrong. Regenerate the package-lock.json with "npm install".',
'returns message to regenerate package-lock'
)

t.done()
})
})

test('cleanup', function (t) {
cleanup()
t.done()
})
66 changes: 66 additions & 0 deletions test/tap/shrinkwrap-empty-dep-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict'

const common = require('../common-tap.js')
const path = require('path')
const test = require('tap').test

const Tacks = require('tacks')
const File = Tacks.File
const Dir = Tacks.Dir

const basedir = common.pkg
const testdir = path.join(basedir, 'testdir')

const fixture = new Tacks(Dir({
cache: Dir(),
global: Dir(),
tmp: Dir(),
testdir: Dir({
'npm-shrinkwrap.json': File({
name: 'http-locks',
version: '0.0.0',
dependencies: {
minimist: {}
}
}),
'package.json': File({
name: 'http-locks',
version: '1.0.0',
dependencies: {
minimist: common.registry + '/minimist/-/minimist-0.0.5.tgz'
}
})
})
}))

function setup () {
cleanup()
fixture.create(basedir)
}

function cleanup () {
fixture.remove(basedir)
}

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

test('raises error to regenerate the shrinkwrap', function (t) {
common.npm(['install'], {cwd: testdir}, function (err, code, stdout, stderr) {
if (err) throw err
t.match(
stderr,
'npm ERR! If using a shrinkwrap, regenerate with "npm shrinkwrap".',
'returns message to regenerate shrinkwrap'
)

t.done()
})
})

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

0 comments on commit 74305db

Please sign in to comment.