Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add cli.watch test.

  • Loading branch information...
commit d54c36c35b38a9ca48213a1f74046a958a611320 1 parent b7f031b
Cliffano Subagio authored
Showing with 26 additions and 7 deletions.
  1. +3 −3 lib/cli.js
  2. +23 −4 test/cli.js
6 lib/cli.js
View
@@ -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();
}
27 test/cli.js
View
@@ -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,10 +92,11 @@ 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 = {},
@@ -98,9 +104,10 @@ vows.describe('cli').addBatch({
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 = {},
@@ -108,10 +115,11 @@ 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], '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 = {},
@@ -119,10 +127,21 @@ vows.describe('cli').addBatch({
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);
Please sign in to comment.
Something went wrong with that request. Please try again.