var Attendant = require('turndown-attendant') var TurndownService = require('../lib/turndown.cjs') var attendant = new Attendant({ file: __dirname + '/index.html', TurndownService: TurndownService }) var test = attendant.test attendant.run() test('malformed documents', function (t) { t.plan(0) var turndownService = new TurndownService() turndownService.turndown('
') t.end() }) test('null input', function (t) { t.plan(1) var turndownService = new TurndownService() t.throws( function () { turndownService.turndown(null) }, /null is not a string/ ) }) test('undefined input', function (t) { t.plan(1) var turndownService = new TurndownService() t.throws( function () { turndownService.turndown(void (0)) }, /undefined is not a string/ ) }) test('#addRule returns the instance', function (t) { t.plan(1) var turndownService = new TurndownService() var rule = { filter: ['del', 's', 'strike'], replacement: function (content) { return '~~' + content + '~~' } } t.equal(turndownService.addRule('strikethrough', rule), turndownService) }) test('#addRule adds the rule', function (t) { t.plan(2) var turndownService = new TurndownService() var rule = { filter: ['del', 's', 'strike'], replacement: function (content) { return '~~' + content + '~~' } } // Assert rules#add is called turndownService.rules.add = function (key, r) { t.equal(key, 'strikethrough') t.equal(rule, r) } turndownService.addRule('strikethrough', rule) }) test('#use returns the instance for chaining', function (t) { t.plan(1) var turndownService = new TurndownService() t.equal(turndownService.use(function plugin () {}), turndownService) }) test('#use with a single plugin calls the fn with instance', function (t) { t.plan(1) var turndownService = new TurndownService() function plugin (service) { t.equal(service, turndownService) } turndownService.use(plugin) }) test('#use with multiple plugins calls each fn with instance', function (t) { t.plan(2) var turndownService = new TurndownService() function plugin1 (service) { t.equal(service, turndownService) } function plugin2 (service) { t.equal(service, turndownService) } turndownService.use([plugin1, plugin2]) }) test('#keep keeps elements as HTML', function (t) { t.plan(2) var turndownService = new TurndownService() var input = 'Hello worldWorld
Hello worldWorld
Hello world
'), 'Hello world') }) test('keeping elements that have a blank textContent but contain significant elements', function (t) { t.plan(1) var turndownService = new TurndownService() turndownService.keep('figure') t.equal( turndownService.turndown('Hello worldWorld
Hello world
'), 'Hello world') }) test('remove elements are overridden by keep', function (t) { t.plan(1) var turndownService = new TurndownService() turndownService.keep(['del', 'ins']) turndownService.remove(['del', 'ins']) t.equal(turndownService.turndown( 'Hello worldWorld