-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
41 lines (37 loc) · 1.4 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
const test = require('ava')
const whichModule = require('./')
const path = require('path')
test('finds required local module', (t) => {
const indexModule = whichModule(whichModule)
const expectedFilename = path.join(__dirname, 'index.js')
t.is(indexModule.id, expectedFilename)
t.is(indexModule.filename, expectedFilename)
t.is(indexModule.exports, whichModule)
t.is(indexModule.parent, module)
t.is(indexModule.loaded, true)
t.is(indexModule.paths[0], path.join(__dirname, 'node_modules'))
})
test('finds required dependency module', (t) => {
const avaModule = whichModule(test)
const expectedFilename = path.join(__dirname, 'node_modules', 'ava', 'index.js')
t.is(avaModule.id, expectedFilename)
t.is(avaModule.filename, expectedFilename)
t.is(avaModule.exports, test)
t.is(avaModule.parent, module)
t.is(avaModule.loaded, true)
t.is(avaModule.paths[0], path.join(__dirname, 'node_modules', 'ava', 'node_modules'))
t.truthy(avaModule.children.length)
})
test('returns falsy for system module', (t) => {
t.falsy(whichModule(path))
t.falsy(whichModule(require('fs')))
})
test('returns falsy for non-required', (t) => {
// note that a module may export a boolean (e.g. supports-color)
// or undefined (e.g. lodash/_Reflect.js)
t.falsy(whichModule(t))
t.falsy(whichModule({}))
t.falsy(whichModule(function () {}))
t.falsy(whichModule('foobar'))
t.falsy(whichModule(String))
})