UNPKG

2.46 kBJavaScriptView Raw
1var assert = require('assert'),
2 cleaner = require('./index.js');
3
4// test that text is unchanged
5cleaner.clean('Foo Bar', function (html) {
6 assert.equal(html, 'Foo Bar');
7});
8
9// test that extra whitespace is removed
10cleaner.clean('Foo Bar', function (html) {
11 assert.equal(html, 'Foo Bar');
12});
13cleaner.clean('Foo\nBar', function (html) {
14 assert.equal(html, 'Foo Bar');
15});
16
17// test that comments are removed
18cleaner.clean('<!-- foo -->', function (html) {
19 assert.equal(html, '<!-- foo -->');
20});
21cleaner.clean('<!-- foo -->', {'remove-comments': true}, function (html) {
22 assert.equal(html, '');
23});
24
25// test that lines breaks are added before and after comments
26cleaner.clean('foo<!-- bar -->qux', function (html) {
27 assert.equal(html, 'foo\n<!-- bar -->\nqux');
28});
29cleaner.clean('foo<!-- bar -->qux', {'break-around-comments': false}, function (html) {
30 assert.equal(html, 'foo<!-- bar -->qux');
31});
32
33// test that empty paragraph tags are removed
34cleaner.clean('<p>\n</p>', function (html) {
35 assert.equal(html, '<p>\n</p>');
36});
37cleaner.clean('<p>\n</p>', {'remove-empty-paras': true}, function (html) {
38 assert.equal(html, '');
39});
40
41// test that deprecated tags are removed
42cleaner.clean('<font face="arial">foo</font>', function (html) {
43 assert.equal(html, 'foo');
44});
45
46// test that legacy attributes are removed
47cleaner.clean('<span color="red">foo</span>', function (html) {
48 assert.equal(html, '<span>foo</span>');
49});
50
51// test that line break is added after br tag
52cleaner.clean('foo<br>bar', function (html) {
53 assert.equal(html, 'foo<br>\nbar');
54});
55cleaner.clean('foo<br>bar', {'break-after-br': false}, function (html) {
56 assert.equal(html, 'foo<br>bar');
57});
58
59// test that line breaks are added before and after block element tags
60cleaner.clean('foo<div></div>bar', function (html) {
61 assert.equal(html, 'foo\n<div>\n</div>\nbar');
62});
63
64// test that nested tags are indented after block element tags
65cleaner.clean('<div>foo</div>', function (html) {
66 assert.equal(html, '<div>\n foo\n</div>');
67});
68cleaner.clean('<div><div>foo</div></div>', function (html) {
69 assert.equal(html, '<div>\n <div>\n foo\n </div>\n</div>');
70});
71cleaner.clean('<div>foo</div>', {'indent': ' '}, function (html) {
72 assert.equal(html, '<div>\n foo\n</div>');
73});
74
75// test that output is trimmed
76cleaner.clean(' foo\n', function (html) {
77 assert.equal(html, 'foo');
78});
79
80console.log('all tests passed');