You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
4.3 KiB

  1. 'use strict';
  2. var grunt = require('grunt');
  3. var path = require('path');
  4. var fs = require('fs');
  5. var helper = require('./helper');
  6. var fixtures = helper.fixtures;
  7. function cleanUp() {
  8. helper.cleanUp([
  9. 'events/node_modules',
  10. 'events/lib/added.js'
  11. ]);
  12. }
  13. function writeAll(cwd) {
  14. var write = 'var one = true;';
  15. grunt.file.write(path.join(cwd, 'lib', 'added.js'), write);
  16. setTimeout(function() {
  17. grunt.file.write(path.join(cwd, 'lib', 'one.js'), write);
  18. }, 300);
  19. setTimeout(function() {
  20. grunt.file.delete(path.join(cwd, 'lib', 'added.js'));
  21. }, 300);
  22. }
  23. exports.events = {
  24. setUp: function(done) {
  25. cleanUp();
  26. fs.symlinkSync(path.join(__dirname, '../../node_modules'), path.join(fixtures, 'events', 'node_modules'));
  27. done();
  28. },
  29. tearDown: function(done) {
  30. cleanUp();
  31. done();
  32. },
  33. events: function(test) {
  34. test.expect(3);
  35. var cwd = path.resolve(fixtures, 'events');
  36. var assertWatch = helper.assertTask('watch:all', {cwd: cwd});
  37. assertWatch([function() {
  38. writeAll(cwd);
  39. }], function(result) {
  40. result = helper.unixify(result);
  41. helper.verboseLog(result);
  42. test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event not emitted when file added');
  43. test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, 'event not emitted when file changed');
  44. test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event not emitted when file deleted');
  45. test.done();
  46. });
  47. },
  48. onlyAdded: function(test) {
  49. test.expect(3);
  50. var cwd = path.resolve(fixtures, 'events');
  51. var assertWatch = helper.assertTask('watch:onlyAdded', {cwd: cwd});
  52. assertWatch([function() {
  53. writeAll(cwd);
  54. }], function(result) {
  55. result = helper.unixify(result);
  56. helper.verboseLog(result);
  57. test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event not emitted when file added');
  58. test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed');
  59. test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, 'event should NOT have emitted when file deleted');
  60. test.done();
  61. });
  62. },
  63. onlyChanged: function(test) {
  64. test.expect(3);
  65. var cwd = path.resolve(fixtures, 'events');
  66. var assertWatch = helper.assertTask('watch:onlyChanged', {cwd: cwd});
  67. assertWatch([function() {
  68. writeAll(cwd);
  69. }], function(result) {
  70. result = helper.unixify(result);
  71. helper.verboseLog(result);
  72. test.ok(result.indexOf('lib/added.js was indeed added') === -1, 'event should NOT have emitted when file added');
  73. test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, 'event should have emitted when file changed');
  74. test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, 'event should NOT have emitted when file deleted');
  75. test.done();
  76. });
  77. },
  78. onlyDeleted: function(test) {
  79. test.expect(3);
  80. var cwd = path.resolve(fixtures, 'events');
  81. var assertWatch = helper.assertTask('watch:onlyDeleted', {cwd: cwd});
  82. assertWatch([function() {
  83. writeAll(cwd);
  84. }], function(result) {
  85. result = helper.unixify(result);
  86. helper.verboseLog(result);
  87. test.ok(result.indexOf('lib/added.js was indeed added') === -1, 'event should NOT have emitted when file added');
  88. test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed');
  89. test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event should have emitted when file deleted');
  90. test.done();
  91. });
  92. },
  93. onlyAddedAndDeleted: function(test) {
  94. test.expect(3);
  95. var cwd = path.resolve(fixtures, 'events');
  96. var assertWatch = helper.assertTask('watch:onlyAddedAndDeleted', {cwd: cwd});
  97. assertWatch([function() {
  98. writeAll(cwd);
  99. }], function(result) {
  100. result = helper.unixify(result);
  101. helper.verboseLog(result);
  102. test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event should have emitted when file added');
  103. test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed');
  104. test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event should have emitted when file deleted');
  105. test.done();
  106. });
  107. },
  108. };