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.

60 lines
1.3 KiB

  1. module.exports = function(grunt) {
  2. 'use strict';
  3. var http = require('http');
  4. var port = 1337;
  5. grunt.initConfig({
  6. watch: {
  7. nospawn: {
  8. files: ['lib/nospawn.js'],
  9. tasks: ['server'],
  10. options: {
  11. nospawn: true,
  12. },
  13. },
  14. spawn: {
  15. files: ['lib/spawn.js'],
  16. tasks: ['server'],
  17. },
  18. interrupt: {
  19. files: ['lib/interrupt.js'],
  20. tasks: ['long', 'long', 'long'],
  21. options: {
  22. nospawn: true,
  23. interrupt: true,
  24. },
  25. },
  26. },
  27. });
  28. // Load this watch task
  29. grunt.loadTasks('../../../tasks');
  30. // Our test server task
  31. var server;
  32. grunt.registerTask('server', function() {
  33. if (!server) {
  34. server = http.createServer(function(req, res) {
  35. res.writeHead(200, {'Content-Type': 'text/plain'});
  36. res.end('Server is talking!');
  37. }).listen(port);
  38. grunt.log.writeln('Server is listening...');
  39. } else {
  40. var done = this.async();
  41. http.request({port: port}, function(res) {
  42. res.on('data', function(buf) {
  43. grunt.log.writeln(buf);
  44. done();
  45. });
  46. }).end();
  47. }
  48. });
  49. // A long running task
  50. grunt.registerTask('long', function() {
  51. setTimeout(this.async(), 2000);
  52. });
  53. grunt.registerTask('default', ['server', 'watch']);
  54. };