Welcome to mirror list, hosted at ThFree Co, Russian Federation.

npm-defaults.js « test « init-package-json « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 292b9623ae96f0fd48740224ff4f51ae08e6cbe4 (plain)
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
106
107
108
109
var test = require('tap').test
var rimraf = require('rimraf')
var resolve = require('path').resolve

var npm = require('npm')
var init = require('../')

var EXPECTED = {
  name: 'test',
  version: '3.1.4',
  description: '',
  main: 'basic.js',
  scripts: {
    test: 'echo "Error: no test specified" && exit 1'
  },
  keywords: [],
  author: 'npmbot <n@p.m> (http://npm.im/)',
  license: 'WTFPL'
}

test('npm configuration values pulled from environment', function (t) {
  /*eslint camelcase:0 */
  process.env.npm_config_yes = 'yes'

  process.env.npm_config_init_author_name = 'npmbot'
  process.env.npm_config_init_author_email = 'n@p.m'
  process.env.npm_config_init_author_url = 'http://npm.im'

  process.env.npm_config_init_license = EXPECTED.license
  process.env.npm_config_init_version = EXPECTED.version

  npm.load({}, function (err) {
    t.ifError(err, 'npm loaded successfully')

    // clear out dotted names from test environment
    npm.config.del('init.author.name')
    npm.config.del('init.author.email')
    npm.config.del('init.author.url')
    // the following have npm defaults, and need to be explicitly overridden
    npm.config.set('init.license', '')
    npm.config.set('init.version', '')

    process.chdir(resolve(__dirname))
    init(__dirname, __dirname, npm.config, function (er, data) {
      t.ifError(err, 'init ran successfully')

      t.same(data, EXPECTED, 'got the package data from the environment')
      t.end()
    })
  })
})

test('npm configuration values pulled from dotted config', function (t) {
  /*eslint camelcase:0 */
  var config = {
    yes: 'yes',

    'init.author.name': 'npmbot',
    'init.author.email': 'n@p.m',
    'init.author.url': 'http://npm.im',

    'init.license': EXPECTED.license,
    'init.version': EXPECTED.version
  }

  npm.load(config, function (err) {
    t.ifError(err, 'npm loaded successfully')

    process.chdir(resolve(__dirname))
    init(__dirname, __dirname, npm.config, function (er, data) {
      t.ifError(err, 'init ran successfully')

      t.same(data, EXPECTED, 'got the package data from the config')
      t.end()
    })
  })
})

test('npm configuration values pulled from dashed config', function (t) {
  /*eslint camelcase:0 */
  var config = {
    yes: 'yes',

    'init-author-name': 'npmbot',
    'init-author-email': 'n@p.m',
    'init-author-url': 'http://npm.im',

    'init-license': EXPECTED.license,
    'init-version': EXPECTED.version
  }

  npm.load(config, function (err) {
    t.ifError(err, 'npm loaded successfully')

    process.chdir(resolve(__dirname))
    init(__dirname, __dirname, npm.config, function (er, data) {
      t.ifError(err, 'init ran successfully')

      t.same(data, EXPECTED, 'got the package data from the config')
      t.end()
    })
  })
})

test('cleanup', function (t) {
  rimraf.sync(resolve(__dirname, 'package.json'))
  t.pass('cleaned up')
  t.end()
})