mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Modified test runner to support extension tests as well
This commit is contained in:
parent
7db254fcb2
commit
9d0a929fac
5
test/extensions/twitter/basic.html
Normal file
5
test/extensions/twitter/basic.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<p>Testing of the twitter extension.</p>
|
||||
|
||||
<p>Ping <a href="http://twitter.com/andstuff">@andstuff</a> to find out more about <a href="http://twitter.com/search/%23extensions">#extensions</a> with showdown</p>
|
||||
|
||||
<p>And @something shouldn't render as a twitter link</p>
|
5
test/extensions/twitter/basic.md
Normal file
5
test/extensions/twitter/basic.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
Testing of the twitter extension.
|
||||
|
||||
Ping @andstuff to find out more about #extensions with showdown
|
||||
|
||||
And \@something shouldn't render as a twitter link
|
60
test/run.js
60
test/run.js
|
@ -1,25 +1,27 @@
|
|||
var showdown = new require('../src/showdown'),
|
||||
convertor = new showdown.converter(),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
should = require('should');
|
||||
|
||||
|
||||
var runTestsInDir = function(dir, converter) {
|
||||
|
||||
// Load test cases from disk
|
||||
var cases = fs.readdirSync('test/cases').filter(function(file){
|
||||
var cases = fs.readdirSync(dir).filter(function(file){
|
||||
return ~file.indexOf('.md');
|
||||
}).map(function(file){
|
||||
return file.replace('.md', '');
|
||||
});
|
||||
|
||||
// Run each test case
|
||||
// Run each test case (markdown -> html)
|
||||
cases.forEach(function(test){
|
||||
var name = test.replace(/[-.]/g, ' ');
|
||||
it (name, function(){
|
||||
var mdpath = path.join('test/cases', test + '.md'),
|
||||
htmlpath = path.join('test/cases', test + '.html'),
|
||||
var mdpath = path.join(dir, test + '.md'),
|
||||
htmlpath = path.join(dir, test + '.html'),
|
||||
md = fs.readFileSync(mdpath, 'utf8'),
|
||||
expected = fs.readFileSync(htmlpath, 'utf8').trim(),
|
||||
actual = convertor.makeHtml(md).trim();
|
||||
actual = converter.makeHtml(md).trim();
|
||||
|
||||
// Normalize line returns
|
||||
expected = expected.replace(/\r/g, '');
|
||||
|
@ -42,3 +44,49 @@ cases.forEach(function(test){
|
|||
actual.should.equal(expected);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// :: Markdown to HTML testing ::
|
||||
//
|
||||
|
||||
describe('Markdown', function() {
|
||||
var converter = new showdown.converter();
|
||||
runTestsInDir('test/cases', converter);
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// :: Extensions Testing ::
|
||||
//
|
||||
|
||||
if (path.existsSync('test/extensions')) {
|
||||
|
||||
describe('extensions', function() {
|
||||
// Search all sub-folders looking for directory-specific tests
|
||||
var extensions = fs.readdirSync('test/extensions').filter(function(file){
|
||||
return fs.lstatSync('test/extensions/' + file).isDirectory();
|
||||
});
|
||||
|
||||
// Run tests in each extension sub-folder
|
||||
extensions.forEach(function(ext){
|
||||
// Make sure extension exists
|
||||
var src = 'src/extensions/' + ext + '.js';
|
||||
if (!path.existsSync(src)) {
|
||||
throw "Attempting tests for '" + ext + "' but sourc file (" + src + ") was not found.";
|
||||
}
|
||||
|
||||
// Build converter with extension included
|
||||
var extension = require('../src/extensions/' + ext);
|
||||
if (!extension) {
|
||||
throw "Could not load extension '" + ext + "'. Did you forget module.exports?";
|
||||
}
|
||||
|
||||
var converter = new showdown.converter({ extensions: [ extension ] });
|
||||
var dir = 'test/extensions/' + ext;
|
||||
runTestsInDir(dir, converter);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user