3 var test = require('tape')
6 var path = require('path')
8 var npmRun = require('../')
10 var level0 = path.join(__dirname, 'fixtures', 'level0')
11 var level1 = path.join(level0, 'node_modules', 'level1')
12 var level2 = path.join(level1, 'node_modules', 'level2')
14 var level = [level0, level1, level2]
15 var binPath = level.map(function(levelPath) {
16 return path.join(levelPath, "node_modules", ".bin")
19 test('spawn', function(t) {
21 var child = npmRun.spawn(
23 'here are some arguments'.split(' '),
26 var stdout = bl(function(err, data) {
27 t.equal(data.toString().trim(), 'level1')
29 var stderr = bl(function(err, data) {
30 t.equal(data.toString().trim(), 'here are some arguments')
32 child.stdout.pipe(stdout)
33 child.stderr.pipe(stderr)
34 child.on('close', function(errCode) {
39 test('spawn nested', function(t) {
41 var child = npmRun.spawn(
43 'here are some arguments'.split(' '),
46 var stdout = bl(function(err, data) {
47 t.equal(data.toString().trim(), 'level1')
49 var stderr = bl(function(err, data) {
50 t.equal(data.toString().trim(), 'here are some arguments')
52 child.stdout.pipe(stdout)
53 child.stderr.pipe(stderr)
54 child.on('close', function(errCode) {
59 test('spawn bad command', function(t) {
60 var badPath = 'not-exist-adsjk'
63 'here are some arguments'.split(' '),
65 ).on('error', function(err) {
66 t.ok(err, 'has error')
67 t.equal(err.code, 'ENOENT')
68 t.ok(err.message.indexOf(badPath) !== -1)