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.

65 lines
2.2 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. var useFixtures = ['nospawn'];
  8. function cleanUp() {
  9. useFixtures.forEach(function(fixture) {
  10. helper.cleanUp(fixture + '/node_modules');
  11. });
  12. }
  13. exports.nospawn = {
  14. setUp: function(done) {
  15. cleanUp();
  16. useFixtures.forEach(function(fixture) {
  17. fs.symlinkSync(path.join(__dirname, '../../node_modules'), path.join(fixtures, fixture, 'node_modules'));
  18. });
  19. done();
  20. },
  21. tearDown: function(done) {
  22. cleanUp();
  23. done();
  24. },
  25. nospawn: function(test) {
  26. test.expect(3);
  27. var cwd = path.resolve(fixtures, 'nospawn');
  28. var assertWatch = helper.assertTask(['server', 'watch'], {cwd:cwd});
  29. assertWatch(function() {
  30. var write = 'var nospawn = true;';
  31. grunt.file.write(path.join(cwd, 'lib', 'nospawn.js'), write);
  32. }, function(result) {
  33. helper.verboseLog(result);
  34. var count = result.match((new RegExp('Running "watch" task', 'g'))).length;
  35. test.equal(count, 2, 'Watch should have fired twice.');
  36. test.ok(result.indexOf('Server is listening...') !== -1, 'server should have been started.');
  37. test.ok(result.indexOf('Server is talking!') !== -1, 'server should have responded.');
  38. test.done();
  39. });
  40. },
  41. interrupt: function(test) {
  42. test.expect(2);
  43. var cwd = path.resolve(fixtures, 'nospawn');
  44. var assertWatch = helper.assertTask('watch', {cwd:cwd});
  45. assertWatch([function() {
  46. var write = 'var interrupt = true;';
  47. grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), write);
  48. setTimeout(function() {
  49. grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), write);
  50. }, 1000);
  51. }, function() {
  52. // Two functions needed to run two rounds of watching
  53. }], function(result) {
  54. helper.verboseLog(result);
  55. var count = result.match((new RegExp('Running "long" task', 'g'))).length;
  56. test.equal(count, 4, 'long task should have been ran only 4 times.');
  57. test.ok(result.indexOf('have been interrupted') !== -1, 'tasks should have been interrupted.');
  58. test.done();
  59. });
  60. },
  61. };