cwd-test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var tap = require("tap")
  2. var origCwd = process.cwd()
  3. process.chdir(__dirname)
  4. tap.test("changing cwd and searching for **/d", function (t) {
  5. var glob = require('../')
  6. var path = require('path')
  7. t.test('.', function (t) {
  8. glob('**/d', function (er, matches) {
  9. t.ifError(er)
  10. t.like(matches, [ 'a/b/c/d', 'a/c/d' ])
  11. t.end()
  12. })
  13. })
  14. t.test('a', function (t) {
  15. glob('**/d', {cwd:path.resolve('a')}, function (er, matches) {
  16. t.ifError(er)
  17. t.like(matches, [ 'b/c/d', 'c/d' ])
  18. t.end()
  19. })
  20. })
  21. t.test('a/b', function (t) {
  22. glob('**/d', {cwd:path.resolve('a/b')}, function (er, matches) {
  23. t.ifError(er)
  24. t.like(matches, [ 'c/d' ])
  25. t.end()
  26. })
  27. })
  28. t.test('a/b/', function (t) {
  29. glob('**/d', {cwd:path.resolve('a/b/')}, function (er, matches) {
  30. t.ifError(er)
  31. t.like(matches, [ 'c/d' ])
  32. t.end()
  33. })
  34. })
  35. t.test('.', function (t) {
  36. glob('**/d', {cwd: process.cwd()}, function (er, matches) {
  37. t.ifError(er)
  38. t.like(matches, [ 'a/b/c/d', 'a/c/d' ])
  39. t.end()
  40. })
  41. })
  42. t.test('cd -', function (t) {
  43. process.chdir(origCwd)
  44. t.end()
  45. })
  46. t.end()
  47. })