Skip to content

Commit

Permalink
test: add header download test
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 30, 2019
1 parent 8d79000 commit c3dfcec
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/test-configure-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const test = require('tap').test
const path = require('path')
const devDir = require('./common').devDir()
const gyp = require('../lib/node-gyp')
const requireInject = require('require-inject')
const configure = requireInject('../lib/configure', {
Expand Down
74 changes: 73 additions & 1 deletion test/test-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ const path = require('path')
const http = require('http')
const https = require('https')
const install = require('../lib/install')
const semver = require('semver')
const devDir = require('./common').devDir()
const rimraf = require('rimraf')
const gyp = require('../lib/node-gyp')
const log = require('npmlog')

require('npmlog').level = 'warn'
log.level = 'warn'

test('download over http', function (t) {
t.plan(2)
Expand Down Expand Up @@ -103,3 +108,70 @@ test('check certificate splitting', function (t) {
t.strictEqual(cas.length, 2)
t.notStrictEqual(cas[0], cas[1])
})

// only run this test if we are running a version of Node with predictable version path behavior

test('download headers (actual)', function (t) {
if (process.env.FAST_TEST ||
process.release.name !== 'node' ||
semver.prerelease(process.version) !== null ||
semver.satisfies(process.version, '<10')) {
return t.skip('Skipping acutal download of headers due to test environment configuration')
}

t.plan(19)

const expectedDir = path.join(devDir, process.version.replace(/^v/, ''))
rimraf(expectedDir, (err) => {
t.ifError(err)

const prog = gyp()
prog.parseArgv([])
prog.devDir = devDir
log.level = 'warn'
install(prog, [], (err) => {
t.ifError(err)

fs.readFile(path.join(expectedDir, 'installVersion'), 'utf8', (err, data) => {
t.ifError(err)
t.strictEqual(data, '9\n', 'correct installVersion')
})

fs.readdir(path.join(expectedDir, 'include/node'), (err, list) => {
t.ifError(err)

t.ok(list.includes('common.gypi'))
t.ok(list.includes('config.gypi'))
t.ok(list.includes('node.h'))
t.ok(list.includes('node_version.h'))
t.ok(list.includes('openssl'))
t.ok(list.includes('uv'))
t.ok(list.includes('uv.h'))
t.ok(list.includes('v8-platform.h'))
t.ok(list.includes('v8.h'))
t.ok(list.includes('zlib.h'))
})

fs.readFile(path.join(expectedDir, 'include/node/node_version.h'), 'utf8', (err, contents) => {
t.ifError(err)

const lines = contents.split('\n')

// extract the 3 version parts from the defines and check them against our env version

const version = ['major', 'minor', 'patch'].reduce((version, type) => {
const re = new RegExp(`^#define\\sNODE_${type.toUpperCase()}_VERSION`)
const line = lines.find((l) => re.test(l))
if (line) {
version[type] = parseInt(line.replace(/^[^0-9]+([0-9]+).*$/, '$1'), 10)
}
return version
}, {})

t.strictEqual(version.major, semver.major(process.version))
t.strictEqual(version.minor, semver.minor(process.version))
t.strictEqual(version.patch, semver.patch(process.version))
})
})
})
})

0 comments on commit c3dfcec

Please sign in to comment.