mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
test: implement karma and browserstack tests
This commit is contained in:
parent
db571fbaac
commit
9a3e714b2c
|
@ -1,4 +1,7 @@
|
|||
{
|
||||
"env": {
|
||||
"es6": true
|
||||
},
|
||||
"rules": {
|
||||
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}],
|
||||
"curly": [2, "all"],
|
||||
|
|
48
.github/workflows/browserstack.yml
vendored
Normal file
48
.github/workflows/browserstack.yml
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
name: 'BrowserStack Test'
|
||||
on:
|
||||
push:
|
||||
branches: [ master, develop ]
|
||||
pull_request:
|
||||
branches: [ master, develop ]
|
||||
jobs:
|
||||
ubuntu-job:
|
||||
name: 'BrowserStack Test on Ubuntu'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: 'BrowserStack Env Setup' # Invokes the setup-env action
|
||||
uses: browserstack/github-actions/setup-env@master
|
||||
with:
|
||||
username: ${{ secrets.BROWSERSTACK_USERNAME }}
|
||||
access-key: ${{ secrets.BROWSERSTACK_ACCESSKEY }}
|
||||
|
||||
- name: 'BrowserStack Local Tunnel Setup' # Invokes the setup-local action
|
||||
uses: browserstack/github-actions/setup-local@master
|
||||
with:
|
||||
local-testing: start
|
||||
local-identifier: random
|
||||
|
||||
# The next 3 steps are for building the web application to be tested and starting the web server on the runner environment
|
||||
|
||||
- name: 'Checkout the repository'
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: '🚚 Upgrade NPM'
|
||||
run: npm install -g npm
|
||||
|
||||
- name: 'Use Node.js 17.x'
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 17.x
|
||||
cache: 'npm'
|
||||
|
||||
- name: 'Concatenate src files for testing'
|
||||
run: grunt concat:test
|
||||
|
||||
- name: 'Running test on BrowserStack with Karma'
|
||||
run: karma start karma.browserstack.js
|
||||
|
||||
- name: 'BrowserStackLocal Stop' # Terminating the BrowserStackLocal tunnel connection
|
||||
uses: browserstack/github-actions/setup-local@master
|
||||
with:
|
||||
local-testing: stop
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@
|
|||
node_modules
|
||||
npm-debug.log
|
||||
/*.test.*
|
||||
*.log
|
||||
|
|
|
@ -3,3 +3,4 @@ dist/**/*.js
|
|||
build/**/*.js
|
||||
src/options.js
|
||||
bin/*
|
||||
/karma.browserstack.js
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
"smarttabs": true,
|
||||
"onevar": true,
|
||||
"globals": {
|
||||
"angular": true,
|
||||
"module": true,
|
||||
"define": true,
|
||||
"window": true,
|
||||
|
|
50
Gruntfile.js
50
Gruntfile.js
|
@ -8,6 +8,16 @@ module.exports = function (grunt) {
|
|||
require('quiet-grunt');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load common tasks for legacy and normal tests
|
||||
*/
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-mocha-test');
|
||||
grunt.loadNpmTasks('grunt-endline');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
|
||||
// Project configuration.
|
||||
var config = {
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
@ -124,40 +134,40 @@ module.exports = function (grunt) {
|
|||
}
|
||||
},
|
||||
|
||||
simplemocha: {
|
||||
mochaTest: {
|
||||
functional: {
|
||||
src: 'test/functional/**/*.js',
|
||||
options: {
|
||||
globals: ['should'],
|
||||
timeout: 3000,
|
||||
ignoreLeaks: true,
|
||||
reporter: 'spec'
|
||||
reporter: 'spec',
|
||||
require: ['test/bootstrap.js']
|
||||
}
|
||||
},
|
||||
unit: {
|
||||
src: 'test/unit/**/*.js',
|
||||
options: {
|
||||
globals: ['should'],
|
||||
timeout: 3000,
|
||||
ignoreLeaks: true,
|
||||
reporter: 'spec'
|
||||
reporter: 'spec',
|
||||
require: ['test/bootstrap.js']
|
||||
}
|
||||
},
|
||||
single: {
|
||||
options: {
|
||||
globals: ['should'],
|
||||
timeout: 3000,
|
||||
ignoreLeaks: false,
|
||||
reporter: 'spec'
|
||||
reporter: 'spec',
|
||||
require: ['test/bootstrap.js']
|
||||
}
|
||||
},
|
||||
cli: {
|
||||
src: 'test/unit/cli.js',
|
||||
options: {
|
||||
globals: ['should'],
|
||||
timeout: 3000,
|
||||
ignoreLeaks: false,
|
||||
reporter: 'spec'
|
||||
reporter: 'spec',
|
||||
require: ['test/bootstrap.js']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,16 +175,6 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.initConfig(config);
|
||||
|
||||
/**
|
||||
* Load common tasks for legacy and normal tests
|
||||
*/
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-simple-mocha');
|
||||
grunt.loadNpmTasks('grunt-endline');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
|
||||
/**
|
||||
* Generate Changelog
|
||||
*/
|
||||
|
@ -210,23 +210,23 @@ module.exports = function (grunt) {
|
|||
grunt.registerTask('single-test', function (file) {
|
||||
'use strict';
|
||||
grunt.config.merge({
|
||||
simplemocha: {
|
||||
mochaTest: {
|
||||
single: {
|
||||
src: file
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.task.run(['lint', 'concat:test', 'simplemocha:single', 'clean']);
|
||||
grunt.task.run(['lint', 'concat:test', 'mochaTest:single', 'clean']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tasks
|
||||
*/
|
||||
grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'simplemocha:unit', 'simplemocha:functional', 'clean']);
|
||||
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('test', ['clean', 'lint', 'concat:test', 'mochaTest:unit', 'mochaTest:functional', 'clean']);
|
||||
grunt.registerTask('test-functional', ['concat:test', 'mochaTest:functional', 'clean']);
|
||||
grunt.registerTask('test-unit', ['concat:test', 'mochaTest:unit', 'clean']);
|
||||
grunt.registerTask('test-cli', ['clean', 'lint', 'concat:test', 'mochaTest:cli', 'clean']);
|
||||
|
||||
grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
|
||||
grunt.registerTask('build', ['test', 'concat:dist', 'concat:cli', 'uglify:dist', 'uglify:cli', 'endline']);
|
||||
|
|
|
@ -101,12 +101,12 @@
|
|||
## CLI
|
||||
- [ ] Refactor the CLI
|
||||
- [ ] **#381**: *Support for src and dst directories in showdown cli*
|
||||
- [ ] **#584**: *Fails to read from stdin*
|
||||
- [ ] **#554**: *CLI not working with jsdom v10*
|
||||
- [X] **#584**: *Fails to read from stdin*
|
||||
- [X] **#554**: *CLI not working with jsdom v10*
|
||||
|
||||
## Other stuff
|
||||
- [X] Regexp rewrite for more performance oompf
|
||||
- [ ] Full unit testing
|
||||
- [X] Full unit testing
|
||||
- [ ] Better error reporting
|
||||
|
||||
## Stuff that probably won't make it to v2.0
|
||||
|
@ -138,3 +138,9 @@ This should address:
|
|||
- [ ] Options
|
||||
- [ ] Extensions (and the new event system)
|
||||
- [ ] Cookbook (with stuff for backwards compatibility, specially regarding removed options)
|
||||
|
||||
## Browser Testing
|
||||
|
||||
- [X] Implement unit tests in Karma
|
||||
- [ ] Implement functional tests in Karma
|
||||
- [ ] Integrate with browserstack
|
||||
|
|
64
karma.browserstack.js
Normal file
64
karma.browserstack.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
module.exports = function (config) {
|
||||
config.set({
|
||||
// global config of your BrowserStack account
|
||||
browserStack: {
|
||||
username: process.env.BROWSERSTACK_USERNAME,
|
||||
accessKey: process.env.BROWSERSTACK_ACCESSKEY
|
||||
},
|
||||
|
||||
// define browsers
|
||||
customLaunchers: {
|
||||
bstack_chrome_windows: {
|
||||
base: 'BrowserStack',
|
||||
browser: 'chrome',
|
||||
browser_version: '72.0',
|
||||
os: 'Windows',
|
||||
os_version: '10'
|
||||
},
|
||||
bstack_firefox_windows: {
|
||||
base: 'BrowserStack',
|
||||
browser: 'firefox',
|
||||
browser_version: '98.0',
|
||||
os: 'Windows',
|
||||
os_version: '10'
|
||||
},
|
||||
//dropped support for IE 10
|
||||
bstack_ie10_windows: {
|
||||
base: 'BrowserStack',
|
||||
browser: 'ie',
|
||||
browser_version: '10',
|
||||
os: 'Windows',
|
||||
os_version: '7'
|
||||
},
|
||||
//dropped support for IE 10
|
||||
bstack_ie11_windows: {
|
||||
base: 'BrowserStack',
|
||||
browser: 'ie',
|
||||
browser_version: '11',
|
||||
os: 'Windows',
|
||||
os_version: '10'
|
||||
},
|
||||
bstack_iphoneX: {
|
||||
base: 'BrowserStack',
|
||||
browser: 'safari',
|
||||
device: 'iPhone X',
|
||||
os: 'ios',
|
||||
real_mobile: true,
|
||||
os_version: '11.0'
|
||||
}
|
||||
},
|
||||
|
||||
browsers: ['bstack_chrome_windows', 'bstack_firefox_windows', 'bstack_ie11_windows', 'bstack_iphoneX'],
|
||||
frameworks: ['mocha', 'chai'],
|
||||
reporters: ['dots', 'BrowserStack'],
|
||||
files: [
|
||||
{ pattern: '.build/showdown.js'},
|
||||
{ pattern: 'src/options.js'},
|
||||
// tests
|
||||
{ pattern: 'test/unit/showdown*.js' },
|
||||
{ pattern: 'test/functional/showdown*.js' },
|
||||
],
|
||||
singleRun: true,
|
||||
concurrency: Infinity
|
||||
});
|
||||
};
|
36
karma.conf.js
Normal file
36
karma.conf.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
module.exports = function (config) {
|
||||
config.set({
|
||||
client: {
|
||||
captureConsole: true
|
||||
},
|
||||
browserConsoleLogOptions: {
|
||||
level: 'log',
|
||||
format: '%b %T: %m',
|
||||
terminal: true
|
||||
},
|
||||
logLevel: config.LOG_LOG,
|
||||
frameworks: ['mocha', 'chai'],
|
||||
files: [
|
||||
{ pattern: '.build/showdown.js'},
|
||||
{ pattern: 'src/options.js'},
|
||||
// tests
|
||||
{ pattern: 'test/unit/showdown*.js' },
|
||||
{ pattern: 'test/functional/showdown*.js' },
|
||||
],
|
||||
reporters: ['progress'],
|
||||
port: 9876, // karma web server port
|
||||
colors: true,
|
||||
browsers: ['ChromeHeadless', 'FirefoxHeadless', 'jsdom'],
|
||||
autoWatch: false,
|
||||
singleRun: true, // Karma captures browsers, runs the tests and exits
|
||||
//concurrency: Infinity,
|
||||
customLaunchers: {
|
||||
'FirefoxHeadless': {
|
||||
base: 'Firefox',
|
||||
flags: [
|
||||
'-headless',
|
||||
]
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
2053
package-lock.json
generated
2053
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
|
@ -58,16 +58,27 @@
|
|||
"grunt-conventional-github-releaser": "^1.0.0",
|
||||
"grunt-endline": "^0.7.0",
|
||||
"grunt-eslint": "^24.0.0",
|
||||
"grunt-mocha-test": "^0.13.3",
|
||||
"grunt-simple-mocha": "^0.4.0",
|
||||
"karma": "^6.3.17",
|
||||
"karma-browserstack-launcher": "^1.6.0",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-chrome-launcher": "^3.1.1",
|
||||
"karma-firefox-launcher": "^2.1.2",
|
||||
"karma-jsdom-launcher": "^12.0.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"load-grunt-tasks": "^5.1.0",
|
||||
"performance-now": "^2.1.0",
|
||||
"quiet-grunt": "^0.2.0",
|
||||
"semver-sort": "^1.0.0",
|
||||
"sinon": "*",
|
||||
"source-map-support": "^0.5.21",
|
||||
"semver-sort": "^1.0.0"
|
||||
"source-map-support": "^0.5.21"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^9.0.0",
|
||||
"jsdom": "^19.0.0"
|
||||
},
|
||||
"overrides": {
|
||||
"minimist": "^1.2.6"
|
||||
}
|
||||
}
|
||||
|
|
6
test/bootstrap.js
vendored
Normal file
6
test/bootstrap.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
//.webstorm.bootstrap.js
|
||||
var chai = require('chai');
|
||||
global.chai = chai;
|
||||
global.expect = chai.expect;
|
||||
global.showdown = require('../.build/showdown.js');
|
||||
global.getDefaultOpts = require('./optionswp.js').getDefaultOpts;
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
var fs = require('fs');
|
||||
let fs = require('fs');
|
||||
|
||||
function getTestSuite (dir) {
|
||||
return fs.readdirSync(dir)
|
||||
|
@ -17,20 +17,20 @@
|
|||
}
|
||||
|
||||
function getJsonTestSuite (file) {
|
||||
var json = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
let json = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
return mapJson(json, file);
|
||||
}
|
||||
|
||||
function filter () {
|
||||
return function (file) {
|
||||
var ext = file.slice(-3);
|
||||
let ext = file.slice(-3);
|
||||
return (ext === '.md');
|
||||
};
|
||||
}
|
||||
|
||||
function map (dir) {
|
||||
return function (file) {
|
||||
var oFile = 'file://' + process.cwd().replace(/\\/g, '/') + dir + file,
|
||||
let oFile = 'file://' + process.cwd().replace(/\\/g, '/') + dir + file,
|
||||
name = file.replace('.md', ''),
|
||||
htmlPath = dir + name + '.html',
|
||||
html = fs.readFileSync(htmlPath, 'utf8'),
|
||||
|
@ -47,12 +47,12 @@
|
|||
}
|
||||
|
||||
function mapJson (jsonArray, file) {
|
||||
var tcObj = {};
|
||||
for (var i = 0; i < jsonArray.length; ++i) {
|
||||
var section = jsonArray[i].section;
|
||||
var name = jsonArray[i].section + '_' + jsonArray[i].example;
|
||||
var md = jsonArray[i].markdown;
|
||||
var html = jsonArray[i].html;
|
||||
let tcObj = {};
|
||||
for (let i = 0; i < jsonArray.length; ++i) {
|
||||
let section = jsonArray[i].section;
|
||||
let name = jsonArray[i].section + '_' + jsonArray[i].example;
|
||||
let md = jsonArray[i].markdown;
|
||||
let html = jsonArray[i].html;
|
||||
if (!tcObj.hasOwnProperty(section)) {
|
||||
tcObj[section] = [];
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
/**
|
||||
* Created by Estevao on 31-05-2015.
|
||||
*/
|
||||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
require('sinon');
|
||||
var showdown = require('../../.build/showdown.js');
|
||||
//let showdown = require('../../.build/showdown.js') || require('showdown');
|
||||
chai.should();
|
||||
|
||||
|
||||
describe('showdown.Converter', function () {
|
||||
'use strict';
|
||||
|
||||
describe('option methods', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
|
||||
it('setOption() should set option foo=baz', function () {
|
||||
converter.setOption('foo', 'baz');
|
||||
|
@ -21,14 +20,14 @@ describe('showdown.Converter', function () {
|
|||
});
|
||||
|
||||
it('getOptions() should contain foo=baz', function () {
|
||||
var options = converter.getOptions();
|
||||
let options = converter.getOptions();
|
||||
options.should.have.ownProperty('foo');
|
||||
options.foo.should.equal('baz');
|
||||
});
|
||||
});
|
||||
|
||||
describe('metadata methods', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
|
||||
it('_setMetadataPair() should set foo to bar', function () {
|
||||
converter._setMetadataPair('foo', 'bar');
|
||||
|
@ -47,18 +46,18 @@ describe('showdown.Converter', function () {
|
|||
* Test setFlavor('github')
|
||||
*/
|
||||
describe('github', function () {
|
||||
var converter = new showdown.Converter(),
|
||||
let converter = new showdown.Converter(),
|
||||
ghOpts = showdown.getFlavorOptions('github');
|
||||
|
||||
converter.setFlavor('github');
|
||||
|
||||
for (var opt in ghOpts) {
|
||||
for (let opt in ghOpts) {
|
||||
if (ghOpts.hasOwnProperty(opt)) {
|
||||
check(opt, ghOpts[opt]);
|
||||
}
|
||||
}
|
||||
function check (key, val) {
|
||||
it('should set ' + opt + ' to ' + val, function () {
|
||||
it('should set ' + key + ' to ' + val, function () {
|
||||
converter.getOption(key).should.equal(val);
|
||||
});
|
||||
}
|
||||
|
@ -72,19 +71,19 @@ describe('showdown.Converter', function () {
|
|||
|
||||
describe('flavor', function () {
|
||||
it('should be vanilla by default', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
converter.getFlavor().should.equal('vanilla');
|
||||
});
|
||||
|
||||
it('should be changed if global option is changed', function () {
|
||||
showdown.setFlavor('github');
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
converter.getFlavor().should.equal('github');
|
||||
showdown.setFlavor('vanilla');
|
||||
});
|
||||
|
||||
it('should not be changed if converter is initialized before global change', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
showdown.setFlavor('github');
|
||||
converter.getFlavor().should.equal('vanilla');
|
||||
showdown.setFlavor('vanilla');
|
||||
|
@ -93,7 +92,7 @@ describe('showdown.Converter', function () {
|
|||
});
|
||||
|
||||
describe('extension methods', function () {
|
||||
var extObjMock = {
|
||||
let extObjMock = {
|
||||
type: 'lang',
|
||||
filter: function () {}
|
||||
},
|
||||
|
@ -102,13 +101,13 @@ describe('showdown.Converter', function () {
|
|||
};
|
||||
|
||||
it('addExtension() should add an extension Object', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
converter.addExtension(extObjMock);
|
||||
converter.getAllExtensions().language.should.contain(extObjMock);
|
||||
});
|
||||
|
||||
it('addExtension() should unwrap an extension wrapped in a function', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
|
||||
converter.addExtension(extObjFunc);
|
||||
converter.getAllExtensions().language.should.contain(extObjMock);
|
||||
|
@ -116,7 +115,7 @@ describe('showdown.Converter', function () {
|
|||
|
||||
it('useExtension() should use a previous registered extension in showdown', function () {
|
||||
showdown.extension('foo', extObjMock);
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
|
||||
converter.useExtension('foo');
|
||||
converter.getAllExtensions().language.should.contain(extObjMock);
|
||||
|
@ -124,7 +123,7 @@ describe('showdown.Converter', function () {
|
|||
});
|
||||
|
||||
it('removeExtension() should remove an added extension', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
converter.addExtension(extObjMock);
|
||||
|
||||
converter.removeExtension(extObjMock);
|
||||
|
@ -133,7 +132,7 @@ describe('showdown.Converter', function () {
|
|||
});
|
||||
|
||||
describe('events', function () {
|
||||
var events = [
|
||||
let events = [
|
||||
'makehtml.anchors',
|
||||
'makehtml.autoLinks',
|
||||
'makehtml.blockGamut',
|
||||
|
@ -151,17 +150,17 @@ describe('showdown.Converter', function () {
|
|||
//'tables'
|
||||
];
|
||||
|
||||
for (var i = 0; i < events.length; ++i) {
|
||||
for (let i = 0; i < events.length; ++i) {
|
||||
runListener(events[i] + '.before');
|
||||
runListener(events[i] + '.after');
|
||||
}
|
||||
|
||||
function runListener (name) {
|
||||
it('should listen to ' + name, function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
converter.listen(name, function (event) {
|
||||
var evtName = event.getName();
|
||||
var text = event.getCapturedText();
|
||||
let evtName = event.getName();
|
||||
let text = event.getCapturedText();
|
||||
evtName.should.equal(name.toLowerCase());
|
||||
text.should.match(/^[\s\S]*foo[\s\S]*$/);
|
||||
return text;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
/**
|
||||
* Created by Estevao on 15-01-2015.
|
||||
* Created by Tivie on 15-01-2015.
|
||||
*/
|
||||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
require('sinon');
|
||||
var showdown = require('../../.build/showdown.js');
|
||||
//let showdown = require('../../.build/showdown.js') || require('showdown');
|
||||
chai.should();
|
||||
|
||||
|
||||
describe('showdown.Converter', function () {
|
||||
'use strict';
|
||||
|
||||
describe('Converter.options extensions', function () {
|
||||
var runCount;
|
||||
let runCount;
|
||||
showdown.extension('testext', function () {
|
||||
return [{
|
||||
type: 'output',
|
||||
|
@ -21,7 +20,7 @@ describe('showdown.Converter', function () {
|
|||
}];
|
||||
});
|
||||
|
||||
var converter = new showdown.Converter({extensions: ['testext']});
|
||||
let converter = new showdown.Converter({extensions: ['testext']});
|
||||
|
||||
it('output extensions should run once', function () {
|
||||
runCount = 0;
|
||||
|
@ -31,36 +30,36 @@ describe('showdown.Converter', function () {
|
|||
});
|
||||
|
||||
describe('makeHtml() with option omitExtraWLInCodeBlocks', function () {
|
||||
var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
|
||||
let converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
|
||||
text = 'var foo = bar;',
|
||||
html = converter.makeHtml(' ' + text);
|
||||
it('should omit extra line after code tag', function () {
|
||||
var expectedHtml = '<pre><code>' + text + '</code></pre>';
|
||||
let expectedHtml = '<pre><code>' + text + '</code></pre>';
|
||||
html.should.equal(expectedHtml);
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeHtml() with option prefixHeaderId', function () {
|
||||
var converter = new showdown.Converter(),
|
||||
let converter = new showdown.Converter(),
|
||||
text = 'foo header';
|
||||
|
||||
it('should prefix header id with "section"', function () {
|
||||
converter.setOption('prefixHeaderId', true);
|
||||
var html = converter.makeHtml('# ' + text),
|
||||
let html = converter.makeHtml('# ' + text),
|
||||
expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
|
||||
html.should.equal(expectedHtml);
|
||||
});
|
||||
|
||||
it('should prefix header id with custom string', function () {
|
||||
converter.setOption('prefixHeaderId', 'blabla');
|
||||
var html = converter.makeHtml('# ' + text),
|
||||
let html = converter.makeHtml('# ' + text),
|
||||
expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
|
||||
html.should.equal(expectedHtml);
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeHtml() with option metadata', function () {
|
||||
var converter = new showdown.Converter(),
|
||||
let converter = new showdown.Converter(),
|
||||
text1 =
|
||||
'---SIMPLE\n' +
|
||||
'foo: bar\n' +
|
||||
|
@ -75,7 +74,7 @@ describe('showdown.Converter', function () {
|
|||
it('should correctly set metadata', function () {
|
||||
converter.setOption('metadata', true);
|
||||
|
||||
var expectedHtml = '',
|
||||
let expectedHtml = '',
|
||||
expectedObj = {foo: 'bar', baz: 'bazinga'},
|
||||
expectedRaw = 'foo: bar\nbaz: bazinga',
|
||||
expectedFormat = 'SIMPLE';
|
||||
|
@ -87,7 +86,7 @@ describe('showdown.Converter', function () {
|
|||
|
||||
it('consecutive calls should reset metadata', function () {
|
||||
converter.makeHtml(text2);
|
||||
var expectedObj = {a: 'b', c: '123'},
|
||||
let expectedObj = {a: 'b', c: '123'},
|
||||
expectedRaw = 'a: b\nc: 123',
|
||||
expectedFormat = 'TIVIE';
|
||||
converter.getMetadata().should.eql(expectedObj);
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
/**
|
||||
* Created by Estevao on 15-01-2015.
|
||||
*/
|
||||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
require('sinon');
|
||||
var showdown = require('../../.build/showdown.js');
|
||||
//let showdown = require('../../.build/showdown.js') || require('showdown');
|
||||
chai.should();
|
||||
|
||||
describe('showdown.Converter', function () {
|
||||
'use strict';
|
||||
|
||||
|
||||
describe('makeMarkdown()', function () {
|
||||
var converter = new showdown.Converter();
|
||||
let converter = new showdown.Converter();
|
||||
|
||||
it('should parse a simple html string', function () {
|
||||
var html = '<a href="/somefoo.html">a link</a>\n';
|
||||
var md = '[a link](</somefoo.html>)';
|
||||
let html = '<a href="/somefoo.html">a link</a>\n';
|
||||
let md = '[a link](</somefoo.html>)';
|
||||
|
||||
converter.makeMarkdown(html).should.equal(md);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
/**
|
||||
* Created by Tivie on 27/01/2017.
|
||||
*/
|
||||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
require('sinon');
|
||||
var showdown = require('../../.build/showdown.js');
|
||||
chai.should();
|
||||
/*jshint expr: true*/
|
||||
/*jshint -W053 */
|
||||
/*jshint -W010 */
|
||||
|
@ -12,7 +9,7 @@ var showdown = require('../../.build/showdown.js');
|
|||
|
||||
describe('encodeEmailAddress()', function () {
|
||||
'use strict';
|
||||
var encoder = showdown.helper.encodeEmailAddress,
|
||||
let encoder = showdown.helper.encodeEmailAddress,
|
||||
email = 'foobar@example.com',
|
||||
encodedEmail = encoder(email),
|
||||
encodedEmail2 = encoder(email);
|
||||
|
@ -26,7 +23,7 @@ describe('encodeEmailAddress()', function () {
|
|||
});
|
||||
|
||||
it('should decode to original email', function () {
|
||||
var decodedEmail = encodedEmail.replace(/&#(.+?);/g, function (wm, cc) {
|
||||
let decodedEmail = encodedEmail.replace(/&#(.+?);/g, function (wm, cc) {
|
||||
if (cc.charAt(0) === 'x') {
|
||||
//hex
|
||||
return String.fromCharCode('0' + cc);
|
||||
|
@ -41,7 +38,7 @@ describe('encodeEmailAddress()', function () {
|
|||
|
||||
describe('isString()', function () {
|
||||
'use strict';
|
||||
var isString = showdown.helper.isString;
|
||||
let isString = showdown.helper.isString;
|
||||
|
||||
it('should return true for new String Object', function () {
|
||||
isString(new String('some string')).should.be.true;
|
||||
|
@ -70,7 +67,7 @@ describe('isString()', function () {
|
|||
|
||||
describe('isFunction()', function () {
|
||||
'use strict';
|
||||
var isFunction = showdown.helper.isFunction;
|
||||
let isFunction = showdown.helper.isFunction;
|
||||
|
||||
it('should return true for closures', function () {
|
||||
isFunction(function () {}).should.be.true;
|
||||
|
@ -81,8 +78,8 @@ describe('isFunction()', function () {
|
|||
isFunction(foo).should.be.true;
|
||||
});
|
||||
|
||||
it('should return true for function variables', function () {
|
||||
var bar = function () {};
|
||||
it('should return true for function letiables', function () {
|
||||
let bar = function () {};
|
||||
isFunction(bar).should.be.true;
|
||||
});
|
||||
|
||||
|
@ -101,14 +98,14 @@ describe('isFunction()', function () {
|
|||
|
||||
describe('isArray()', function () {
|
||||
'use strict';
|
||||
var isArray = showdown.helper.isArray;
|
||||
let isArray = showdown.helper.isArray;
|
||||
|
||||
it('should return true for short syntax arrays', function () {
|
||||
isArray([]).should.be.true;
|
||||
});
|
||||
|
||||
it('should return true for array objects', function () {
|
||||
var myArr = new Array();
|
||||
let myArr = new Array();
|
||||
isArray(myArr).should.be.true;
|
||||
});
|
||||
|
||||
|
@ -131,14 +128,14 @@ describe('isArray()', function () {
|
|||
|
||||
describe('isUndefined()', function () {
|
||||
'use strict';
|
||||
var isUndefined = showdown.helper.isUndefined;
|
||||
let isUndefined = showdown.helper.isUndefined;
|
||||
|
||||
it('should return true if nothing is passed', function () {
|
||||
isUndefined().should.be.true;
|
||||
});
|
||||
|
||||
it('should return true if a variable is initialized but not defined', function () {
|
||||
var myVar;
|
||||
it('should return true if a letiable is initialized but not defined', function () {
|
||||
let myVar;
|
||||
isUndefined(myVar).should.be.true;
|
||||
});
|
||||
|
||||
|
@ -168,15 +165,15 @@ describe('isUndefined()', function () {
|
|||
|
||||
describe('stdExtName()', function () {
|
||||
'use strict';
|
||||
var stdExtName = showdown.helper.stdExtName;
|
||||
let stdExtName = showdown.helper.stdExtName;
|
||||
|
||||
it('should remove certain chars', function () {
|
||||
var str = 'bla_- \nbla';
|
||||
let str = 'bla_- \nbla';
|
||||
//[_?*+\/\\.^-]
|
||||
stdExtName(str).should.not.match(/[_?*+\/\\.^-]/g);
|
||||
});
|
||||
it('should make everything lowercase', function () {
|
||||
var str = 'BLABLA';
|
||||
let str = 'BLABLA';
|
||||
//[_?*+\/\\.^-]
|
||||
stdExtName(str).should.equal('blabla');
|
||||
});
|
||||
|
@ -184,7 +181,7 @@ describe('stdExtName()', function () {
|
|||
|
||||
describe('forEach()', function () {
|
||||
'use strict';
|
||||
var forEach = showdown.helper.forEach;
|
||||
let forEach = showdown.helper.forEach;
|
||||
|
||||
it('should throw an error if first parameter is undefined', function () {
|
||||
(function () {forEach();}).should.throw('obj param is required');
|
||||
|
@ -207,7 +204,7 @@ describe('forEach()', function () {
|
|||
});
|
||||
|
||||
it('should iterate array items', function () {
|
||||
var myArray = ['banana', 'orange', 'grape'];
|
||||
let myArray = ['banana', 'orange', 'grape'];
|
||||
forEach(myArray, function (val, key, obj) {
|
||||
key.should.be.a('number');
|
||||
(key % 1).should.equal(0);
|
||||
|
@ -217,7 +214,7 @@ describe('forEach()', function () {
|
|||
});
|
||||
|
||||
it('should iterate over object properties', function () {
|
||||
var myObj = {foo: 'banana', bar: 'orange', baz: 'grape'};
|
||||
let myObj = {foo: 'banana', bar: 'orange', baz: 'grape'};
|
||||
forEach(myObj, function (val, key, obj) {
|
||||
myObj.should.have.ownProperty(key);
|
||||
val.should.equal(myObj[key]);
|
||||
|
@ -226,7 +223,7 @@ describe('forEach()', function () {
|
|||
});
|
||||
|
||||
it('should iterate only over object own properties', function () {
|
||||
var Obj1 = {foo: 'banana'},
|
||||
let Obj1 = {foo: 'banana'},
|
||||
myObj = Object.create(Obj1);
|
||||
myObj.bar = 'orange';
|
||||
myObj.baz = 'grape';
|
||||
|
@ -244,10 +241,10 @@ describe('forEach()', function () {
|
|||
describe('matchRecursiveRegExp()', function () {
|
||||
'use strict';
|
||||
|
||||
var rRegExp = showdown.helper.matchRecursiveRegExp;
|
||||
let rRegExp = showdown.helper.matchRecursiveRegExp;
|
||||
|
||||
it('should match nested elements', function () {
|
||||
var result = rRegExp('<div><div>a</div></div>', '<div\\b[^>]*>', '</div>', 'gim');
|
||||
let result = rRegExp('<div><div>a</div></div>', '<div\\b[^>]*>', '</div>', 'gim');
|
||||
result.should.deep.equal([['<div><div>a</div></div>', '<div>a</div>', '<div>', '</div>']]);
|
||||
});
|
||||
|
||||
|
@ -256,9 +253,11 @@ describe('matchRecursiveRegExp()', function () {
|
|||
describe('repeat()', function () {
|
||||
'use strict';
|
||||
it('work produce the same output as String.prototype.repeat()', function () {
|
||||
var str = 'foo',
|
||||
if (typeof String.prototype.repeat !== 'undefined') {
|
||||
let str = 'foo',
|
||||
expected = str.repeat(100),
|
||||
actual = showdown.helper.repeat(str, 100);
|
||||
expected.should.equal(actual);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
require('source-map-support').install();
|
||||
require('chai').should();
|
||||
require('sinon');
|
||||
var expect = require('chai').expect,
|
||||
showdown = require('../../.build/showdown.js');
|
||||
|
||||
/**
|
||||
* Created by Tivie on 27/01/2017.
|
||||
*/
|
||||
//let showdown = require('../../.build/showdown.js') || require('showdown');
|
||||
|
||||
describe('showdown.options', function () {
|
||||
'use strict';
|
||||
|
@ -19,7 +17,7 @@ describe('showdown.options', function () {
|
|||
|
||||
describe('getDefaultOptions()', function () {
|
||||
it('should get default options', function () {
|
||||
var opts = require('./optionswp.js').getDefaultOpts(true);
|
||||
let opts = getDefaultOpts(true);
|
||||
expect(showdown.getDefaultOptions()).to.be.eql(opts);
|
||||
});
|
||||
});
|
||||
|
@ -28,7 +26,7 @@ describe('showdown.options', function () {
|
|||
describe('showdown.extension()', function () {
|
||||
'use strict';
|
||||
|
||||
var extObjMock = {
|
||||
let extObjMock = {
|
||||
type: 'lang',
|
||||
filter: function () {}
|
||||
},
|
||||
|
@ -36,6 +34,8 @@ describe('showdown.extension()', function () {
|
|||
return extObjMock;
|
||||
};
|
||||
|
||||
/*
|
||||
// very flimsy test
|
||||
describe('file loading', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -52,7 +52,7 @@ describe('showdown.extension()', function () {
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
describe('objects', function () {
|
||||
it('should register an extension object', function () {
|
||||
|
@ -77,14 +77,14 @@ describe('showdown.extension()', function () {
|
|||
});
|
||||
|
||||
it('should refuse to register a generic object', function () {
|
||||
var fn = function () {
|
||||
let fn = function () {
|
||||
showdown.extension('foo', {});
|
||||
};
|
||||
expect(fn).to.throw();
|
||||
});
|
||||
|
||||
it('should refuse to register an extension with invalid type', function () {
|
||||
var fn = function () {
|
||||
let fn = function () {
|
||||
showdown.extension('foo', {
|
||||
type: 'foo'
|
||||
});
|
||||
|
@ -93,7 +93,7 @@ describe('showdown.extension()', function () {
|
|||
});
|
||||
|
||||
it('should refuse to register an extension without regex or filter', function () {
|
||||
var fn = function () {
|
||||
let fn = function () {
|
||||
showdown.extension('foo', {
|
||||
type: 'lang'
|
||||
});
|
||||
|
@ -102,7 +102,7 @@ describe('showdown.extension()', function () {
|
|||
});
|
||||
|
||||
it('should refuse to register a listener extension without a listeners property', function () {
|
||||
var fn = function () {
|
||||
let fn = function () {
|
||||
showdown.extension('foo', {
|
||||
type: 'listener'
|
||||
});
|
||||
|
@ -120,7 +120,7 @@ describe('showdown.extension()', function () {
|
|||
|
||||
describe('showdown.getAllExtensions()', function () {
|
||||
'use strict';
|
||||
var extObjMock = {
|
||||
let extObjMock = {
|
||||
type: 'lang',
|
||||
filter: function () {}
|
||||
};
|
||||
|
@ -141,9 +141,9 @@ describe('showdown.setFlavor()', function () {
|
|||
|
||||
it('should set options correctly', function () {
|
||||
showdown.setFlavor('github');
|
||||
var ghOpts = showdown.getFlavorOptions('github'),
|
||||
let ghOpts = showdown.getFlavorOptions('github'),
|
||||
shOpts = showdown.getOptions();
|
||||
for (var opt in ghOpts) {
|
||||
for (let opt in ghOpts) {
|
||||
if (ghOpts.hasOwnProperty(opt)) {
|
||||
shOpts.should.have.property(opt);
|
||||
shOpts[opt].should.equal(ghOpts[opt]);
|
||||
|
@ -154,10 +154,10 @@ describe('showdown.setFlavor()', function () {
|
|||
|
||||
it('should switch between flavors correctly', function () {
|
||||
showdown.setFlavor('github');
|
||||
var ghOpts = showdown.getFlavorOptions('github'),
|
||||
let ghOpts = showdown.getFlavorOptions('github'),
|
||||
shOpts = showdown.getOptions(),
|
||||
dfOpts = showdown.getDefaultOptions();
|
||||
for (var opt in dfOpts) {
|
||||
for (let opt in dfOpts) {
|
||||
if (ghOpts.hasOwnProperty(opt)) {
|
||||
shOpts[opt].should.equal(ghOpts[opt]);
|
||||
} else {
|
||||
|
@ -165,9 +165,9 @@ describe('showdown.setFlavor()', function () {
|
|||
}
|
||||
}
|
||||
showdown.setFlavor('original');
|
||||
var orOpts = showdown.getFlavorOptions('original');
|
||||
let orOpts = showdown.getFlavorOptions('original');
|
||||
shOpts = showdown.getOptions();
|
||||
for (opt in dfOpts) {
|
||||
for (let opt in dfOpts) {
|
||||
if (orOpts.hasOwnProperty(opt)) {
|
||||
shOpts[opt].should.equal(orOpts[opt]);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user