windows.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 # Skip windows tests, this is not windows\n')
  8. return
  9. }
  10. // load this before clubbing the platform name.
  11. var tap = require('tap')
  12. process.env.windir = 'c:\\windows'
  13. process.env.USERDOMAIN = 'some-domain'
  14. process.env.USERNAME = 'sirUser'
  15. process.env.USERPROFILE = 'C:\\Users\\sirUser'
  16. process.env.COMPUTERNAME = 'my-machine'
  17. process.env.TMPDIR = 'C:\\tmpdir'
  18. process.env.TMP = 'C:\\tmp'
  19. process.env.TEMP = 'C:\\temp'
  20. process.env.Path = 'C:\\Program Files\\;C:\\Binary Stuff\\bin'
  21. process.env.PROMPT = '(o_o) $ '
  22. process.env.EDITOR = 'edit'
  23. process.env.VISUAL = 'visualedit'
  24. process.env.ComSpec = 'some-com'
  25. tap.test('basic windows sanity test', function (t) {
  26. var osenv = require('../osenv.js')
  27. t.equal(osenv.user(),
  28. process.env.USERDOMAIN + '\\' + process.env.USERNAME)
  29. t.equal(osenv.home(), process.env.USERPROFILE)
  30. t.equal(osenv.hostname(), process.env.COMPUTERNAME)
  31. t.same(osenv.path(), process.env.Path.split(';'))
  32. t.equal(osenv.prompt(), process.env.PROMPT)
  33. t.equal(osenv.tmpdir(), process.env.TMPDIR)
  34. // mildly evil, but it's for a test.
  35. process.env.TMPDIR = ''
  36. delete require.cache[require.resolve('../osenv.js')]
  37. var osenv = require('../osenv.js')
  38. t.equal(osenv.tmpdir(), process.env.TMP)
  39. process.env.TMP = ''
  40. delete require.cache[require.resolve('../osenv.js')]
  41. var osenv = require('../osenv.js')
  42. t.equal(osenv.tmpdir(), process.env.TEMP)
  43. process.env.TEMP = ''
  44. delete require.cache[require.resolve('../osenv.js')]
  45. var osenv = require('../osenv.js')
  46. osenv.home = function () { return null }
  47. t.equal(osenv.tmpdir(), 'c:\\windows\\temp')
  48. t.equal(osenv.editor(), 'edit')
  49. process.env.EDITOR = ''
  50. delete require.cache[require.resolve('../osenv.js')]
  51. var osenv = require('../osenv.js')
  52. t.equal(osenv.editor(), 'visualedit')
  53. process.env.VISUAL = ''
  54. delete require.cache[require.resolve('../osenv.js')]
  55. var osenv = require('../osenv.js')
  56. t.equal(osenv.editor(), 'notepad.exe')
  57. t.equal(osenv.shell(), 'some-com')
  58. process.env.ComSpec = ''
  59. delete require.cache[require.resolve('../osenv.js')]
  60. var osenv = require('../osenv.js')
  61. t.equal(osenv.shell(), 'cmd')
  62. t.end()
  63. })