From d891990cd4bf57dfb05163731e7ef86a74e11692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Sat, 1 Oct 2011 12:48:25 +0200 Subject: [PATCH] [test] Add tests for watch Please note that tests are synchronous because of possible race conditions. --- test/watch-test.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 test/watch-test.js diff --git a/test/watch-test.js b/test/watch-test.js new file mode 100644 index 00000000..1ddb43ed --- /dev/null +++ b/test/watch-test.js @@ -0,0 +1,72 @@ +/* + * watch-test.js + * + * (C) 2010 and Charlie Robbins + * MIT LICENSE + * + */ + +var assert = require('assert'), + path = require('path'), + fs = require('fs'), + vows = require('vows'), + forever = require('../lib/forever'); + +vows.describe('forever/watch').addBatch({ + 'When using forever with watch enabled': { + 'forever should': { + topic: forever.start('daemon.js', { + silent: true, + options: ['-p', '8090'], + watch: true, + sourceDir: path.join(__dirname, 'fixtures', 'watch') + }), + 'have correct options set': function (child) { + assert.isTrue(child.watchIgnoreDotFiles); + assert.equal(fs.realpathSync(path.join(__dirname, 'fixtures', 'watch')), + fs.realpathSync(child.watchDirectory)); + }, + 'when file changes': { + topic: function (child) { + child.once('restart', this.callback); + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'file'), + '// hello, I know nodejitsu.'); + }, + 'restart the script': function (child, _) { + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'file'), + '/* hello, I know nodejitsu. */'); + } + }, + 'when file is added': { + topic: function (child) { + child.once('restart', this.callback); + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'newFile'), ''); + }, + 'restart the script': function (child, _) { + fs.unlinkSync(path.join(__dirname, 'fixtures', 'watch', 'newFile')); + } + }, + 'when file is removed': { + topic: function (child) { + child.once('restart', this.callback); + fs.unlinkSync(path.join(__dirname, 'fixtures', 'watch', 'removeMe')); + }, + 'restart the script': function (child, _) { + fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'removeMe'), ''); + } + }, + 'read .foreverignore file': { + 'and store ignore patterns': function (child) { + assert.deepEqual( + child.watchIgnorePatterns, + fs.readFileSync( + path.join(__dirname, 'fixtures', 'watch', '.foreverignore'), + 'utf8' + ).split("\n") + ); + } + } + } + } +}).export(module); +