diff --git a/Gruntfile.js b/Gruntfile.js index b451a2d..5d0cc45 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -144,7 +144,6 @@ module.exports = function (grunt) { } }, single: { - src: 'test/node/**/*.js', options: { globals: ['should'], timeout: 3000, @@ -153,7 +152,7 @@ module.exports = function (grunt) { } }, cli: { - src: 'test/node/testsuite.cli.js', + src: 'test/unit/cli.js', options: { globals: ['should'], timeout: 3000, @@ -208,14 +207,12 @@ module.exports = function (grunt) { /** * Run a single test */ - grunt.registerTask('single-test', function (grep) { + grunt.registerTask('single-test', function (file) { 'use strict'; grunt.config.merge({ simplemocha: { single: { - options: { - grep: grep - } + src: file } } }); @@ -230,6 +227,7 @@ module.exports = function (grunt) { grunt.registerTask('test-functional', ['concat:test', 'simplemocha:functional', 'clean']); grunt.registerTask('test-unit', ['concat:test', 'simplemocha:unit', 'clean']); grunt.registerTask('test-cli', ['clean', 'lint', 'concat:test', 'simplemocha:cli', 'clean']); + grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']); grunt.registerTask('build', ['test', 'concat:dist', 'concat:cli', 'uglify:dist', 'uglify:cli', 'endline']); grunt.registerTask('build-without-test', ['concat:dist', 'uglify', 'endline']); diff --git a/dist/showdown.js b/dist/showdown.js index 13ef529..347181b 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 1a0100f..d0b8c3b 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index adb9074..671f8ca 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 4c7cdcd..2d00658 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/helpers.js b/src/helpers.js index 6ca54bf..ac5f1c7 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -363,12 +363,16 @@ showdown.helper.encodeEmailAddress = function (mail) { /** * String.prototype.repeat polyfill * - * @param str - * @param count + * @param {string} str + * @param {int} count * @returns {string} */ -function repeat (str, count) { +showdown.helper.repeat = function (str, count) { 'use strict'; + // use built-in method if it's available + if (!showdown.helper.isUndefined(String.prototype.repeat)) { + return str.repeat(count); + } str = '' + str; if (count < 0) { throw new RangeError('repeat count must be non-negative'); @@ -396,7 +400,7 @@ function repeat (str, count) { } str += str.substring(0, maxCount - str.length); return str; -} +}; /** * String.prototype.padEnd polyfill @@ -418,7 +422,7 @@ showdown.helper.padEnd = function padEnd (str, targetLength, padString) { } else { targetLength = targetLength - str.length; if (targetLength > padString.length) { - padString += repeat(padString, targetLength / padString.length); //append to original to ensure we are longer than needed + padString += showdown.helper.repeat(padString, targetLength / padString.length); //append to original to ensure we are longer than needed } return String(str) + padString.slice(0,targetLength); } diff --git a/test/unit/showdown.Converter.makeHtml.js b/test/unit/showdown.Converter.makeHtml.js index 9f1591e..26a9f59 100644 --- a/test/unit/showdown.Converter.makeHtml.js +++ b/test/unit/showdown.Converter.makeHtml.js @@ -1,15 +1,14 @@ /** * Created by Estevao on 15-01-2015. */ +require('source-map-support').install(); +require('chai').should(); +require('sinon'); +var showdown = require('../../.build/showdown.js'); describe('showdown.Converter', function () { 'use strict'; - require('source-map-support').install(); - require('chai').should(); - - var showdown = require('../../.build/showdown.js'); - describe('Converter.options extensions', function () { var runCount; showdown.extension('testext', function () { diff --git a/test/unit/showdown.Converter.makeMarkdown.js b/test/unit/showdown.Converter.makeMarkdown.js index fb85bf2..95e6e9c 100644 --- a/test/unit/showdown.Converter.makeMarkdown.js +++ b/test/unit/showdown.Converter.makeMarkdown.js @@ -1,15 +1,14 @@ /** * Created by Estevao on 15-01-2015. */ +require('source-map-support').install(); +require('chai').should(); +require('sinon'); +var showdown = require('../../.build/showdown.js'); describe('showdown.Converter', function () { 'use strict'; - require('source-map-support').install(); - require('chai').should(); - var jsdom = require('jsdom'), - document = new jsdom.JSDOM('', {}).window.document, // jshint ignore:line - showdown = require('../../.build/showdown.js'); describe('makeMarkdown()', function () { var converter = new showdown.Converter(); @@ -18,7 +17,7 @@ describe('showdown.Converter', function () { var html = 'a link\n'; var md = '[a link]()'; - converter.makeMarkdown(html, document).should.equal(md); + converter.makeMarkdown(html).should.equal(md); }); }); diff --git a/test/unit/showdown.helpers.js b/test/unit/showdown.helpers.js index c9e35c8..2995728 100644 --- a/test/unit/showdown.helpers.js +++ b/test/unit/showdown.helpers.js @@ -1,11 +1,14 @@ /** - * Created by Estevao on 27/01/2017. + * Created by Tivie on 27/01/2017. */ +require('source-map-support').install(); +require('chai').should(); +require('sinon'); +var showdown = require('../../.build/showdown.js'); /*jshint expr: true*/ /*jshint -W053 */ /*jshint -W010 */ /*jshint -W009 */ -var showdown = require('../../.build/showdown.js'); describe('encodeEmailAddress()', function () { 'use strict'; @@ -245,3 +248,12 @@ describe('matchRecursiveRegExp()', function () { }); +describe('repeat()', function () { + 'use strict'; + it('work produce the same output as String.prototype.repeat()', function () { + var str = 'foo', + expected = str.repeat(100), + actual = showdown.helper.repeat(str, 100); + expected.should.equal(actual); + }); +}); diff --git a/test/unit/showdown.js b/test/unit/showdown.js index 64465d0..0d9cbf4 100644 --- a/test/unit/showdown.js +++ b/test/unit/showdown.js @@ -1,5 +1,6 @@ require('source-map-support').install(); require('chai').should(); +require('sinon'); var expect = require('chai').expect, showdown = require('../../.build/showdown.js');