"use strict"

var test = require('tape')

var path = require('path')

var npmWhich = require('../')

var level0 = path.join(__dirname, 'fixtures', 'level0')
var level1 = path.join(level0, 'node_modules', 'level1')
var level2 = path.join(level1, 'node_modules', 'level2')

var level = [level0, level1, level2]
var binPath = level.map(function(levelPath) {
  return path.join(levelPath, "node_modules", ".bin")
})

test('includes all .bin dirs in all parent node_modules folders', function(t) {
  t.test('no nesting', function(t) {
    var level1Bin = npmWhich.sync('level1', {cwd: level[0]})
    t.equal(level1Bin, path.join(binPath[0], 'level1'))
    t.end()
  })

  t.test('nesting', function(t) {
    var level1Bin = npmWhich.sync('level1', {cwd: level[1]})
    t.equal(level1Bin, path.join(binPath[0], 'level1'))
    var level2Bin = npmWhich.sync('level2', {cwd: level[1]})
    t.equal(level2Bin, path.join(binPath[1], 'level2'))
    t.end()
  })

  t.test('more nesting', function(t) {
    var level1Bin = npmWhich.sync('level1', {cwd: level[2]})
    t.equal(level1Bin, path.join(binPath[0], 'level1'))
    var level2Bin = npmWhich.sync('level2', {cwd: level[2]})
    t.equal(level2Bin, path.join(binPath[1], 'level2'))
    t.end()
  })

  t.end()
})


@@ -1245,12 +1245,229 @@
 t.end()%0A%7D)%0A%0A
+test('does not mutate PATH', function(t) %7B%0A  var before = process.env.PATH%0A  var level1Bin = npmWhich.sync('level1', %7Benv: %7BPATH: binPath%5B0%5D%7D%7D)%0A  var after = process.env.PATH%0A  t.deepEqual(before, after)%0A  t.end()%0A%7D)%0A

Test that PATH is not mutated.