Initial commit
[yaffs-website] / node_modules / node-gyp / test / test-find-node-directory.js
1 var test = require('tape')
2 var path = require('path')
3 var findNodeDirectory = require('../lib/find-node-directory')
4
5 var platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']
6
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
10 // .... /deps/npm
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]}
15     t.equal(
16       findNodeDirectory('/x/deps/npm/node_modules/node-gyp/lib', processObj),
17                         path.join('/x'))
18   }
19 })
20
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') {
31       t.equal(
32         findNodeDirectory('/y/node_modules/npm/node_modules/node-gyp/lib',
33                            processObj), path.join('/y'))
34     } else {
35       t.equal(
36         findNodeDirectory('/y/lib/node_modules/npm/node_modules/node-gyp/lib',
37                            processObj), path.join('/y'))
38     }
39   }
40 })
41
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]}
48     t.equal(
49       findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
50       path.join('/x/y'))
51   }
52 })
53
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++) {
59     var processObj
60     if (platforms[next] === 'win32') {
61       processObj = {execPath: '/x/y/Release/node', platform: platforms[next]}
62     } else {
63       processObj = {execPath: '/x/y/out/Release/node',
64                     platform: platforms[next]}
65     }
66
67     t.equal(
68       findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
69                         path.join('/x/y'))
70   }
71 })
72
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++) {
78     var processObj
79     if (platforms[next] === 'win32') {
80       processObj = {execPath: '/a/b/Debug/node', platform: platforms[next]}
81     } else {
82       processObj = {execPath: '/a/b/out/Debug/node', platform: platforms[next]}
83     }
84
85     t.equal(
86       findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
87                         path.join('/a/b'))
88   }
89 })
90
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), '')
98   }
99 })
100
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
104 // .... /deps/npm
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]}
111     t.equal(
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'))
114   }
115 })