diff --git a/test/common.js b/test/common.js index aef6bacfe1..489502d4dd 100644 --- a/test/common.js +++ b/test/common.js @@ -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 +} diff --git a/test/test-addon.js b/test/test-addon.js index b8d90b65bb..1f4d95ed7e 100644 --- a/test/test-addon.js +++ b/test/test-addon.js @@ -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') @@ -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) @@ -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 @@ -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) } } @@ -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) diff --git a/test/test-download.js b/test/test-download.js index e8e9df4a76..1d0f3ab286 100644 --- a/test/test-download.js +++ b/test/test-download.js @@ -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') @@ -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 }) diff --git a/test/test-install.js b/test/test-install.js index b578f3dd7f..de91b26ad8 100644 --- a/test/test-install.js +++ b/test/test-install.js @@ -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') @@ -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/, ''))