• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var path = require('path')
3var test = require('tap').test
4var mkdirp = require('mkdirp')
5var writeFileSync = require('fs').writeFileSync
6var common = require('../common-tap.js')
7
8var base = common.pkg
9var mockGlobal = path.join(base, 'global')
10var toInstall = path.join(base, 'to-install')
11
12var config = 'prefix = ' + base
13var configPath = path.join(base, '_npmrc')
14
15// use a clean environment for this test
16// otherwise local dev-time npm settings can throw it off
17var OPTS = {
18  env: Object.keys(process.env).filter(function (k) {
19    return !/^npm_config_/i.test(k)
20  }).reduce(function (set, k) {
21    set[k] = process.env[k]
22    return set
23  }, {})
24}
25
26var installJSON = {
27  name: 'to-install',
28  version: '1.0.0',
29  description: '',
30  main: 'index.js',
31  scripts: {
32    test: 'echo "Error: no test specified" && exit 1'
33  },
34  author: '',
35  license: 'ISC'
36}
37
38test('setup', function (t) {
39  mkdirp.sync(mockGlobal)
40  mkdirp.sync(toInstall)
41  writeFileSync(
42    path.join(toInstall, 'package.json'),
43    JSON.stringify(installJSON, null, 2)
44  )
45  writeFileSync(configPath, config)
46  t.end()
47})
48
49test('no-global-warns', function (t) {
50  common.npm(
51    [
52      'install', '-g',
53      '--userconfig=' + configPath,
54      toInstall
55    ],
56    OPTS,
57    function (err, code, stdout, stderr) {
58      t.ifError(err, 'installed w/o error')
59      const preWarn = 'npm WARN You are using a pre-release version ' +
60        'of node and things may not work as expected'
61      stderr = stderr.trim().replace(preWarn, '')
62      t.is(stderr, '', 'no warnings printed to stderr')
63      t.end()
64    })
65})
66