File: test.js

package info (click to toggle)
node-which-module 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 96 kB
  • sloc: javascript: 43; sh: 2; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download | duplicates (3)
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
import test from 'ava'
import whichModule from './'
import path from '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))
})