root.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var t = require("tap")
  2. var origCwd = process.cwd()
  3. process.chdir(__dirname)
  4. var glob = require('../')
  5. var path = require('path')
  6. t.test('.', function (t) {
  7. glob('/b*/**', { globDebug: true, root: '.' }, function (er, matches) {
  8. t.ifError(er)
  9. t.like(matches, [])
  10. t.end()
  11. })
  12. })
  13. t.test('a', function (t) {
  14. console.error("root=" + path.resolve('a'))
  15. glob('/b*/**', { globDebug: true, root: path.resolve('a') }, function (er, matches) {
  16. t.ifError(er)
  17. var wanted = [
  18. '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f'
  19. ].map(function (m) {
  20. return path.join(path.resolve('a'), m).replace(/\\/g, '/')
  21. })
  22. t.like(matches, wanted)
  23. t.end()
  24. })
  25. })
  26. t.test('root=a, cwd=a/b', function (t) {
  27. glob('/b*/**', { globDebug: true, root: 'a', cwd: path.resolve('a/b') }, function (er, matches) {
  28. t.ifError(er)
  29. t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
  30. return path.join(path.resolve('a'), m).replace(/\\/g, '/')
  31. }))
  32. t.end()
  33. })
  34. })
  35. t.test('cd -', function (t) {
  36. process.chdir(origCwd)
  37. t.end()
  38. })