-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
46 lines (39 loc) · 1.33 KB
/
test.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
/*!
* get-comments <https://github.com/tunnckoCore/get-comments>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var fs = require('fs')
var test = require('assertit')
var getComments = require('./index')
test('get-comments:', function () {
test('should throw TypeError if not string given', function (done) {
function fixture () {
getComments()
}
test.throws(fixture, TypeError)
test.throws(fixture, /get-comments expects a string/)
done()
})
test('should extract comments as object when getComments(input)', function (done) {
var input = fs.readFileSync('./fixture.js', 'utf8')
var actual = getComments(input)
test.equal(typeof actual, 'object')
test.equal(Object.keys(actual).length, 2)
test.ok(actual[0].after)
test.ok(actual[0].after.indexOf('module.exports = function koaIpFilter') !== -1)
done()
})
test('should extract comments as array when getComments(input, true)', function (done) {
var input = fs.readFileSync('./fixture.js', 'utf8')
var actual = getComments(input, true)
test.equal(Array.isArray(actual), true)
test.equal(actual.length, 2)
test.ok(actual[1].after)
test.ok(actual[1].after.indexOf('exports.data =') !== -1)
done()
})
})