test-cwd.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* global describe, it, afterEach */
  2. var watch = require('..');
  3. var path = require('path');
  4. var touch = require('./util/touch');
  5. require('should');
  6. function fixtures(glob) {
  7. return path.join(__dirname, 'fixtures', glob);
  8. }
  9. describe('cwd', function () {
  10. var w;
  11. afterEach(function (done) {
  12. w.on('end', done);
  13. w.close();
  14. });
  15. it('should respect opts.cwd', function (done) {
  16. w = watch('index.js', {cwd: fixtures('')}, function (file) {
  17. file.relative.should.eql('index.js');
  18. done();
  19. }).on('ready', touch(fixtures('index.js')));
  20. });
  21. it('should emit file outside opts.cwd using relative glob', function (done) {
  22. w = watch('../index.js', {cwd: fixtures('folder')}, function (file) {
  23. file.relative.should.eql('index.js');
  24. file.contents.toString().should.equal('fixtures index');
  25. done();
  26. }).on('ready', touch(fixtures('index.js'), 'fixtures index'));
  27. });
  28. it('should emit file outside opts.cwd using absolute glob', function (done) {
  29. w = watch(fixtures('index.js'), {cwd: fixtures('folder')}, function (file) {
  30. file.relative.should.eql('index.js');
  31. file.contents.toString().should.equal('fixtures index');
  32. done();
  33. }).on('ready', touch(fixtures('index.js'), 'fixtures index'));
  34. });
  35. it('should normalized reported paths with non-normalized cwd and non-normalized relative glob', function (done) {
  36. w = watch('../fixtures/index.js', {cwd: fixtures('../util')}, function (file) {
  37. file.path.should.eql(fixtures('index.js'));
  38. done();
  39. }).on('ready', touch(fixtures('index.js'), 'fixtures index'));
  40. });
  41. it('should normalized reported paths with non-normalized cwd and non-normalized absolute glob', function (done) {
  42. w = watch(fixtures('../fixtures/index.js'), {cwd: fixtures('../util')}, function (file) {
  43. file.path.should.eql(fixtures('index.js'));
  44. done();
  45. }).on('ready', touch(fixtures('index.js'), 'fixtures index'));
  46. });
  47. it('should normalized reported paths with non-normalized relative glob outside implicit cwd', function (done) {
  48. var cwd = process.cwd();
  49. process.chdir(fixtures('../util'));
  50. w = watch('../fixtures/index.js', function (file) {
  51. process.chdir(cwd);
  52. file.path.should.eql(fixtures('index.js'));
  53. done();
  54. }).on('ready', touch(fixtures('index.js'), 'fixtures index'));
  55. });
  56. it('should normalized reported paths with non-normalized absolute glob outside implicit cwd', function (done) {
  57. var cwd = process.cwd();
  58. process.chdir(fixtures('../util'));
  59. w = watch(fixtures('../fixtures/index.js'), {cwd: fixtures('../util')}, function (file) {
  60. process.chdir(cwd);
  61. file.path.should.eql(fixtures('index.js'));
  62. done();
  63. }).on('ready', touch(fixtures('index.js'), 'fixtures index'));
  64. });
  65. });