1 | 'use strict'
|
2 |
|
3 | const test = require('tap').test
|
4 | const path = require('path')
|
5 | const findNodeDirectory = require('../lib/find-node-directory')
|
6 |
|
7 | const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | test('test find-node-directory - node install', function (t) {
|
14 | t.plan(platforms.length)
|
15 | for (var next = 0; next < platforms.length; next++) {
|
16 | var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
|
17 | t.equal(
|
18 | findNodeDirectory('/x/deps/npm/node_modules/node-gyp/lib', processObj),
|
19 | path.join('/x'))
|
20 | }
|
21 | })
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | test('test find-node-directory - node build', function (t) {
|
29 | t.plan(platforms.length)
|
30 | for (var next = 0; next < platforms.length; next++) {
|
31 | var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
|
32 | if (platforms[next] === 'win32') {
|
33 | t.equal(
|
34 | findNodeDirectory('/y/node_modules/npm/node_modules/node-gyp/lib',
|
35 | processObj), path.join('/y'))
|
36 | } else {
|
37 | t.equal(
|
38 | findNodeDirectory('/y/lib/node_modules/npm/node_modules/node-gyp/lib',
|
39 | processObj), path.join('/y'))
|
40 | }
|
41 | }
|
42 | })
|
43 |
|
44 |
|
45 |
|
46 | test('test find-node-directory - node in bin directory', function (t) {
|
47 | t.plan(platforms.length)
|
48 | for (var next = 0; next < platforms.length; next++) {
|
49 | var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
|
50 | t.equal(
|
51 | findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
|
52 | path.join('/x/y'))
|
53 | }
|
54 | })
|
55 |
|
56 |
|
57 |
|
58 | test('test find-node-directory - node in build release dir', function (t) {
|
59 | t.plan(platforms.length)
|
60 | for (var next = 0; next < platforms.length; next++) {
|
61 | var processObj
|
62 | if (platforms[next] === 'win32') {
|
63 | processObj = { execPath: '/x/y/Release/node', platform: platforms[next] }
|
64 | } else {
|
65 | processObj = {
|
66 | execPath: '/x/y/out/Release/node',
|
67 | platform: platforms[next]
|
68 | }
|
69 | }
|
70 |
|
71 | t.equal(
|
72 | findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
|
73 | path.join('/x/y'))
|
74 | }
|
75 | })
|
76 |
|
77 |
|
78 |
|
79 | test('test find-node-directory - node in Debug release dir', function (t) {
|
80 | t.plan(platforms.length)
|
81 | for (var next = 0; next < platforms.length; next++) {
|
82 | var processObj
|
83 | if (platforms[next] === 'win32') {
|
84 | processObj = { execPath: '/a/b/Debug/node', platform: platforms[next] }
|
85 | } else {
|
86 | processObj = { execPath: '/a/b/out/Debug/node', platform: platforms[next] }
|
87 | }
|
88 |
|
89 | t.equal(
|
90 | findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
|
91 | path.join('/a/b'))
|
92 | }
|
93 | })
|
94 |
|
95 |
|
96 |
|
97 | test('test find-node-directory - not found', function (t) {
|
98 | t.plan(platforms.length)
|
99 | for (var next = 0; next < platforms.length; next++) {
|
100 | var processObj = { execPath: '/x/y/z/y', platform: next }
|
101 | t.equal(findNodeDirectory('/a/b/c/d', processObj), '')
|
102 | }
|
103 | })
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | test('test find-node-directory - node install', function (t) {
|
112 | t.plan(platforms.length)
|
113 | for (var next = 0; next < platforms.length; next++) {
|
114 | var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
|
115 | t.equal(
|
116 | findNodeDirectory('/x/y/z/a/b/c/deps/npm/node_modules/node-gyp/lib',
|
117 | processObj), path.join('/x/y/z/a/b/c'))
|
118 | }
|
119 | })
|