-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.js
105 lines (81 loc) 路 2.37 KB
/
index.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const parseChangelog = require('..')
const test = require('tape')
const path = require('path')
const fs = require('fs')
const expected = require('./fixtures/expected')
const removeMarkdownExpected = require('./fixtures/remove-markdown-expected')
const filePath = path.join(__dirname, 'fixtures', 'CHANGELOG.md')
test('throws on bad params', function (t) {
t.plan(3)
const missing = 'must provide filePath or text'
const invalidPath = 'invalid filePath, expected string'
const invalidText = 'invalid text, expected string'
t.throws(parseChangelog, missing, missing)
t.throws(function () {
parseChangelog({ filePath: 0 })
}, invalidPath, invalidPath)
t.throws(function () {
parseChangelog({ text: 0 })
}, invalidText, invalidText)
})
test('parses example changelog', function (t) {
t.plan(1)
parseChangelog(filePath, function (err, result) {
if (err) throw err
t.deepEqual(result, expected)
t.end()
})
})
test('parses example changelog as text', function (t) {
t.plan(1)
parseChangelog({ text: fs.readFileSync(filePath, 'utf8') }, function (err, result) {
if (err) throw err
t.deepEqual(result, expected)
t.end()
})
})
test('returns a Promise when invoked without a valid `callback`', function (t) {
t.plan(2)
const result = parseChangelog(filePath)
t.true(typeof result === 'object')
t.true(result instanceof Promise)
})
test('resolved Promise contains a "CHANGELOG" object', function (t) {
t.plan(1)
parseChangelog(filePath).then(function (result) {
t.deepEqual(result, expected)
t.end()
})
})
test('callback and Promise methods should yield identical values', function (t) {
t.plan(1)
parseChangelog(filePath, function (err, resultA) {
if (err) t.fail()
parseChangelog(filePath)
.then(function (resultB) {
t.deepEqual(resultA, resultB)
t.end()
})
.catch(t.fail)
})
})
test('accepts object as first argument', function (t) {
t.plan(1)
parseChangelog({ filePath: filePath }, function (err, result) {
if (err) throw err
t.deepEqual(result, expected)
t.end()
})
})
test('accepts { removeMardown: false } option', function (t) {
t.plan(1)
const options = {
filePath: filePath,
removeMarkdown: false
}
parseChangelog(options, function (err, result) {
if (err) throw err
t.deepEqual(result, removeMarkdownExpected)
t.end()
})
})