Skip to content

Commit a68586a

Browse files
committed
chore: use platform specific timeouts in tests
1 parent 4e0ed99 commit a68586a

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

test/common.js

+9
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ module.exports.FULL_TEST =
2222
process.env.FULL_TEST === '1' &&
2323
process.release.name === 'node' &&
2424
semver.prerelease(process.version) === null
25+
26+
module.exports.platformTimeout = (def, obj) => {
27+
for (const [key, value] of Object.entries(obj)) {
28+
if (process.platform === key) {
29+
return value * 60 * 1000
30+
}
31+
}
32+
return def * 60 * 1000
33+
}

test/test-addon.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const fs = require('graceful-fs')
77
const os = require('os')
88
const cp = require('child_process')
99
const util = require('../lib/util')
10+
const { platformTimeout } = require('./common')
1011

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

4344
describe('addon', function () {
44-
this.timeout(300000)
45-
4645
it('build simple addon', async function () {
46+
this.timeout(platformTimeout(1, { win32: 5 }))
47+
4748
// Set the loglevel otherwise the output disappears when run via 'npm test'
4849
const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
4950
const [err, logLines] = await execFile(cmd)
@@ -69,15 +70,14 @@ describe('addon', function () {
6970
return this.skip('no need to test')
7071
}
7172

72-
this.timeout(300000)
73+
this.timeout(platformTimeout(1, { win32: 5 }))
7374

7475
let data
7576
const configPath = path.join(addonPath, 'build', 'config.gypi')
7677
try {
7778
data = fs.readFileSync(configPath, 'utf8')
7879
} catch (err) {
79-
assert.fail(err)
80-
return
80+
return assert.fail(err)
8181
}
8282
const config = JSON.parse(data.replace(/#.+\n/, ''))
8383
const nodeDir = config.variables.nodedir
@@ -89,11 +89,9 @@ describe('addon', function () {
8989
switch (err.code) {
9090
case 'EEXIST': break
9191
case 'EPERM':
92-
assert.fail(err, null, 'Please try to running console as an administrator')
93-
return
92+
return assert.fail(err, null, 'Please try to running console as an administrator')
9493
default:
95-
assert.fail(err)
96-
return
94+
return assert.fail(err)
9795
}
9896
}
9997

@@ -118,7 +116,7 @@ describe('addon', function () {
118116
})
119117

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

123121
const notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath))
124122
fs.copyFileSync(process.execPath, notNodePath)

test/test-download.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const http = require('http')
88
const https = require('https')
99
const install = require('../lib/install')
1010
const { download, readCAFile } = require('../lib/download')
11-
const { FULL_TEST, devDir } = require('./common')
11+
const { FULL_TEST, devDir, platformTimeout } = require('./common')
1212
const gyp = require('../lib/node-gyp')
1313
const certs = require('./fixtures/certs')
1414

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

163-
this.timeout(300000)
163+
this.timeout(platformTimeout(1, { win32: 5 }))
164164

165165
const expectedDir = path.join(devDir, process.version.replace(/^v/, ''))
166166
await fs.rm(expectedDir, { recursive: true, force: true })

test/test-install.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require('path')
88
const os = require('os')
99
const { pipeline: streamPipeline } = require('stream/promises')
1010
const requireInject = require('require-inject')
11-
const { FULL_TEST } = require('./common')
11+
const { FULL_TEST, platformTimeout } = require('./common')
1212
const gyp = require('../lib/node-gyp')
1313
const install = require('../lib/install')
1414
const { download } = require('../lib/download')
@@ -74,7 +74,7 @@ describe('install', function () {
7474
}
7575

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

0 commit comments

Comments
 (0)