spmrc.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var fs = require('fs');
  2. var path = require('path');
  3. var should = require('should');
  4. var Spmrc = require('..');
  5. var spmrc = Spmrc({
  6. dir: '.spmrc',
  7. file: 'spmrc-3x',
  8. defaults: {
  9. 'registry': 'http://spmjs.io',
  10. 'install.path': 'spm_modules'
  11. }
  12. })
  13. describe('spmrc', function () {
  14. // spmrc.spmrcfile = path.join(__dirname, './tmp/spmrc');
  15. it('get nothing', function () {
  16. spmrc.get().should.eql({});
  17. });
  18. it('get default values', function () {
  19. spmrc.get('install.path').should.equal('spm_modules');
  20. spmrc.get('registry').should.equal('http://spmjs.io');
  21. });
  22. it("write data", function () {
  23. spmrc.write({
  24. user: {
  25. username: "spm3"
  26. }
  27. });
  28. spmrc.get('user.username').should.equal('spm3');
  29. });
  30. it('set user.username = spm', function () {
  31. spmrc.set('user.username', 'spm');
  32. });
  33. it('get user.username', function () {
  34. spmrc.get('user.username').should.equal('spm');
  35. });
  36. it('set auth = spm', function () {
  37. spmrc.set('auth', 'spm');
  38. });
  39. it('get auth', function () {
  40. spmrc.get('auth').should.equal('spm');
  41. });
  42. it('get via config', function () {
  43. spmrc.config('user.username').should.equal('spm');
  44. });
  45. it('set via config', function () {
  46. spmrc.config('user.username', 'spmjs');
  47. spmrc.get('user.username').should.equal('spmjs');
  48. });
  49. it('set section:title.key', function () {
  50. spmrc.set('section:title.key', 'value');
  51. spmrc.get('section:title.key').should.equal('value');
  52. spmrc.get('section.title.key').should.equal('value');
  53. });
  54. it('set section.title.key', function () {
  55. spmrc.set('section.title.key', 'value2');
  56. spmrc.get('section:title.key').should.equal('value2');
  57. spmrc.get('section.title.key').should.equal('value2');
  58. });
  59. after(function () {
  60. fs.unlinkSync(spmrc.spmrcfile);
  61. });
  62. });