windows.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // only run this test on windows
  2. // pretending to be another platform is too hacky, since it breaks
  3. // how the underlying system looks up module paths and runs
  4. // child processes, and all that stuff is cached.
  5. if (process.platform !== 'win32') {
  6. console.log('TAP Version 13\n' +
  7. '1..0\n' +
  8. '# Skip windows tests, this is not windows\n')
  9. return
  10. }
  11. // load this before clubbing the platform name.
  12. var tap = require('tap')
  13. process.env.windir = 'C:\\windows'
  14. process.env.USERDOMAIN = 'some-domain'
  15. process.env.USERNAME = 'sirUser'
  16. process.env.USERPROFILE = 'C:\\Users\\sirUser'
  17. process.env.COMPUTERNAME = 'my-machine'
  18. process.env.TMPDIR = 'C:\\tmpdir'
  19. process.env.TMP = 'C:\\tmp'
  20. process.env.TEMP = 'C:\\temp'
  21. process.env.Path = 'C:\\Program Files\\;C:\\Binary Stuff\\bin'
  22. process.env.PROMPT = '(o_o) $ '
  23. process.env.EDITOR = 'edit'
  24. process.env.VISUAL = 'visualedit'
  25. process.env.ComSpec = 'some-com'
  26. tap.test('basic windows sanity test', function (t) {
  27. var osenv = require('../osenv.js')
  28. var osenv = require('../osenv.js')
  29. t.equal(osenv.user(),
  30. process.env.USERDOMAIN + '\\' + process.env.USERNAME)
  31. t.equal(osenv.home(), process.env.USERPROFILE)
  32. t.equal(osenv.hostname(), process.env.COMPUTERNAME)
  33. t.same(osenv.path(), process.env.Path.split(';'))
  34. t.equal(osenv.prompt(), process.env.PROMPT)
  35. t.equal(osenv.tmpdir(), process.env.TMPDIR)
  36. // mildly evil, but it's for a test.
  37. process.env.TMPDIR = ''
  38. delete require.cache[require.resolve('../osenv.js')]
  39. var osenv = require('../osenv.js')
  40. t.equal(osenv.tmpdir(), process.env.TMP)
  41. process.env.TMP = ''
  42. delete require.cache[require.resolve('../osenv.js')]
  43. var osenv = require('../osenv.js')
  44. t.equal(osenv.tmpdir(), process.env.TEMP)
  45. process.env.TEMP = ''
  46. delete require.cache[require.resolve('../osenv.js')]
  47. var osenv = require('../osenv.js')
  48. t.equal(osenv.tmpdir(), 'C:\\Users\\sirUser\\temp')
  49. process.env.TEMP = ''
  50. delete require.cache[require.resolve('../osenv.js')]
  51. var osenv = require('../osenv.js')
  52. osenv.home = function () { return null }
  53. t.equal(osenv.tmpdir(), 'C:\\windows\\temp')
  54. t.equal(osenv.editor(), 'edit')
  55. process.env.EDITOR = ''
  56. delete require.cache[require.resolve('../osenv.js')]
  57. var osenv = require('../osenv.js')
  58. t.equal(osenv.editor(), 'visualedit')
  59. process.env.VISUAL = ''
  60. delete require.cache[require.resolve('../osenv.js')]
  61. var osenv = require('../osenv.js')
  62. t.equal(osenv.editor(), 'notepad.exe')
  63. t.equal(osenv.shell(), 'some-com')
  64. process.env.ComSpec = ''
  65. delete require.cache[require.resolve('../osenv.js')]
  66. var osenv = require('../osenv.js')
  67. t.equal(osenv.shell(), 'cmd')
  68. t.end()
  69. })