Skip to content

Commit c3dfcec

Browse files
committed
test: add header download test
1 parent 8d79000 commit c3dfcec

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

test/test-configure-python.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const test = require('tap').test
44
const path = require('path')
5+
const devDir = require('./common').devDir()
56
const gyp = require('../lib/node-gyp')
67
const requireInject = require('require-inject')
78
const configure = requireInject('../lib/configure', {

test/test-download.js

+73-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ const path = require('path')
66
const http = require('http')
77
const https = require('https')
88
const install = require('../lib/install')
9+
const semver = require('semver')
10+
const devDir = require('./common').devDir()
11+
const rimraf = require('rimraf')
12+
const gyp = require('../lib/node-gyp')
13+
const log = require('npmlog')
914

10-
require('npmlog').level = 'warn'
15+
log.level = 'warn'
1116

1217
test('download over http', function (t) {
1318
t.plan(2)
@@ -103,3 +108,70 @@ test('check certificate splitting', function (t) {
103108
t.strictEqual(cas.length, 2)
104109
t.notStrictEqual(cas[0], cas[1])
105110
})
111+
112+
// only run this test if we are running a version of Node with predictable version path behavior
113+
114+
test('download headers (actual)', function (t) {
115+
if (process.env.FAST_TEST ||
116+
process.release.name !== 'node' ||
117+
semver.prerelease(process.version) !== null ||
118+
semver.satisfies(process.version, '<10')) {
119+
return t.skip('Skipping acutal download of headers due to test environment configuration')
120+
}
121+
122+
t.plan(19)
123+
124+
const expectedDir = path.join(devDir, process.version.replace(/^v/, ''))
125+
rimraf(expectedDir, (err) => {
126+
t.ifError(err)
127+
128+
const prog = gyp()
129+
prog.parseArgv([])
130+
prog.devDir = devDir
131+
log.level = 'warn'
132+
install(prog, [], (err) => {
133+
t.ifError(err)
134+
135+
fs.readFile(path.join(expectedDir, 'installVersion'), 'utf8', (err, data) => {
136+
t.ifError(err)
137+
t.strictEqual(data, '9\n', 'correct installVersion')
138+
})
139+
140+
fs.readdir(path.join(expectedDir, 'include/node'), (err, list) => {
141+
t.ifError(err)
142+
143+
t.ok(list.includes('common.gypi'))
144+
t.ok(list.includes('config.gypi'))
145+
t.ok(list.includes('node.h'))
146+
t.ok(list.includes('node_version.h'))
147+
t.ok(list.includes('openssl'))
148+
t.ok(list.includes('uv'))
149+
t.ok(list.includes('uv.h'))
150+
t.ok(list.includes('v8-platform.h'))
151+
t.ok(list.includes('v8.h'))
152+
t.ok(list.includes('zlib.h'))
153+
})
154+
155+
fs.readFile(path.join(expectedDir, 'include/node/node_version.h'), 'utf8', (err, contents) => {
156+
t.ifError(err)
157+
158+
const lines = contents.split('\n')
159+
160+
// extract the 3 version parts from the defines and check them against our env version
161+
162+
const version = ['major', 'minor', 'patch'].reduce((version, type) => {
163+
const re = new RegExp(`^#define\\sNODE_${type.toUpperCase()}_VERSION`)
164+
const line = lines.find((l) => re.test(l))
165+
if (line) {
166+
version[type] = parseInt(line.replace(/^[^0-9]+([0-9]+).*$/, '$1'), 10)
167+
}
168+
return version
169+
}, {})
170+
171+
t.strictEqual(version.major, semver.major(process.version))
172+
t.strictEqual(version.minor, semver.minor(process.version))
173+
t.strictEqual(version.patch, semver.patch(process.version))
174+
})
175+
})
176+
})
177+
})

0 commit comments

Comments
 (0)