You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-find-node-directory.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict'
  2. const { describe, it } = require('mocha')
  3. const assert = require('assert')
  4. const path = require('path')
  5. const findNodeDirectory = require('../lib/find-node-directory')
  6. const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix', 'os400']
  7. describe('find-node-directory', function () {
  8. // we should find the directory based on the directory
  9. // the script is running in and it should match the layout
  10. // in a build tree where npm is installed in
  11. // .... /deps/npm
  12. it('test find-node-directory - node install', function () {
  13. for (var next = 0; next < platforms.length; next++) {
  14. var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
  15. assert.strictEqual(
  16. findNodeDirectory('/x/deps/npm/node_modules/node-gyp/lib', processObj),
  17. path.join('/x'))
  18. }
  19. })
  20. // we should find the directory based on the directory
  21. // the script is running in and it should match the layout
  22. // in an installed tree where npm is installed in
  23. // .... /lib/node_modules/npm or .../node_modules/npm
  24. // depending on the patform
  25. it('test find-node-directory - node build', function () {
  26. for (var next = 0; next < platforms.length; next++) {
  27. var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
  28. if (platforms[next] === 'win32') {
  29. assert.strictEqual(
  30. findNodeDirectory('/y/node_modules/npm/node_modules/node-gyp/lib',
  31. processObj), path.join('/y'))
  32. } else {
  33. assert.strictEqual(
  34. findNodeDirectory('/y/lib/node_modules/npm/node_modules/node-gyp/lib',
  35. processObj), path.join('/y'))
  36. }
  37. }
  38. })
  39. // we should find the directory based on the execPath
  40. // for node and match because it was in the bin directory
  41. it('test find-node-directory - node in bin directory', function () {
  42. for (var next = 0; next < platforms.length; next++) {
  43. var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
  44. assert.strictEqual(
  45. findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
  46. path.join('/x/y'))
  47. }
  48. })
  49. // we should find the directory based on the execPath
  50. // for node and match because it was in the Release directory
  51. it('test find-node-directory - node in build release dir', function () {
  52. for (var next = 0; next < platforms.length; next++) {
  53. var processObj
  54. if (platforms[next] === 'win32') {
  55. processObj = { execPath: '/x/y/Release/node', platform: platforms[next] }
  56. } else {
  57. processObj = {
  58. execPath: '/x/y/out/Release/node',
  59. platform: platforms[next]
  60. }
  61. }
  62. assert.strictEqual(
  63. findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
  64. path.join('/x/y'))
  65. }
  66. })
  67. // we should find the directory based on the execPath
  68. // for node and match because it was in the Debug directory
  69. it('test find-node-directory - node in Debug release dir', function () {
  70. for (var next = 0; next < platforms.length; next++) {
  71. var processObj
  72. if (platforms[next] === 'win32') {
  73. processObj = { execPath: '/a/b/Debug/node', platform: platforms[next] }
  74. } else {
  75. processObj = { execPath: '/a/b/out/Debug/node', platform: platforms[next] }
  76. }
  77. assert.strictEqual(
  78. findNodeDirectory('/nothere/npm/node_modules/node-gyp/lib', processObj),
  79. path.join('/a/b'))
  80. }
  81. })
  82. // we should not find it as it will not match based on the execPath nor
  83. // the directory from which the script is running
  84. it('test find-node-directory - not found', function () {
  85. for (var next = 0; next < platforms.length; next++) {
  86. var processObj = { execPath: '/x/y/z/y', platform: next }
  87. assert.strictEqual(findNodeDirectory('/a/b/c/d', processObj), '')
  88. }
  89. })
  90. // we should find the directory based on the directory
  91. // the script is running in and it should match the layout
  92. // in a build tree where npm is installed in
  93. // .... /deps/npm
  94. // same test as above but make sure additional directory entries
  95. // don't cause an issue
  96. it('test find-node-directory - node install', function () {
  97. for (var next = 0; next < platforms.length; next++) {
  98. var processObj = { execPath: '/x/y/bin/node', platform: platforms[next] }
  99. assert.strictEqual(
  100. findNodeDirectory('/x/y/z/a/b/c/deps/npm/node_modules/node-gyp/lib',
  101. processObj), path.join('/x/y/z/a/b/c'))
  102. }
  103. })
  104. })