|
| 1 | +/* |
| 2 | + * watch-test.js |
| 3 | + * |
| 4 | + * (C) 2010 and Charlie Robbins |
| 5 | + * MIT LICENSE |
| 6 | + * |
| 7 | + */ |
| 8 | + |
| 9 | +var assert = require('assert'), |
| 10 | + path = require('path'), |
| 11 | + fs = require('fs'), |
| 12 | + vows = require('vows'), |
| 13 | + forever = require('../lib/forever'); |
| 14 | + |
| 15 | +vows.describe('forever/watch').addBatch({ |
| 16 | + 'When using forever with watch enabled': { |
| 17 | + 'forever should': { |
| 18 | + topic: forever.start('daemon.js', { |
| 19 | + silent: true, |
| 20 | + options: ['-p', '8090'], |
| 21 | + watch: true, |
| 22 | + sourceDir: path.join(__dirname, 'fixtures', 'watch') |
| 23 | + }), |
| 24 | + 'have correct options set': function (child) { |
| 25 | + assert.isTrue(child.watchIgnoreDotFiles); |
| 26 | + assert.equal(fs.realpathSync(path.join(__dirname, 'fixtures', 'watch')), |
| 27 | + fs.realpathSync(child.watchDirectory)); |
| 28 | + }, |
| 29 | + 'when file changes': { |
| 30 | + topic: function (child) { |
| 31 | + child.once('restart', this.callback); |
| 32 | + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'file'), |
| 33 | + '// hello, I know nodejitsu.'); |
| 34 | + }, |
| 35 | + 'restart the script': function (child, _) { |
| 36 | + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'file'), |
| 37 | + '/* hello, I know nodejitsu. */'); |
| 38 | + } |
| 39 | + }, |
| 40 | + 'when file is added': { |
| 41 | + topic: function (child) { |
| 42 | + child.once('restart', this.callback); |
| 43 | + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'newFile'), ''); |
| 44 | + }, |
| 45 | + 'restart the script': function (child, _) { |
| 46 | + fs.unlinkSync(path.join(__dirname, 'fixtures', 'watch', 'newFile')); |
| 47 | + } |
| 48 | + }, |
| 49 | + 'when file is removed': { |
| 50 | + topic: function (child) { |
| 51 | + child.once('restart', this.callback); |
| 52 | + fs.unlinkSync(path.join(__dirname, 'fixtures', 'watch', 'removeMe')); |
| 53 | + }, |
| 54 | + 'restart the script': function (child, _) { |
| 55 | + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'removeMe'), ''); |
| 56 | + } |
| 57 | + }, |
| 58 | + 'read .foreverignore file': { |
| 59 | + 'and store ignore patterns': function (child) { |
| 60 | + assert.deepEqual( |
| 61 | + child.watchIgnorePatterns, |
| 62 | + fs.readFileSync( |
| 63 | + path.join(__dirname, 'fixtures', 'watch', '.foreverignore'), |
| 64 | + 'utf8' |
| 65 | + ).split("\n") |
| 66 | + ); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +}).export(module); |
| 72 | + |
0 commit comments