Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #67 from twitter/hulk-tests

add tests + docs for hulk
  • Loading branch information...
commit a0254158556b698d6089e9b81fe8f2d2d983beb1 2 parents 4c6557c + a09770b
@sayrer sayrer authored
Showing with 79 additions and 11 deletions.
  1. +6 −0 Makefile
  2. +11 −9 bin/hulk
  3. +42 −0 test/hulk.js
  4. +20 −2 web/index.html.mustache
View
6 Makefile
@@ -9,6 +9,12 @@ test:
@ node test/run.js test/index.html
#
+# Run hulk tests
+#
+hulk:
+ @ node test/hulk.js
+
+#
# Run Mustache spec tests
#
spec:
View
20 bin/hulk
@@ -15,13 +15,15 @@
* limitations under the License.
*/
-var hogan = require('../lib/hogan.js'),
- path = require('path'),
- fs = require('fs');
+// dependencies
+var hogan = require('../lib/hogan.js')
+ , path = require('path')
+ , fs = require('fs');
-var specials = ['/', '.', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\\'],
- specialsRegExp = new RegExp('(\\' + specials.join('|\\') + ')', 'g'),
- templates;
+// locals
+var specials = ['/', '.', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\\']
+ , specialsRegExp = new RegExp('(\\' + specials.join('|\\') + ')', 'g')
+ , templates;
// Escape special regexp characters
@@ -32,13 +34,13 @@ function esc(text) {
// Check for dirs and correct ext (<3 for windows)
function extractFiles(args) {
- var usage = 'USAGE: hulk ./templates/*.mustaches\n' +
- 'NOTE: hulk supports the "*" wildcard and allows you to target specific extensions too',
+ var usage = '\033[36mUSAGE:\033[39m hulk ./templates/*.mustaches\n' +
+ '\033[36mNOTE:\033[39m hulk supports the "*" wildcard and allows you to target specific extensions too',
files = [];
if (!args.length) {
console.log(usage);
- process.exit(-1);
+ process.exit(0);
}
args.forEach(function (arg) {
View
42 test/hulk.js
@@ -0,0 +1,42 @@
+var exec = require('child_process').exec
+ , assert = require('assert')
+ , Hogan = require('../lib/hogan.js');
+
+
+// help text
+exec('node bin/hulk', function (error, stdout, stderr) {
+ if (error) throw error;
+ assert(typeof stdout == 'string', 'it should have help text.');
+ assert(/USAGE/.test(stdout), 'has USAGE text');
+ assert(/NOTE/.test(stdout), 'has NOTE text about wildcard');
+})
+
+// templates wildcard
+exec('node bin/hulk test/templates/*', function (error, stdout, stderr) {
+ if (error) throw error;
+ eval(stdout);
+ assert(typeof templates == 'object', 'defineed a templates object');
+ assert(typeof templates.list == 'object', 'defined a templates.list object');
+ assert(typeof templates.list.r == 'function', 'defined a templates.list.r function');
+ assert(templates.list.r() == '<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>')
+});
+
+// templates wildcard w/ extension
+exec('node bin/hulk test/templates/*.mustache', function (error, stdout, stderr) {
+ if (error) throw error;
+ eval(stdout);
+ assert(typeof templates == 'object', 'defineed a templates object');
+ assert(typeof templates.list == 'object', 'defined a templates.list object');
+ assert(typeof templates.list.r == 'function', 'defined a templates.list.r function');
+ assert(templates.list.r() == '<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>')
+});
+
+// templates single file
+exec('node bin/hulk test/templates/list.mustache', function (error, stdout, stderr) {
+ if (error) throw error;
+ eval(stdout);
+ assert(typeof templates == 'object', 'defineed a templates object');
+ assert(typeof templates.list == 'object', 'defined a templates.list object');
+ assert(typeof templates.list.r == 'function', 'defined a templates.list.r function');
+ assert(templates.list.r() == '<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>')
+});
View
22 web/index.html.mustache
@@ -117,6 +117,26 @@
<div class="ten columns offset-by-one">
<script src="https://gist.github.com/1575714.js"> </script>
</div>
+ <div class="hogan-divider">
+ <div class="hogan-icon"></div>
+ </div>
+
+
+ <!-- Layout 5 -->
+ <div class="five columns">
+ <h4 id='rendering'>Hulk</h4>
+ <p>
+ Hulk is Hogan's command line utility. Use it to easily compile your templates as js files.
+ </p>
+ <p>
+ Hulk supports the <code>*</code> wilcard (even on windows) and allows you to target specific file extensions as well.</p>
+ <p>
+ </p>
+ </div>
+
+ <div class="ten columns offset-by-one">
+ <script src="https://gist.github.com/2322961.js"> </script>
+ </div>
<div class="sixteen columns hogan-footer">
<span class="copyright">
@@ -128,8 +148,6 @@
</span>
</div>
-
-
</div><!-- container -->
Please sign in to comment.
Something went wrong with that request. Please try again.