test.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* global describe, it */
  2. var requireMainFilename = require('./')
  3. require('tap').mochaGlobals()
  4. require('chai').should()
  5. describe('require-main-filename', function () {
  6. it('returns require.main.filename in normal circumstances', function () {
  7. requireMainFilename().should.match(/test\.js/)
  8. })
  9. it('should use children[0].filename when running on iisnode', function () {
  10. var main = {
  11. filename: 'D:\\Program Files (x86)\\iisnode\\interceptor.js',
  12. children: [ {filename: 'D:\\home\\site\\wwwroot\\server.js'} ]
  13. }
  14. requireMainFilename({
  15. main: main
  16. }).should.match(/server\.js/)
  17. })
  18. it('should not use children[0] if no children exist', function () {
  19. var main = {
  20. filename: 'D:\\Program Files (x86)\\iisnode\\interceptor.js',
  21. children: []
  22. }
  23. requireMainFilename({
  24. main: main
  25. }).should.match(/interceptor\.js/)
  26. })
  27. it('should default to process.cwd() if require.main is undefined', function () {
  28. requireMainFilename({}).should.match(/require-main-filename/)
  29. })
  30. })