Skip to content

Commit

Permalink
Add test for custom markdown parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed May 7, 2015
1 parent c57bde1 commit ad90e7b
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
96 changes: 96 additions & 0 deletions test/custom_markdown_parser_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*jshint unused:false, expr:true */

/**
* Test: apiDoc full parse
*/

// node modules
var apidoc = require('apidoc-core');
var exec = require('child_process').exec;
var fs = require('fs-extra');
var path = require('path');
var semver = require('semver');
var should = require('should');

var versions = require('apidoc-example').versions;

describe('apiDoc custom markdown parser', function() {

// get latest example for the used apidoc-spec
var latestExampleVersion = semver.maxSatisfying(versions, '~' + apidoc.getSpecificationVersion()); // ~0.2.0 = >=0.2.0 <0.3.0

var exampleBasePath = 'node_modules/apidoc-example/' + latestExampleVersion;
var fixturePath = exampleBasePath + '/fixtures';

var fixtureFiles = [
'api_data.js',
'api_data.json',
'api_project.js',
'api_project.json',
'index.html'
];

var markdownFile = './fixtures/custom_markdown_parser.js';
var markdownFileBase = '../test/fixtures/custom_markdown_parser.js';

before(function(done) {
fs.removeSync('./tmp/');

done();
});

after(function(done) {
done();
});

// Render static text.
it('should render static text with custom markdown parser', function(done) {
var Markdown = require(markdownFile);
var markdownParser = new Markdown();
var text = markdownParser.render('some text');
should(text).equal('Custom Markdown Parser: some text');
done();
});

// create
it('should create example in tmp/', function(done) {
var cmd = 'node ./bin/apidoc -i ' + exampleBasePath + '/src/ -o tmp/ -t test/template/ --markdown ' + markdownFileBase + ' --silent';
exec(cmd, function(err, stdout, stderr) {
if (err)
throw err;

if (stderr)
throw stderr;

done();
});
});

// check
it('should find created files', function(done) {
fixtureFiles.forEach(function(name) {
fs.existsSync(fixturePath + '/' + name).should.eql(true);
});
done();
});

// Count how many custom parser text inserts where found.
it('created files should have custom text', function(done) {
var countCustomText = 0;
fixtureFiles.forEach(function(name) {
var createdContent = fs.readFileSync('./tmp/' + name, 'utf8');

var createdLines = createdContent.split(/\r\n/);

for (var lineNumber = 0; lineNumber < createdLines.length; lineNumber += 1) {
if (createdLines[lineNumber].indexOf('Custom Markdown Parser: ') !== -1)
countCustomText++;
}
});

should.notEqual(countCustomText, 0);

done();
});

});
22 changes: 22 additions & 0 deletions test/fixtures/custom_markdown_parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Custom Markdown Parser example.
*/
function CustomMarkdownParser() {
// Some init stuff.
}

/**
* Exports.
*/
module.exports = CustomMarkdownParser;

/**
* Render a markdown Text to HTML.
*
* @param {String} text Markdown Text.
* @returns {String} Converted HTML Text.
*/
CustomMarkdownParser.prototype.render = function(text) {
// Here would be the markdown-Parser call.
return 'Custom Markdown Parser: ' + text;
};

0 comments on commit ad90e7b

Please sign in to comment.