Skip to content

Commit 5930d79

Browse files
committed
Add Gruntfile and initial tests
1 parent 587fbf7 commit 5930d79

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed

Gruntfile.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = function(grunt) {
2+
3+
// Project configuration.
4+
grunt.initConfig({
5+
pkg: grunt.file.readJSON('package.json'),
6+
7+
// Js Hint
8+
jshint: {
9+
options: {
10+
reporter: require('jshint-stylish')
11+
},
12+
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
13+
},
14+
15+
// Jamsine
16+
jasmine: {
17+
emailBuilder: {
18+
src: 'index.js',
19+
options: {
20+
specs: 'test/specs/*Spec.js',
21+
helpers: 'test/spec/*Helper.js'
22+
}
23+
}
24+
}
25+
});
26+
27+
// Load tasks
28+
grunt.loadNpmTasks('grunt-contrib-jshint');
29+
grunt.loadNpmTasks('grunt-contrib-jasmine');
30+
31+
// Default task(s).
32+
grunt.registerTask('default', ['jshint']);
33+
grunt.registerTask('test', ['jshint', 'jasmine']);
34+
35+
};

lib/emailBuilder.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function EmailBuilder(task) {
2424
this.task = task;
2525
this.options = task.options(EmailBuilder.Defaults);
2626
this.basepath = process.cwd();
27+
2728
}
2829

2930
EmailBuilder.taskName = 'emailBuilder';
@@ -88,7 +89,7 @@ EmailBuilder.prototype.handleConditionals = function(html){
8889

8990
EmailBuilder.prototype.prepareHtml = function(file) {
9091

91-
var html = this.grunt.file.read(file),
92+
var html = this.grunt.file.read(file),
9293
$ = cheerio.load(html),
9394
styleTags = $('style'),
9495
linkTags = $('link'),
@@ -326,27 +327,9 @@ EmailBuilder.prototype.run = function() {
326327
.then(this.sendEmailTest);
327328

328329
})
329-
.catch(function(err){ this.grunt.log.error(err); });
330-
};
331-
332-
333-
EmailBuilder.registerWithGrunt = function(grunt) {
334-
335-
// Please see the grunt documentation for more information regarding task and
336-
// helper creation: https://github.com/gruntjs/grunt/blob/master/docs/toc.md
337-
338-
// ==========================================================================
339-
// TASKS
340-
// ==========================================================================
341-
342-
grunt.registerMultiTask(EmailBuilder.taskName, EmailBuilder.taskDescription, function() {
343-
344-
this.grunt = grunt;
345-
var done = this.async();
346-
var task = new EmailBuilder(this);
330+
.catch(function(err){
347331

348-
task.run()
349-
.done(done);
332+
this.grunt.log.error(err);
350333

351334
});
352335
};

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Email builder core",
55
"main": "index.js",
66
"scripts": {
7-
"test": "test"
7+
"test": "grunt test"
88
},
99
"repository": {
1010
"type": "git",
@@ -22,6 +22,9 @@
2222
"lodash": "^2.4.1"
2323
},
2424
"devDependencies": {
25-
"grunt": "^0.4.5"
25+
"grunt": "^0.4.5",
26+
"grunt-contrib-jasmine": "^0.8.1",
27+
"grunt-contrib-jshint": "^0.10.0",
28+
"jshint-stylish": "^1.0.0"
2629
}
2730
}

test/specs/EmailBuilderSpec.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
describe("Calendar Stuff", function() {
2+
var emailBuilder;
3+
4+
beforeEach(function() {
5+
emailBuilder = new EmailBuilder();
6+
});
7+
8+
describe('Something something', function() {
9+
var today;
10+
11+
beforeEach(function() {
12+
today = new Date();
13+
});
14+
15+
it('should be main entry', function() {
16+
var expected = '<strong>10:00</strong> AM';
17+
var unit = 'hours';
18+
var minutesFrom = 60;
19+
20+
today.setHours(10, 0, 0, 0);
21+
var dateString = calendar.constructTimeEntry(today, minutesFrom, unit);
22+
23+
expect(dateString.date).toBe('<strong>10:00</strong> AM');
24+
});
25+
26+
27+
});
28+
29+
30+
});

0 commit comments

Comments
 (0)