Skip to content

Commit

Permalink
chore: use platform specific timeouts in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Oct 29, 2023
1 parent 4e0ed99 commit a68586a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
9 changes: 9 additions & 0 deletions test/common.js
Expand Up @@ -22,3 +22,12 @@ module.exports.FULL_TEST =
process.env.FULL_TEST === '1' &&
process.release.name === 'node' &&
semver.prerelease(process.version) === null

module.exports.platformTimeout = (def, obj) => {
for (const [key, value] of Object.entries(obj)) {
if (process.platform === key) {
return value * 60 * 1000
}
}
return def * 60 * 1000
}
18 changes: 8 additions & 10 deletions test/test-addon.js
Expand Up @@ -7,6 +7,7 @@ const fs = require('graceful-fs')
const os = require('os')
const cp = require('child_process')
const util = require('../lib/util')
const { platformTimeout } = require('./common')

const addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
const nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')
Expand Down Expand Up @@ -41,9 +42,9 @@ function checkCharmapValid () {
}

describe('addon', function () {
this.timeout(300000)

it('build simple addon', async function () {
this.timeout(platformTimeout(1, { win32: 5 }))

// Set the loglevel otherwise the output disappears when run via 'npm test'
const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
const [err, logLines] = await execFile(cmd)
Expand All @@ -69,15 +70,14 @@ describe('addon', function () {
return this.skip('no need to test')
}

this.timeout(300000)
this.timeout(platformTimeout(1, { win32: 5 }))

let data
const configPath = path.join(addonPath, 'build', 'config.gypi')
try {
data = fs.readFileSync(configPath, 'utf8')
} catch (err) {
assert.fail(err)
return
return assert.fail(err)
}
const config = JSON.parse(data.replace(/#.+\n/, ''))
const nodeDir = config.variables.nodedir
Expand All @@ -89,11 +89,9 @@ describe('addon', function () {
switch (err.code) {
case 'EEXIST': break
case 'EPERM':
assert.fail(err, null, 'Please try to running console as an administrator')
return
return assert.fail(err, null, 'Please try to running console as an administrator')
default:
assert.fail(err)
return
return assert.fail(err)
}
}

Expand All @@ -118,7 +116,7 @@ describe('addon', function () {
})

it('addon works with renamed host executable', async function () {
this.timeout(300000)
this.timeout(platformTimeout(1, { win32: 5 }))

const notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath))
fs.copyFileSync(process.execPath, notNodePath)
Expand Down
4 changes: 2 additions & 2 deletions test/test-download.js
Expand Up @@ -8,7 +8,7 @@ const http = require('http')
const https = require('https')
const install = require('../lib/install')
const { download, readCAFile } = require('../lib/download')
const { FULL_TEST, devDir } = require('./common')
const { FULL_TEST, devDir, platformTimeout } = require('./common')
const gyp = require('../lib/node-gyp')
const certs = require('./fixtures/certs')

Expand Down Expand Up @@ -160,7 +160,7 @@ describe('download', function () {
return this.skip('Skipping actual download of headers due to test environment configuration')
}

this.timeout(300000)
this.timeout(platformTimeout(1, { win32: 5 }))

const expectedDir = path.join(devDir, process.version.replace(/^v/, ''))
await fs.rm(expectedDir, { recursive: true, force: true })
Expand Down
4 changes: 2 additions & 2 deletions test/test-install.js
Expand Up @@ -8,7 +8,7 @@ const path = require('path')
const os = require('os')
const { pipeline: streamPipeline } = require('stream/promises')
const requireInject = require('require-inject')
const { FULL_TEST } = require('./common')
const { FULL_TEST, platformTimeout } = require('./common')
const gyp = require('../lib/node-gyp')
const install = require('../lib/install')
const { download } = require('../lib/download')
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('install', function () {
}

return it(name, async function () {
this.timeout(600000)
this.timeout(platformTimeout(1, { win32: 20 }))
const start = Date.now()
await fn.call(this)
const expectedDir = path.join(prog.devDir, process.version.replace(/^v/, ''))
Expand Down

0 comments on commit a68586a

Please sign in to comment.