1var test = require('tap').test 2var path = require('path') 3var mkdirp = require('mkdirp') 4var spawn = require('child_process').spawn 5var npm = require.resolve('../../bin/npm-cli.js') 6var node = process.execPath 7const common = require('../common-tap.js') 8var pkg = common.pkg 9var workdir = path.join(pkg, 'workdir') 10var tmp = path.join(pkg, 'tmp') 11var fs = require('fs') 12 13test('package.json sorting after install', function (t) { 14 var packageJson = path.resolve(pkg, 'package.json') 15 var installedPackage = path.resolve(workdir, 16 'node_modules/install-package-json-order/package.json') 17 18 mkdirp.sync(tmp) 19 mkdirp.sync(workdir) 20 21 fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({ 22 'name': 'install-package-json-order', 23 'version': '0.0.0', 24 'array': [ 'one', 'two', 'three' ] 25 }, null, 2), 'utf8') 26 27 fs.writeFileSync(path.resolve(workdir, 'package.json'), JSON.stringify({ 28 'name': 'install-package-json-order-work', 29 'version': '0.0.0' 30 }, null, 2), 'utf8') 31 32 var before = JSON.parse(fs.readFileSync(packageJson).toString()) 33 var child = spawn(node, [npm, 'install', pkg], { cwd: workdir }) 34 35 child.on('close', function (code) { 36 t.equal(code, 0, 'npm install exited with code') 37 var result = fs.readFileSync(installedPackage, 'utf8') 38 var resultAsJson = JSON.parse(result) 39 t.same(resultAsJson.array, before.array) 40 t.end() 41 }) 42}) 43