Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add cli.watch test.

  • Loading branch information...
commit d54c36c35b38a9ca48213a1f74046a958a611320 1 parent b7f031b
Cliffano Subagio authored

Showing 2 changed files with 26 additions and 7 deletions. Show diff stats Hide diff stats

  1. +3 3 lib/cli.js
  2. +23 4 test/cli.js
6 lib/cli.js
@@ -42,18 +42,18 @@ function exec() {
42 42 process.exit((err) ? 1 : 0);
43 43 });
44 44 });
45   -/*
  45 +
46 46 nomnom.command('watch').callback(function (args) {
47 47 console.log('Watching project');
48 48 var prms = require(p.join(process.cwd(), 'params'));
49 49 ae86.watch(function listener(curr, prev) {
50 50 if (curr.mtime > prev.mtime) {
51   - console.log('Regenerating website');
  51 + console.log('Change detected. Regenerating website');
52 52 ae86.gen(prms.params);
53 53 }
54 54 });
55 55 });
56   -*/
  56 +
57 57 nomnom.parseArgs();
58 58 }
59 59
27 test/cli.js
@@ -24,6 +24,11 @@ vows.describe('cli').addBatch({
24 24 assert.equal(params.foo, 'bar');
25 25 cb(ae86.err, ae86.results);
26 26 }
  27 + },
  28 + watch: function (listener) {
  29 + if (command === 'watch') {
  30 + listener({ mtime: 8 }, { mtime: 7 });
  31 + }
27 32 }
28 33 };
29 34 }
@@ -87,10 +92,11 @@ vows.describe('cli').addBatch({
87 92 cli.exec();
88 93 assert.equal(checks.code, 1);
89 94 assert.equal(checks.parseArgsCount, 1);
90   - assert.equal(checks.messages.length, 3);
  95 + assert.equal(checks.messages.length, 4);
91 96 assert.equal(checks.messages[0], 'Initialising project');
92 97 assert.equal(checks.messages[1], 'An error has occured. some error');
93 98 assert.equal(checks.messages[2], 'Generating website');
  99 + assert.equal(checks.messages[3], 'Watching project');
94 100 },
95 101 'should pass exit code 0 when init callback has no error': function (topic) {
96 102 var checks = {},
@@ -98,9 +104,10 @@ vows.describe('cli').addBatch({
98 104 cli.exec();
99 105 assert.equal(checks.code, 0);
100 106 assert.equal(checks.parseArgsCount, 1);
101   - assert.equal(checks.messages.length, 2);
  107 + assert.equal(checks.messages.length, 3);
102 108 assert.equal(checks.messages[0], 'Initialising project');
103 109 assert.equal(checks.messages[1], 'Generating website');
  110 + assert.equal(checks.messages[2], 'Watching project');
104 111 },
105 112 'should pass exit code 1 when gen callback has an error': function (topic) {
106 113 var checks = {},
@@ -108,10 +115,11 @@ vows.describe('cli').addBatch({
108 115 cli.exec();
109 116 assert.equal(checks.code, 1);
110 117 assert.equal(checks.parseArgsCount, 1);
111   - assert.equal(checks.messages.length, 3);
  118 + assert.equal(checks.messages.length, 4);
112 119 assert.equal(checks.messages[0], 'Initialising project');
113 120 assert.equal(checks.messages[1], 'Generating website');
114 121 assert.equal(checks.messages[2], 'An error has occured. some error');
  122 + assert.equal(checks.messages[3], 'Watching project');
115 123 },
116 124 'should pass exit code 0 when gen callback has no error': function (topic) {
117 125 var checks = {},
@@ -119,10 +127,21 @@ vows.describe('cli').addBatch({
119 127 cli.exec();
120 128 assert.equal(checks.code, 0);
121 129 assert.equal(checks.parseArgsCount, 1);
122   - assert.equal(checks.messages.length, 3);
  130 + assert.equal(checks.messages.length, 4);
123 131 assert.equal(checks.messages[0], 'Initialising project');
124 132 assert.equal(checks.messages[1], 'Generating website');
125 133 assert.equal(checks.messages[2], 'Total of 2 pages');
  134 + assert.equal(checks.messages[3], 'Watching project');
  135 + },
  136 + 'should watch with specified listener': function (topic) {
  137 + var checks = {},
  138 + cli = topic('watch', {}, checks);
  139 + cli.exec();
  140 + assert.equal(checks.messages.length, 4);
  141 + assert.equal(checks.messages[0], 'Initialising project');
  142 + assert.equal(checks.messages[1], 'Generating website');
  143 + assert.equal(checks.messages[2], 'Watching project');
  144 + assert.equal(checks.messages[3], 'Change detected. Regenerating website');
126 145 }
127 146 }
128 147 }).exportTo(module);

0 comments on commit d54c36c

Please sign in to comment.
Something went wrong with that request. Please try again.