1'use strict' 2 3const common = require('../common-tap.js') 4const fs = require('fs') 5const mr = require('npm-registry-mock') 6const npm = require('../../lib/npm.js') 7const path = require('path') 8const test = require('tap').test 9 10const pkg = common.pkg 11 12const json = { 13 author: 'Rockbert', 14 name: 'shrinkwrap-extra-metadata', 15 version: '0.0.0' 16} 17 18test('setup', function (t) { 19 fs.writeFileSync( 20 path.join(pkg, 'package.json'), 21 JSON.stringify(json, null, 2) 22 ) 23 24 process.chdir(pkg) 25 t.end() 26}) 27 28test('adds additional metadata fields from the pkglock spec', function (t) { 29 mr({ port: common.port }, function (er, s) { 30 t.teardown(() => s.close()) 31 common.npm( 32 [ 33 '--registry', common.registry, 34 '--loglevel', 'silent', 35 'shrinkwrap' 36 ], 37 { cwd: pkg, env: { NODE_PRESERVE_SYMLINKS: 'foo' } }, 38 function (err, code, stdout, stderr) { 39 t.ifError(err, 'shrinkwrap ran without issue') 40 t.notOk(code, 'shrinkwrap ran without raising error code') 41 42 fs.readFile(path.resolve(pkg, 'npm-shrinkwrap.json'), function (err, desired) { 43 t.ifError(err, 'read npm-shrinkwrap.json without issue') 44 t.same( 45 { 46 'name': 'shrinkwrap-extra-metadata', 47 'version': '0.0.0', 48 'lockfileVersion': npm.lockfileVersion, 49 'preserveSymlinks': 'foo' 50 }, 51 JSON.parse(desired), 52 'shrinkwrap wrote the expected metadata fields' 53 ) 54 55 t.end() 56 }) 57 } 58 ) 59 }) 60}) 61