|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { describe, it } = require('mocha') |
| 4 | +const assert = require('assert') |
| 5 | +const path = require('path') |
| 6 | +const gyp = require('../lib/node-gyp') |
| 7 | +const requireInject = require('require-inject') |
| 8 | +const semver = require('semver') |
| 9 | + |
| 10 | +const versionSemver = semver.parse(process.version) |
| 11 | + |
| 12 | +const configure = requireInject('../lib/configure', { |
| 13 | + 'graceful-fs': { |
| 14 | + openSync: () => 0, |
| 15 | + closeSync: () => {}, |
| 16 | + existsSync: () => true, |
| 17 | + readFileSync: () => '#define NODE_MAJOR_VERSION ' + versionSemver.major + '\n' + |
| 18 | + '#define NODE_MINOR_VERSION ' + versionSemver.minor + '\n' + |
| 19 | + '#define NODE_PATCH_VERSION ' + versionSemver.patch + '\n', |
| 20 | + promises: { |
| 21 | + stat: async () => ({}), |
| 22 | + mkdir: async () => {}, |
| 23 | + writeFile: async () => {} |
| 24 | + } |
| 25 | + } |
| 26 | +}) |
| 27 | + |
| 28 | +const configure2 = requireInject('../lib/configure', { |
| 29 | + 'graceful-fs': { |
| 30 | + openSync: () => 0, |
| 31 | + closeSync: () => {}, |
| 32 | + existsSync: () => true, |
| 33 | + readFileSync: () => '#define NODE_MAJOR_VERSION 8\n' + |
| 34 | + '#define NODE_MINOR_VERSION 0\n' + |
| 35 | + '#define NODE_PATCH_VERSION 0\n', |
| 36 | + promises: { |
| 37 | + stat: async () => ({}), |
| 38 | + mkdir: async () => {}, |
| 39 | + writeFile: async () => {} |
| 40 | + } |
| 41 | + } |
| 42 | +}) |
| 43 | + |
| 44 | +const SPAWN_RESULT = cb => ({ on: function () { cb() } }) |
| 45 | + |
| 46 | +describe('configure-nodedir', function () { |
| 47 | + it('configure nodedir with node-gyp command line', function (done) { |
| 48 | + const prog = gyp() |
| 49 | + prog.parseArgv(['dummy_prog', 'dummy_script', '--nodedir=/usr']) |
| 50 | + |
| 51 | + prog.spawn = function (program, args) { |
| 52 | + for (let i = 0; i < args.length; i++) { |
| 53 | + if (path.join(path.sep, 'usr', 'include', 'node', |
| 54 | + 'common.gypi').localeCompare(args[i]) === 0) { |
| 55 | + return SPAWN_RESULT(done) |
| 56 | + } |
| 57 | + }; |
| 58 | + assert.fail() |
| 59 | + } |
| 60 | + configure(prog, [], assert.fail) |
| 61 | + }) |
| 62 | + |
| 63 | + if (process.config.variables.use_prefix_to_find_headers) { |
| 64 | + it('use-prefix-to-find-headers build time option - match', function (done) { |
| 65 | + const prog = gyp() |
| 66 | + prog.parseArgv(['dummy_prog', 'dummy_script']) |
| 67 | + |
| 68 | + prog.spawn = function (program, args) { |
| 69 | + for (let i = 0; i < args.length; i++) { |
| 70 | + const nodedir = process.config.variables.node_prefix |
| 71 | + if (path.join(path.sep, nodedir, 'include', 'node', |
| 72 | + 'common.gypi').localeCompare(args[i]) === 0) { |
| 73 | + return SPAWN_RESULT(done) |
| 74 | + } |
| 75 | + }; |
| 76 | + assert.fail() |
| 77 | + } |
| 78 | + configure(prog, [], assert.fail) |
| 79 | + }) |
| 80 | + |
| 81 | + it('use-prefix-to-find-headers build time option - no match', function (done) { |
| 82 | + const prog = gyp() |
| 83 | + prog.parseArgv(['dummy_prog', 'dummy_script']) |
| 84 | + |
| 85 | + prog.spawn = function (program, args) { |
| 86 | + for (let i = 0; i < args.length; i++) { |
| 87 | + const nodedir = process.config.variables.node_prefix |
| 88 | + if (path.join(path.sep, nodedir, 'include', 'node', |
| 89 | + 'common.gypi').localeCompare(args[i]) === 0) { |
| 90 | + assert.fail() |
| 91 | + } |
| 92 | + }; |
| 93 | + return SPAWN_RESULT(done) |
| 94 | + } |
| 95 | + configure2(prog, [], assert.fail) |
| 96 | + }) |
| 97 | + |
| 98 | + it('use-prefix-to-find-headers build time option, target specified', function (done) { |
| 99 | + const prog = gyp() |
| 100 | + prog.parseArgv(['dummy_prog', 'dummy_script', '--target=8.0.0']) |
| 101 | + |
| 102 | + prog.spawn = function (program, args) { |
| 103 | + for (let i = 0; i < args.length; i++) { |
| 104 | + const nodedir = process.config.variables.node_prefix |
| 105 | + if (path.join(path.sep, nodedir, 'include', 'node', |
| 106 | + 'common.gypi').localeCompare(args[i]) === 0) { |
| 107 | + assert.fail() |
| 108 | + } |
| 109 | + }; |
| 110 | + return SPAWN_RESULT(done) |
| 111 | + } |
| 112 | + configure(prog, [], assert.fail) |
| 113 | + }) |
| 114 | + } |
| 115 | +}) |
0 commit comments