Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
treasonx committed Jun 13, 2013
1 parent 5bd770e commit f03b273
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Expand Up @@ -6,7 +6,7 @@ module.exports = function(grunt) {
all: ['test/**/*.js']
},
watch: {
files: '<%= jshint.files %>',
files: ['<%= jshint.files %>', 'test/**/*.js'],
tasks: 'default'
},
markdown: {
Expand Down Expand Up @@ -72,5 +72,6 @@ module.exports = function(grunt) {

// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);
grunt.registerTask('dev', ['watch', 'jshint', 'nodeunit']);

};
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -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"
Expand Down
78 changes: 68 additions & 10 deletions test/markdown_test.js
Expand Up @@ -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 ========
Expand All @@ -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.