-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathtitle.js
More file actions
80 lines (73 loc) · 2.32 KB
/
title.js
File metadata and controls
80 lines (73 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var read = require('../')
var chai = require('chai')
var expect = chai.expect
var should = chai.should()
describe('find exact title', function () {
describe('length less than 10 before separator', function () {
it('should remove separator', function (done) {
read('<title>The | whole title including separator</title><body></body>', function (err, art) {
should.not.exist(err)
expect(art).to.be.an('object')
art.title.should.equal('The whole title including separator')
done()
})
})
})
;['|', '-', '_', '«', '»'].forEach(function (s) {
describe('better title', function () {
it('split with ' + s, function (done) {
read('<title>Chapter of readability ' + s + ' Tjatse</title><body></body>', function (err, art) {
should.not.exist(err)
expect(art).to.be.an('object')
art.title.should.equal('Chapter of readability')
done()
})
})
})
})
describe('title split with multi separators', function () {
it('should returns the first found length greater than 10', function (done) {
read('<title>Chapter | Demonstration of readability - Tjatse</title><body></body>', function (err, art) {
should.not.exist(err)
expect(art).to.be.an('object')
art.title.should.equal('Chapter Demonstration of readability')
done()
})
})
})
describe('better title', function () {
var article = '<title>Chapter Demonstration of readability_Node.js_readability_GitHub</title><body></body>'
it('by default', function (done) {
read({
html: article
}, function (err, art) {
should.not.exist(err)
art.title.should.equal('Chapter Demonstration of readability')
done()
})
})
it('minLength', function (done) {
read({
html: article,
betterTitle: 1000
}, function (err, art) {
should.not.exist(err)
art.title.should.contain('GitHub')
done()
})
})
it('fn', function (done) {
read({
html: article,
betterTitle: function (t) {
return '[Github]' + t
}
}, function (err, art) {
should.not.exist(err)
art.title.should.contain('[Github]')
art.title.should.contain('readability')
done()
})
})
})
})