1const t = require('tap') 2const { pkg, npm } = require('../common-tap.js') 3const { writeFileSync, statSync, readFileSync } = require('fs') 4const mkdirp = require('mkdirp') 5const proj = pkg + '/project' 6const dep = pkg + '/dep' 7mkdirp.sync(proj) 8mkdirp.sync(dep) 9writeFileSync(dep + '/package.json', JSON.stringify({ 10 name: 'dependency', 11 version: '1.2.3' 12})) 13writeFileSync(proj + '/package.json', JSON.stringify({ 14 name: 'project', 15 version: '4.2.0' 16})) 17 18const runTest = t => npm([ 19 'install', 20 '../dep', 21 '--no-registry' 22], { cwd: proj }).then(([code, out, err]) => { 23 t.equal(code, 0) 24 t.match(out, /^\+ dependency@1\.2\.3\n.* 1 package in [0-9.]+m?s\n$/) 25 t.equal(err, '') 26 const data = readFileSync(proj + '/node_modules/dependency/package.json', 'utf8') 27 t.same(JSON.parse(data), { 28 name: 'dependency', 29 version: '1.2.3' 30 }, 'dep got installed') 31 t.ok(statSync(proj + '/package-lock.json').isFile(), 'package-lock exists') 32}) 33 34t.test('install without a registry, no package lock', t => runTest(t)) 35t.test('install without a registry, with package lock', t => runTest(t)) 36