source: trip-planner-front/node_modules/node-gyp/test/test-find-node-directory.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[6a3a178]1'use strict'
2
3const test = require('tap').test
4const path = require('path')
5const findNodeDirectory = require('../lib/find-node-directory')
6
7const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']
8
9// we should find the directory based on the directory
10// the script is running in and it should match the layout
11// in a build tree where npm is installed in
12// .... /deps/npm
13test('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// we should find the directory based on the directory
24// the script is running in and it should match the layout
25// in an installed tree where npm is installed in
26// .... /lib/node_modules/npm or .../node_modules/npm
27// depending on the patform
28test('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// we should find the directory based on the execPath
45// for node and match because it was in the bin directory
46test('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// we should find the directory based on the execPath
57// for node and match because it was in the Release directory
58test('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// we should find the directory based on the execPath
78// for node and match because it was in the Debug directory
79test('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// we should not find it as it will not match based on the execPath nor
96// the directory from which the script is running
97test('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// we should find the directory based on the directory
106// the script is running in and it should match the layout
107// in a build tree where npm is installed in
108// .... /deps/npm
109// same test as above but make sure additional directory entries
110// don't cause an issue
111test('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})
Note: See TracBrowser for help on using the repository browser.