1var exec = require('child_process').exec 2var fs = require('graceful-fs') 3var path = require('path') 4var existsSync = fs.existsSync || path.existsSync 5 6var mkdirp = require('mkdirp') 7var test = require('tap').test 8 9var escapeExecPath = require('../../lib/utils/escape-exec-path') 10 11var common = require('../common-tap.js') 12 13var resolve = require('path').resolve 14var pkg = resolve(common.pkg, 'package') 15var work = resolve(common.pkg, 'TEST') 16var modules = path.join(work, 'node_modules') 17 18var EXEC_OPTS = { cwd: work } 19 20var world = '#!/usr/bin/env node\nconsole.log("hello blrbld")\n' 21 22var json = { 23 name: '@scoped/package', 24 version: '0.0.0', 25 bin: { 26 hello: './world.js' 27 } 28} 29 30test('setup', function (t) { 31 mkdirp.sync(pkg) 32 fs.writeFileSync( 33 path.join(pkg, 'package.json'), 34 JSON.stringify(json, null, 2) 35 ) 36 fs.writeFileSync(path.join(pkg, 'world.js'), world) 37 38 mkdirp.sync(modules) 39 process.chdir(work) 40 41 t.end() 42}) 43 44test('installing package with links', function (t) { 45 common.npm( 46 [ 47 '--loglevel', 'silent', 48 'install', pkg 49 ], 50 EXEC_OPTS, 51 function (err, code) { 52 t.ifError(err, 'install ran to completion without error') 53 t.notOk(code, 'npm install exited with code 0') 54 55 t.ok( 56 existsSync(path.join(modules, '@scoped', 'package', 'package.json')), 57 'package installed' 58 ) 59 t.ok(existsSync(path.join(modules, '.bin')), 'binary link directory exists') 60 61 var hello = path.join(modules, '.bin', 'hello') 62 t.ok(existsSync(hello), 'binary link exists') 63 64 exec(escapeExecPath(hello), function (err, stdout, stderr) { 65 t.ifError(err, 'command ran fine') 66 t.notOk(stderr, 'got no error output back') 67 t.equal(stdout, 'hello blrbld\n', 'output was as expected') 68 69 t.end() 70 }) 71 } 72 ) 73}) 74