1 var test = require('tape')
2 var path = require('path')
3 var findNodeDirectory = require('../lib/find-node-directory')
5 var platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']
7 // we should find the directory based on the directory
8 // the script is running in and it should match the layout
9 // in a build tree where npm is installed in
11 test('test find-node-directory - node install', function (t) {
12 t.plan(platforms.length)
13 for (var next = 0; next < platforms.length; next++) {
14 var processObj = {execPath: '/x/y/bin/node', platform: platforms[next]}
16 findNodeDirectory('/x/deps/npm/node_modules/node-gyp/lib', processObj),
21 // we should find the directory based on the directory
22 // the script is running in and it should match the layout
23 // in an installed tree where npm is installed in
24 // .... /lib/node_modules/npm or .../node_modules/npm
25 // depending on the patform
26 test('test find-node-directory - node build', function (t) {
27 t.plan(platforms.length)
28 for (var next = 0; next < platforms.length; next++) {
29 var processObj = {execPath: '/x/y/bin/node', platform: platforms[next]}
30 if (platforms[next] === 'win32') {
32 findNodeDirectory('/y/node_modules/npm/node_modules/node-gyp/lib',
33 processObj), path.join('/y'))
36 findNodeDirectory('/y/lib/node_modules/npm/node_modules/node-gyp/lib',
37 processObj), path.join('/y'))
42 // we should find the directory based on the execPath
43 // for node and match because it was in the bin directory
44 test('test find-node-directory - node in bin directory', function (t) {
45 t.plan(platforms.length)
46 for (var next = 0; next < platforms.length; next++) {
47 var processObj = {execPath: '/x/y/bin/node', platform: platforms[next]}
49 findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
54 // we should find the directory based on the execPath
55 // for node and match because it was in the Release directory
56 test('test find-node-directory - node in build release dir', function (t) {
57 t.plan(platforms.length)
58 for (var next = 0; next < platforms.length; next++) {
60 if (platforms[next] === 'win32') {
61 processObj = {execPath: '/x/y/Release/node', platform: platforms[next]}
63 processObj = {execPath: '/x/y/out/Release/node',
64 platform: platforms[next]}
68 findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
73 // we should find the directory based on the execPath
74 // for node and match because it was in the Debug directory
75 test('test find-node-directory - node in Debug release dir', function (t) {
76 t.plan(platforms.length)
77 for (var next = 0; next < platforms.length; next++) {
79 if (platforms[next] === 'win32') {
80 processObj = {execPath: '/a/b/Debug/node', platform: platforms[next]}
82 processObj = {execPath: '/a/b/out/Debug/node', platform: platforms[next]}
86 findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
91 // we should not find it as it will not match based on the execPath nor
92 // the directory from which the script is running
93 test('test find-node-directory - not found', function (t) {
94 t.plan(platforms.length)
95 for (var next = 0; next < platforms.length; next++) {
96 var processObj = {execPath: '/x/y/z/y', platform:next}
97 t.equal(findNodeDirectory('/a/b/c/d', processObj), '')
101 // we should find the directory based on the directory
102 // the script is running in and it should match the layout
103 // in a build tree where npm is installed in
105 // same test as above but make sure additional directory entries
106 // don't cause an issue
107 test('test find-node-directory - node install', function (t) {
108 t.plan(platforms.length)
109 for (var next = 0; next < platforms.length; next++) {
110 var processObj = {execPath: '/x/y/bin/node', platform: platforms[next]}
112 findNodeDirectory('/x/y/z/a/b/c/deps/npm/node_modules/node-gyp/lib',
113 processObj), path.join('/x/y/z/a/b/c'))