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

registry-url.test.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var fs = require('fs')
  2. var path = require('path')
  3. var mocha = require('mocha')
  4. var assert = require('assert')
  5. var requireUncached = require('require-uncached')
  6. var npmRcPath = path.join(__dirname, '..', '.npmrc')
  7. var afterEach = mocha.afterEach
  8. var describe = mocha.describe
  9. var it = mocha.it
  10. describe('registry-url', function () {
  11. afterEach(function (done) {
  12. fs.unlink(npmRcPath, function () {
  13. done()
  14. })
  15. })
  16. it('should read global if no local is found', function () {
  17. var getRegistryUrl = requireUncached('../registry-url')
  18. getRegistryUrl()
  19. })
  20. it('should return default registry if no url is given for scope', function (done) {
  21. fs.writeFile(npmRcPath, 'registry=https://registry.npmjs.org/', function (err) {
  22. var getRegistryUrl = requireUncached('../registry-url')
  23. assert(!err, err)
  24. assert.strictEqual(getRegistryUrl('@somescope'), 'https://registry.npmjs.org/')
  25. done()
  26. })
  27. })
  28. it('should return registry url if url is given for scope ', function (done) {
  29. fs.writeFile(npmRcPath, '@somescope:registry=https://some.registry/', function (err) {
  30. var getRegistryUrl = requireUncached('../registry-url')
  31. assert(!err, err)
  32. assert.strictEqual(getRegistryUrl('@somescope'), 'https://some.registry/')
  33. done()
  34. })
  35. })
  36. it('should append trailing slash if not present', function (done) {
  37. fs.writeFile(npmRcPath, '@somescope:registry=https://some.registry', function (err) {
  38. var getRegistryUrl = requireUncached('../registry-url')
  39. assert(!err, err)
  40. assert.strictEqual(getRegistryUrl('@somescope'), 'https://some.registry/')
  41. done()
  42. })
  43. })
  44. it('should return configured global registry if given', function (done) {
  45. var content = [
  46. 'registry=http://registry.foobar.eu/',
  47. '@somescope:registry=https://some.url/', ''
  48. ].join('\n')
  49. fs.writeFile(npmRcPath, content, function (err) {
  50. var getRegistryUrl = requireUncached('../registry-url')
  51. assert(!err, err)
  52. assert.strictEqual(getRegistryUrl(), 'http://registry.foobar.eu/')
  53. done()
  54. })
  55. })
  56. })