Permalink
Browse files

Add cli.watch test.

  • Loading branch information...
1 parent b7f031b commit d54c36c35b38a9ca48213a1f74046a958a611320 @cliffano committed Dec 10, 2011
Showing with 26 additions and 7 deletions.
  1. +3 −3 lib/cli.js
  2. +23 −4 test/cli.js
View
6 lib/cli.js
@@ -42,18 +42,18 @@ function exec() {
process.exit((err) ? 1 : 0);
});
});
-/*
+
nomnom.command('watch').callback(function (args) {
console.log('Watching project');
var prms = require(p.join(process.cwd(), 'params'));
ae86.watch(function listener(curr, prev) {
if (curr.mtime > prev.mtime) {
- console.log('Regenerating website');
+ console.log('Change detected. Regenerating website');
ae86.gen(prms.params);
}
});
});
-*/
+
nomnom.parseArgs();
}
View
27 test/cli.js
@@ -24,6 +24,11 @@ vows.describe('cli').addBatch({
assert.equal(params.foo, 'bar');
cb(ae86.err, ae86.results);
}
+ },
+ watch: function (listener) {
+ if (command === 'watch') {
+ listener({ mtime: 8 }, { mtime: 7 });
+ }
}
};
}
@@ -87,42 +92,56 @@ vows.describe('cli').addBatch({
cli.exec();
assert.equal(checks.code, 1);
assert.equal(checks.parseArgsCount, 1);
- assert.equal(checks.messages.length, 3);
+ assert.equal(checks.messages.length, 4);
assert.equal(checks.messages[0], 'Initialising project');
assert.equal(checks.messages[1], 'An error has occured. some error');
assert.equal(checks.messages[2], 'Generating website');
+ assert.equal(checks.messages[3], 'Watching project');
},
'should pass exit code 0 when init callback has no error': function (topic) {
var checks = {},
cli = topic('init', {}, checks);
cli.exec();
assert.equal(checks.code, 0);
assert.equal(checks.parseArgsCount, 1);
- assert.equal(checks.messages.length, 2);
+ assert.equal(checks.messages.length, 3);
assert.equal(checks.messages[0], 'Initialising project');
assert.equal(checks.messages[1], 'Generating website');
+ assert.equal(checks.messages[2], 'Watching project');
},
'should pass exit code 1 when gen callback has an error': function (topic) {
var checks = {},
cli = topic('gen', { err: new Error('some error')}, checks);
cli.exec();
assert.equal(checks.code, 1);
assert.equal(checks.parseArgsCount, 1);
- assert.equal(checks.messages.length, 3);
+ assert.equal(checks.messages.length, 4);
assert.equal(checks.messages[0], 'Initialising project');
assert.equal(checks.messages[1], 'Generating website');
assert.equal(checks.messages[2], 'An error has occured. some error');
+ assert.equal(checks.messages[3], 'Watching project');
},
'should pass exit code 0 when gen callback has no error': function (topic) {
var checks = {},
cli = topic('gen', { results: ['index.html', 'contact.html'] }, checks);
cli.exec();
assert.equal(checks.code, 0);
assert.equal(checks.parseArgsCount, 1);
- assert.equal(checks.messages.length, 3);
+ assert.equal(checks.messages.length, 4);
assert.equal(checks.messages[0], 'Initialising project');
assert.equal(checks.messages[1], 'Generating website');
assert.equal(checks.messages[2], 'Total of 2 pages');
+ assert.equal(checks.messages[3], 'Watching project');
+ },
+ 'should watch with specified listener': function (topic) {
+ var checks = {},
+ cli = topic('watch', {}, checks);
+ cli.exec();
+ assert.equal(checks.messages.length, 4);
+ assert.equal(checks.messages[0], 'Initialising project');
+ assert.equal(checks.messages[1], 'Generating website');
+ assert.equal(checks.messages[2], 'Watching project');
+ assert.equal(checks.messages[3], 'Change detected. Regenerating website');
}
}
}).exportTo(module);

0 comments on commit d54c36c

Please sign in to comment.