-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathtest-install.js
105 lines (93 loc) · 3.03 KB
/
test-install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict'
const { describe, it, afterEach, beforeEach } = require('mocha')
const { rm, mkdtemp } = require('fs/promises')
const { createWriteStream } = require('fs')
const assert = require('assert')
const path = require('path')
const os = require('os')
const { pipeline: streamPipeline } = require('stream/promises')
const requireInject = require('require-inject')
const { FULL_TEST, platformTimeout } = require('./common')
const gyp = require('../lib/node-gyp')
const install = require('../lib/install')
const { download } = require('../lib/download')
describe('install', function () {
it('EACCES retry once', async () => {
let statCalled = 0
const mockInstall = requireInject('../lib/install', {
'graceful-fs': {
promises: {
stat (_) {
const err = new Error()
err.code = 'EACCES'
statCalled++
throw err
}
}
}
})
const Gyp = {
devDir: __dirname,
opts: {
ensure: true
},
commands: {
install: (...args) => mockInstall(Gyp, ...args),
remove: async () => {}
}
}
let err
try {
await Gyp.commands.install([])
} catch (e) {
err = e
}
assert.ok(err)
assert.equal(statCalled, 2)
if (/"pre" versions of node cannot be installed/.test(err.message)) {
assert.ok(true)
}
})
describe('parallel', function () {
let prog
beforeEach(async () => {
prog = gyp()
prog.parseArgv([])
prog.devDir = await mkdtemp(path.join(os.tmpdir(), 'node-gyp-test-'))
})
afterEach(async () => {
await rm(prog.devDir, { recursive: true, force: true, maxRetries: 3 })
prog = null
})
const runIt = (name, fn) => {
// only run these tests if we are running a version of Node with predictable version path behavior
if (!FULL_TEST) {
return it.skip('Skipping parallel installs test due to test environment configuration')
}
return it(name, async function () {
this.timeout(platformTimeout(2, { win32: 20 }))
await fn.call(this)
const expectedDir = path.join(prog.devDir, process.version.replace(/^v/, ''))
await rm(expectedDir, { recursive: true, force: true, maxRetries: 3 })
await Promise.all(new Array(10).fill(0).map(async (_, i) => {
const title = `${' '.repeat(8)}${name} ${(i + 1).toString().padEnd(2, ' ')}`
console.log(`${title} : Start`)
console.time(title)
await install(prog, [])
console.timeEnd(title)
}))
})
}
runIt('ensure=true', async function () {
prog.opts.ensure = true
})
runIt('ensure=false', async function () {
prog.opts.ensure = false
})
runIt('tarball', async function () {
prog.opts.tarball = path.join(prog.devDir, 'node-headers.tar.gz')
const dl = await download(prog, `https://nodejs.org/dist/${process.version}/node-${process.version}.tar.gz`)
await streamPipeline(dl.body, createWriteStream(prog.opts.tarball))
})
})
})