1const t = require('tap') 2const common = require('../common-tap.js') 3const mkdirp = require('mkdirp') 4const { writeFileSync, readFileSync } = require('fs') 5const { resolve } = require('path') 6const pkg = common.pkg 7const app = resolve(pkg, 'app') 8const lib = resolve(pkg, 'lib') 9const moda = resolve(lib, 'module-a') 10const modb = resolve(lib, 'module-b') 11 12const rimraf = require('rimraf') 13 14t.test('setup', t => { 15 mkdirp.sync(app) 16 mkdirp.sync(moda) 17 mkdirp.sync(modb) 18 19 writeFileSync(resolve(app, 'package.json'), JSON.stringify({ 20 name: 'app', 21 version: '1.2.3', 22 dependencies: { 23 moda: 'file:../lib/module-a' 24 } 25 })) 26 27 writeFileSync(resolve(moda, 'package.json'), JSON.stringify({ 28 name: 'moda', 29 version: '1.2.3', 30 dependencies: { 31 modb: 'file:../module-b' 32 } 33 })) 34 35 writeFileSync(resolve(modb, 'package.json'), JSON.stringify({ 36 name: 'modb', 37 version: '1.2.3' 38 })) 39 40 t.end() 41}) 42 43t.test('initial install to create package-lock', 44 t => common.npm(['install'], { cwd: app }) 45 .then(([code]) => t.equal(code, 0, 'command worked'))) 46 47t.test('remove node_modules', t => 48 rimraf(resolve(pkg, 'node_modules'), t.end)) 49 50t.test('install again from package-lock', t => 51 common.npm(['install'], { cwd: app }) 52 .then(([code]) => { 53 t.equal(code, 0, 'command worked') 54 // verify that module-b is linked under module-a 55 const depPkg = resolve( 56 app, 57 'node_modules', 58 'moda', 59 'node_modules', 60 'modb', 61 'package.json' 62 ) 63 const data = JSON.parse(readFileSync(depPkg, 'utf8')) 64 t.strictSame(data, { 65 name: 'modb', 66 version: '1.2.3' 67 }) 68 })) 69