-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtest-configure-nodedir.js
More file actions
129 lines (114 loc) · 4.06 KB
/
test-configure-nodedir.js
File metadata and controls
129 lines (114 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict'
const { describe, it } = require('node:test')
const path = require('path')
const os = require('os')
const gyp = require('../lib/node-gyp')
const requireInject = require('require-inject')
const semver = require('semver')
const versionSemver = semver.parse(process.version)
const configure = requireInject('../lib/configure', {
'graceful-fs': {
openSync: () => 0,
closeSync: () => {},
existsSync: () => true,
readFileSync: () => '#define NODE_MAJOR_VERSION ' + versionSemver.major + '\n' +
'#define NODE_MINOR_VERSION ' + versionSemver.minor + '\n' +
'#define NODE_PATCH_VERSION ' + versionSemver.patch + '\n',
promises: {
stat: async () => ({}),
mkdir: async () => {},
writeFile: async () => {}
}
}
})
const configure2 = requireInject('../lib/configure', {
'graceful-fs': {
openSync: () => 0,
closeSync: () => {},
existsSync: () => true,
readFileSync: () => '#define NODE_MAJOR_VERSION 8\n' +
'#define NODE_MINOR_VERSION 0\n' +
'#define NODE_PATCH_VERSION 0\n',
promises: {
stat: async () => ({}),
mkdir: async () => {},
writeFile: async () => {}
}
}
})
const SPAWN_RESULT = cb => ({ on: function () { cb() } })
const driveLetter = os.platform() === 'win32' ? `${process.cwd().split(path.sep)[0]}` : ''
function checkTargetPath (target, value) {
let targetPath = path.join(path.sep, target, 'include', 'node', 'common.gypi')
if (process.platform === 'win32') {
targetPath = driveLetter + targetPath
}
return targetPath.localeCompare(value) === 0
}
describe('configure-nodedir', function () {
it('configure nodedir with node-gyp command line', async function () {
const prog = gyp()
prog.parseArgv(['dummy_prog', 'dummy_script', '--nodedir=' + path.sep + 'usr'])
await new Promise((resolve, reject) => {
prog.spawn = function (program, args) {
for (let i = 0; i < args.length; i++) {
if (checkTargetPath('usr', args[i])) {
return SPAWN_RESULT(resolve)
}
}
reject(new Error('Expected nodedir path not found'))
}
configure(prog, [], reject)
})
})
if (process.config.variables.use_prefix_to_find_headers) {
it('use-prefix-to-find-headers build time option - match', async function () {
const prog = gyp()
prog.parseArgv(['dummy_prog', 'dummy_script'])
await new Promise((resolve, reject) => {
prog.spawn = function (program, args) {
const nodedir = process.config.variables.node_prefix
for (let i = 0; i < args.length; i++) {
if (checkTargetPath(nodedir, args[i])) {
return SPAWN_RESULT(resolve)
}
}
reject(new Error('Expected nodedir path not found'))
}
configure(prog, [], reject)
})
})
it('use-prefix-to-find-headers build time option - no match', async function () {
const prog = gyp()
prog.parseArgv(['dummy_prog', 'dummy_script'])
await new Promise((resolve, reject) => {
prog.spawn = function (program, args) {
const nodedir = process.config.variables.node_prefix
for (let i = 0; i < args.length; i++) {
if (checkTargetPath(nodedir, args[i])) {
return reject(new Error('Unexpected match found'))
}
}
return SPAWN_RESULT(resolve)
}
configure2(prog, [], reject)
})
})
it('use-prefix-to-find-headers build time option, target specified', async function () {
const prog = gyp()
prog.parseArgv(['dummy_prog', 'dummy_script', '--target=8.0.0'])
await new Promise((resolve, reject) => {
prog.spawn = function (program, args) {
const nodedir = process.config.variables.node_prefix
for (let i = 0; i < args.length; i++) {
if (checkTargetPath(nodedir, args[i])) {
return reject(new Error('Unexpected match found for target'))
}
}
return SPAWN_RESULT(resolve)
}
configure(prog, [], reject)
})
})
}
})