| 1 |
|
|---|
| 2 | var n = 'rc'+Math.random()
|
|---|
| 3 | var assert = require('assert')
|
|---|
| 4 |
|
|---|
| 5 | process.env[n+'_envOption'] = 42
|
|---|
| 6 |
|
|---|
| 7 | var config = require('../')(n, {
|
|---|
| 8 | option: true
|
|---|
| 9 | })
|
|---|
| 10 |
|
|---|
| 11 | console.log(config)
|
|---|
| 12 |
|
|---|
| 13 | assert.equal(config.option, true)
|
|---|
| 14 | assert.equal(config.envOption, 42)
|
|---|
| 15 |
|
|---|
| 16 | var customArgv = require('../')(n, {
|
|---|
| 17 | option: true
|
|---|
| 18 | }, { // nopt-like argv
|
|---|
| 19 | option: false,
|
|---|
| 20 | envOption: 24,
|
|---|
| 21 | argv: {
|
|---|
| 22 | remain: [],
|
|---|
| 23 | cooked: ['--no-option', '--envOption', '24'],
|
|---|
| 24 | original: ['--no-option', '--envOption=24']
|
|---|
| 25 | }
|
|---|
| 26 | })
|
|---|
| 27 |
|
|---|
| 28 | console.log(customArgv)
|
|---|
| 29 |
|
|---|
| 30 | assert.equal(customArgv.option, false)
|
|---|
| 31 | assert.equal(customArgv.envOption, 24)
|
|---|
| 32 |
|
|---|
| 33 | var fs = require('fs')
|
|---|
| 34 | var path = require('path')
|
|---|
| 35 | var jsonrc = path.resolve('.' + n + 'rc');
|
|---|
| 36 |
|
|---|
| 37 | fs.writeFileSync(jsonrc, [
|
|---|
| 38 | '{',
|
|---|
| 39 | '// json overrides default',
|
|---|
| 40 | '"option": false,',
|
|---|
| 41 | '/* env overrides json */',
|
|---|
| 42 | '"envOption": 24',
|
|---|
| 43 | '}'
|
|---|
| 44 | ].join('\n'));
|
|---|
| 45 |
|
|---|
| 46 | var commentedJSON = require('../')(n, {
|
|---|
| 47 | option: true
|
|---|
| 48 | })
|
|---|
| 49 |
|
|---|
| 50 | fs.unlinkSync(jsonrc);
|
|---|
| 51 |
|
|---|
| 52 | console.log(commentedJSON)
|
|---|
| 53 |
|
|---|
| 54 | assert.equal(commentedJSON.option, false)
|
|---|
| 55 | assert.equal(commentedJSON.envOption, 42)
|
|---|
| 56 |
|
|---|
| 57 | assert.equal(commentedJSON.config, jsonrc)
|
|---|
| 58 | assert.equal(commentedJSON.configs.length, 1)
|
|---|
| 59 | assert.equal(commentedJSON.configs[0], jsonrc)
|
|---|