Skip to content
Browse files

more tests

  • Loading branch information...
1 parent 5bd770e commit f03b273c62c36cb07a8f1767dc6198738dbee2f0 @treasonx committed
Showing with 73 additions and 12 deletions.
  1. +2 −1 Gruntfile.js
  2. +3 −1 package.json
  3. +68 −10 test/markdown_test.js
View
3 Gruntfile.js
@@ -6,7 +6,7 @@ module.exports = function(grunt) {
all: ['test/**/*.js']
},
watch: {
- files: '<%= jshint.files %>',
+ files: ['<%= jshint.files %>', 'test/**/*.js'],
tasks: 'default'
},
markdown: {
@@ -72,5 +72,6 @@ module.exports = function(grunt) {
// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);
+ grunt.registerTask('dev', ['watch', 'jshint', 'nodeunit']);
};
View
4 package.json
@@ -41,7 +41,9 @@
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.3.0",
"grunt-contrib-nodeunit": "~0.1.2",
- "grunt-contrib-watch": "~0.3.1"
+ "grunt-contrib-watch": "~0.3.1",
+ "mocha": "~1.11.0",
+ "cheerio": "~0.12.0"
},
"keywords": [
"gruntplugin"
View
78 test/markdown_test.js
@@ -2,6 +2,7 @@
var grunt = require('grunt');
var markdown = require('../tasks/lib/markdown').init(grunt);
+var cheerio = require('cheerio');
/*
======== A Handy Little Nodeunit Reference ========
@@ -23,21 +24,78 @@ var markdown = require('../tasks/lib/markdown').init(grunt);
test.ifError(value)
*/
+var filepath = 'test/samples/javascript.md';
+var file = grunt.file.read(filepath);
+var templatepath = 'tasks/template.html';
+var template = grunt.file.read(templatepath);
+var html = null;
+var $result = null;
+var options = {};
+
+function getjQuery() {
+ html = markdown.markdown(file, options, template);
+ $result = cheerio(html);
+}
+
exports['markdown'] = {
setUp: function(done) {
- // setup here
+ done();
+ },
+ tearDown: function(done) {
+ options = {};
done();
},
'helper': function(test) {
- test.expect(1);
- // tests here
- var filepath = 'test/samples/javascript.md';
- var file = grunt.file.read(filepath);
- var options = {};
- var templatepath = 'tasks/template.html';
- var template = grunt.file.read(templatepath);
- var html = markdown.markdown(file, options, template);
- test.ok(html.match(/<body>/), "should have body");
+ getjQuery();
+ test.ok($result.find('body').length === 1, 'should have body');
+ test.done();
+ },
+ 'basic code highlight': function(test) {
+ getjQuery();
+ test.ok($result.find('code.lang-javascript').length === 1, 'should have 1 js code block');
+ test.ok($result.find('code.lang-json').length === 1, 'should have 1 json code block');
+ test.done();
+
+ },
+ 'hjs code hightlight': function(test) {
+ getjQuery();
+ test.ok($result.find('body').length === 1, 'should have body');
test.done();
+
+ },
+ 'should have header': function(test) {
+ getjQuery();
+ test.ok($result.find('h1').length === 1, 'should have h1');
+ test.done();
+
+ },
+ 'should have header text': function(test) {
+ getjQuery();
+ test.ok($result.find('h1').text() === 'This is a test of GFM for javascript', 'should have proper text');
+ test.done();
+
+ },
+ 'should have one list': function(test) {
+ getjQuery();
+ test.ok($result.find('ul li').length === 2, 'should have 2 items in the list');
+ test.done();
+
+ },
+ 'should have a link': function(test) {
+ getjQuery();
+ var $a = $result.find('a');
+ test.ok($a.text() === 'markdown', 'should have link text');
+ test.ok($a.attr('href') === 'http://daringfireball.net/projects/markdown/syntax', 'should have link target');
+ test.done();
+
+ },
+
+ 'should have inline code': function(test) {
+ getjQuery();
+ var $a = $result.find('p code');
+ test.ok($a.text() === 'json', 'should have code text');
+ test.done();
+
}
+
};

0 comments on commit f03b273

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