test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* eslint-env mocha */
  2. var assert = require('assert')
  3. var homedir = require('os-homedir')
  4. var proxyquire = require('proxyquire')
  5. var platforms = [
  6. ['darwin', homedir() + '/Library/Caches/linusu'],
  7. ['freebsd', homedir() + '/.cache/linusu'],
  8. ['linux', homedir() + '/.cache/linusu'],
  9. ['win32', homedir() + '/AppData/Local/linusu/Cache']
  10. ]
  11. platforms.forEach(function (platform) {
  12. describe(platform[0], function () {
  13. var cachedir
  14. before(function () {
  15. var os = {
  16. platform: function () { return platform[0] }
  17. }
  18. cachedir = proxyquire('./', { os: os })
  19. })
  20. it('should give the correct path', function () {
  21. var actual = cachedir('linusu')
  22. var expected = platform[1]
  23. assert.equal(actual, expected)
  24. })
  25. if (platform[0] === 'win32') {
  26. describe('when LOCALAPPDATA is set', function () {
  27. it('should give the correct path', function () {
  28. var oldLocalAppData = process.env.LOCALAPPDATA
  29. process.env.LOCALAPPDATA = 'X:/LocalAppData'
  30. var actual = cachedir('linusu')
  31. process.env.LOCALAPPDATA = oldLocalAppData
  32. var expected = 'X:/LocalAppData/linusu/Cache'
  33. assert.equal(actual, expected)
  34. })
  35. })
  36. }
  37. it('should throw on bad input', function () {
  38. assert.throws(function () { cachedir() })
  39. assert.throws(function () { cachedir('') })
  40. assert.throws(function () { cachedir({}) })
  41. assert.throws(function () { cachedir([]) })
  42. assert.throws(function () { cachedir(null) })
  43. assert.throws(function () { cachedir(1337) })
  44. assert.throws(function () { cachedir('test!!') })
  45. assert.throws(function () { cachedir(undefined) })
  46. })
  47. })
  48. })