Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

test.js 1.1KB

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