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.

55 lines
1.9 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. 'multiTargets/node_modules',
  10. 'multiTargets/Gruntfile.js.bak',
  11. ]);
  12. }
  13. var backupGrunfile;
  14. exports.reloadgruntfile = {
  15. setUp: function(done) {
  16. cleanUp();
  17. fs.symlinkSync(path.join(__dirname, '../../node_modules'), path.join(fixtures, 'multiTargets', 'node_modules'));
  18. backupGrunfile = grunt.file.read(path.join(fixtures, 'multiTargets', 'Gruntfile.js'));
  19. grunt.file.write(path.join(fixtures, 'multiTargets', 'Gruntfile.js.bak'), backupGrunfile);
  20. done();
  21. },
  22. tearDown: function(done) {
  23. grunt.file.write(path.join(fixtures, 'multiTargets', 'Gruntfile.js'), backupGrunfile);
  24. cleanUp();
  25. done();
  26. },
  27. reloadgruntfile: function(test) {
  28. test.expect(3);
  29. var cwd = path.resolve(fixtures, 'multiTargets');
  30. var assertWatch = helper.assertTask('watch', {cwd:cwd});
  31. assertWatch([function() {
  32. // First edit a file and trigger the watch
  33. grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
  34. }, function() {
  35. // Edit and reload the gruntfile
  36. var gruntfile = String(backupGrunfile).replace('echo:one', 'echo:two');
  37. grunt.file.write(path.join(cwd, 'Gruntfile.js'), gruntfile);
  38. }, function() {
  39. // Now editing one.js should trigger echo:two instead
  40. grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
  41. }], function(result) {
  42. helper.verboseLog(result);
  43. var count = result.match((new RegExp('Running "watch" task', 'g'))).length;
  44. test.equal(count, 2, 'Watch should have fired twice.');
  45. test.ok(result.indexOf('one has changed') !== -1, 'task one should have been triggered.');
  46. test.ok(result.indexOf('two has changed') !== -1, 'task two should have been triggered.');
  47. test.done();
  48. });
  49. },
  50. };