-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
74 lines (65 loc) · 1.91 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
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
/*!
* load-deps <https://github.com/tunnckoCore/load-deps>
*
* Copyright (c) 2015-2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('assertit')
var appname = require('app-name')
var loadDeps = require('./index')
test('load-deps:', function () {
test('should load plugins from devDependencies by default', function (done) {
var res = loadDeps('node-*')
var actual = Object.keys(res).length
var expected = 3
test.equal(actual, expected)
test.ok(res['node-foo'])
done()
})
test('should load plugins from dependencies', function (done) {
var res = loadDeps('is-*', {type: 'dependencies'})
var actual = Object.keys(res).length
var expected = 1
test.equal(actual, expected)
test.ok(res['is-match'])
done()
})
test('should return empty object if no matches', function (done) {
var res = loadDeps('foo-bar-*')
var actual = Object.keys(res).length
var expected = 0
test.equal(actual, expected)
test.equal(typeof res, 'object')
done()
})
test('should be able to pass renameKey function through options', function (done) {
var res = loadDeps('node-*', {renameKey: function (name) {
return appname(name, ['node'])
}})
var actual = Object.keys(res).length
var expected = 3
test.equal(actual, expected)
test.ok(res.foo)
test.ok(res.bar)
test.ok(res.baz)
done()
})
test('should be able to pass custom require-ing function', function (done) {
var res = loadDeps('node-ba*', {
require: function (name) {
return require.resolve(name)
},
renameKey: function (name) {
return name.toUpperCase()
}
})
var actual = Object.keys(res).length
var expected = 2
test.equal(actual, expected)
test.ok(res['NODE-BAR'])
test.ok(res['NODE-BAZ'])
done()
})
})