fix(user-agent): set the correct user-agent

This commit is contained in:
zkochan
2017-04-08 15:30:59 +03:00
parent 75d9a3da84
commit fa8f2e57db
8 changed files with 85 additions and 28 deletions

View File

@@ -6,6 +6,11 @@ import {
testDefaults,
execPnpmSync,
} from '../utils'
import path = require('path')
import loadJsonFile = require('load-json-file')
const pkgRoot = path.join(__dirname, '..', '..')
const pnpmPkg = loadJsonFile.sync(path.join(pkgRoot, 'package.json'))
const test = promisifyTape(tape)
@@ -42,6 +47,22 @@ test('installation fails if lifecycle script fails', t => {
t.end()
})
test('lifecycle script runs with the correct user agent', t => {
const project = prepare(t, {
scripts: {
preinstall: 'node --eval "console.log(process.env.npm_config_user_agent)"'
},
})
const result = execPnpmSync('install')
t.equal(result.status, 0, 'installation was successfull')
const expectedUserAgent = `${pnpmPkg.name}/${pnpmPkg.version} npm/? node/${process.version} ${process.platform} ${process.arch}`
t.ok(result.stdout.toString().indexOf(expectedUserAgent) !== -1, 'correct npm_config_user_agent value')
t.end()
})
test('preinstall is executed before general installation', t => {
const project = prepare(t, {
scripts: {