Permalink
Browse files

created working tests

  • Loading branch information...
1 parent f3d2704 commit dabfc4ef41c4c96b7237d8c50978a80a9831f09a @patrickkettner committed Apr 8, 2013
View
@@ -1 +1,2 @@
node_modules
+tmp
View
@@ -30,16 +30,20 @@ module.exports = function(grunt) {
// Configuration to be run (and then tested).
'compile-handlebars': {
dev: {
- preHTML: 'src/pre-dev.html',
- postHTML: 'src/post-dev.html',
- template: 'src/template.handlebars',
- templateData: grunt.file.readJSON('src/data.json'),
- output: 'index.html'
+ preHTML: 'test/fixtures/pre-dev.html',
+ postHTML: 'test/fixtures/post-dev.html',
+ template: 'test/fixtures/template.handlebars',
+ templateData: {
+ "salutation": "Hallo",
+ "punctuation": ",",
+ "location": "Welt"
+ },
+ output: 'tmp/dev.html'
},
prod: {
- template: 'src/template.handlebars',
- templateData: grunt.file.readJSON('src/data.json'),
- output: 'dist/index.html'
+ template: 'test/fixtures/template.handlebars',
+ templateData: grunt.file.readJSON('test/fixtures/data.json'),
+ output: 'tmp/prod.html'
}
},
@@ -11,32 +11,19 @@
module.exports = function(grunt) {
var handlebars = require('handlebars');
- function compileHandlebars(config) {
- if (config) {
- var template = grunt.file.read(config.template);
- var compiledTemplate = handlebars.compile(template);
- var html = '';
-
- if (config.preHTML) html += grunt.file.read(config.preHTML);
-
- html += compiledTemplate(config.template);
-
- if (config.postHTML) html += grunt.file.read(config.postHTML);
-
- return html;
+ grunt.registerMultiTask('compile-handlebars', 'Compile Handlebars templates ', function() {
- }
- }
+ var config = this.data;
+ var template = grunt.file.read(config.template);
+ var compiledTemplate = handlebars.compile(template);
+ var html = '';
+ if (config.preHTML) html += grunt.file.read(config.preHTML);
- // ==========================================================================
- // TASKS
- // ==========================================================================
+ html += compiledTemplate(config.templateData);
- grunt.registerMultiTask('compile-handlebars', 'Compile Handlebars templates ', function() {
- var compiledHTML = compileHandlebars(this.data);
+ if (config.postHTML) html += grunt.file.read(config.postHTML);
- grunt.log.write(grunt.helper('compile-handlebars'));
- grunt.file.write(this.data.output, compiledHTML);
+ grunt.file.write(this.data.output, html);
});
};
@@ -6,12 +6,20 @@ exports.clean = {
dev: function(test) {
test.expect(1);
+ var actual = grunt.file.read('tmp/dev.html');
+ var expected = grunt.file.read('test/expected/dev.html');
+
+ test.equal(actual, expected, 'should be equal to premade static file with pre and post files');
test.done();
},
prod: function(test) {
test.expect(1);
+ var actual = grunt.file.read('tmp/prod.html');
+ var expected = grunt.file.read('test/expected/prod.html');
+
+ test.equal(actual, expected, 'should be equal to premade static file');
test.done();
}
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>static local</title>
+ <script src="static/local/script.js"></script>
+ <link rel="stylesheet" href="static/local/stylesheet.css">
+</head>
+<body>
+ <header>static local header</header>
+<h1>Hallo, Welt</h1>
+</body>
+</html>
@@ -0,0 +1 @@
+<h1>Hello, World</h1>
@@ -0,0 +1,5 @@
+{
+ "salutation": "Hello",
+ "punctuation": ",",
+ "location": "World"
+}
@@ -0,0 +1,2 @@
+</body>
+</html>
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>static local</title>
+ <script src="static/local/script.js"></script>
+ <link rel="stylesheet" href="static/local/stylesheet.css">
+</head>
+<body>
+ <header>static local header</header>
@@ -0,0 +1 @@
+<h1>{{salutation}}{{punctuation}} {{location}}</h1>
View
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>local dev</title>
+</head>
+<body>
+ <header>local dev</header>
+<h1> </h1>
+
+</body>
+</html>

0 comments on commit dabfc4e

Please sign in to comment.