showdown/test/performance/performance.js
Estevão Soares dos Santos 9a66e63952 assorted changes
2022-05-07 18:59:09 +01:00

133 lines
4.6 KiB
JavaScript

/**
* Created by Tivie on 21/12/2016.
*/
'use strict';
var fs = require('fs'),
showdown = require('../../.build/showdown.js'),
converter = new showdown.Converter(),
pkg = require('../../package.json'),
performance = require('./lib/performance.lib.js');
performance.setLibraryName(pkg.name);
performance.setVersion(pkg.version);
performance.setGithubLink('https://github.com/showdownjs/showdown/tree/');
var globals = {
gHtmlBlocks: [],
gHtmlMdBlocks: [],
gHtmlSpans: [],
gUrls: {},
gTitles: {},
gDimensions: {},
gListLevel: 0,
hashLinkCounts: {},
langExtensions: [],
outputModifiers: [],
converter: converter,
ghCodeBlocks: []
},
options = showdown.getOptions();
function runTests () {
var testMDFile = fs.readFileSync('test/performance.testfile.md', 'utf8');
new performance.Suite('Basic')
.setOption('cycles', 50)
.add('Simple "Hello World"', function () {
converter.makeHtml('*Hello* **World**!');
})
.add('performance.testfile.md', {
prepare: function () {
return testMDFile;
},
test: function (mdText) {
converter.makeHtml(mdText);
}
});
new performance.Suite('subParsers')
.setOption('cycles', 20)
.add('hashHTMLBlocks', function () {
showdown.subParser('makehtml.hashHTMLBlocks')(testMDFile, options, globals);
})
.add('anchors', function () {
showdown.subParser('makehtml.link')(testMDFile, options, globals);
})
.add('blockQuotes', function () {
showdown.subParser('makehtml.blockquote')(testMDFile, options, globals);
})
.add('codeBlocks', function () {
showdown.subParser('makehtml.codeBlock')(testMDFile, options, globals);
})
.add('codeSpans', function () {
showdown.subParser('makehtml.codeSpan')(testMDFile, options, globals);
})
.add('encodeAmpsAndAngles', function () {
showdown.subParser('makehtml.encodeAmpsAndAngles')(testMDFile, options, globals);
})
.add('encodeBackslashEscapes', function () {
showdown.subParser('makehtml.encodeBackslashEscapes')(testMDFile, options, globals);
})
.add('encodeCode', function () {
showdown.subParser('makehtml.encodeCode')(testMDFile, options, globals);
})
.add('escapeSpecialCharsWithinTagAttributes', function () {
showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(testMDFile, options, globals);
})
.add('githubCodeBlocks', function () {
showdown.subParser('makehtml.githubCodeBlock')(testMDFile, options, globals);
})
.add('hashBlock', function () {
showdown.subParser('makehtml.hashBlock')(testMDFile, options, globals);
})
.add('hashElement', function () {
showdown.subParser('makehtml.hashElement')(testMDFile, options, globals);
})
.add('hashHTMLSpans', function () {
showdown.subParser('makehtml.hashHTMLSpans')(testMDFile, options, globals);
})
.add('hashPreCodeTags', function () {
showdown.subParser('makehtml.hashPreCodeTags')(testMDFile, options, globals);
})
.add('headers', function () {
showdown.subParser('makehtml.heading')(testMDFile, options, globals);
})
.add('horizontalRule', function () {
showdown.subParser('makehtml.horizontalRule')(testMDFile, options, globals);
})
.add('images', function () {
showdown.subParser('makehtml.image')(testMDFile, options, globals);
})
.add('italicsAndBold', function () {
showdown.subParser('makehtml.emphasisAndStrong')(testMDFile, options, globals);
})
.add('lists', function () {
showdown.subParser('makehtml.list')(testMDFile, options, globals);
})
.add('paragraphs', function () {
showdown.subParser('makehtml.paragraphs')(testMDFile, options, globals);
})
.add('spanGamut', function () {
showdown.subParser('makehtml.spanGamut')(testMDFile, options, globals);
})
.add('strikethrough', function () {
showdown.subParser('makehtml.strikethrough')(testMDFile, options, globals);
})
.add('stripLinkDefinitions', function () {
showdown.subParser('makehtml.stripLinkDefinitions')(testMDFile, options, globals);
})
.add('tables', function () {
showdown.subParser('makehtml.table')(testMDFile, options, globals);
})
.add('unescapeSpecialChars', function () {
showdown.subParser('makehtml.unescapeSpecialChars')(testMDFile, options, globals);
});
}
function generateLogs () {
performance.generateLog(null, null, true);
}
module.exports = {
runTests: runTests,
generateLogs: generateLogs
};