-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
37 lines (34 loc) · 1.28 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
var name = require('./')
var test = require('tape')
test('gets the package name for a require statement', function(t) {
t.equal(name(''), null)
t.equal(name('tape/index.js'), 'tape')
t.equal(name('tape/'), 'tape')
t.equal(name('tape'), 'tape')
t.equal(name('tape/foo/bar/index.js'), 'tape')
t.equal(name('tape/foo/bar/index'), 'tape')
t.equal(name('tape/foo/bar/'), 'tape')
t.equal(name('tape/foo/bar'), 'tape')
t.equal(name('tape///foo/bar'), 'tape', 'handles extra slashes')
//scopes
t.equal(name('@user/home'), '@user/home')
t.equal(name('@user/home/'), '@user/home')
t.equal(name('@user/home/foo.js'), '@user/home')
t.equal(name('@user//foobar'), '@user/foobar')
t.equal(name('@user'), null)
t.equal(name('@user/'), null)
t.equal(name('@user//'), null)
//base name
t.equal(name.base('tape/foo/bar/index'), 'tape')
t.equal(name.base('tape/foo/bar/index'), 'tape')
t.equal(name.base('tape/foo/bar/'), 'tape')
t.equal(name.base('some-module'), 'some-module')
t.equal(name.base('@user/home'), 'home')
t.equal(name.base('@user/home/'), 'home')
t.equal(name.base('@user/home/foo.js'), 'home')
t.equal(name.base('@user//foobar'), 'foobar')
t.equal(name.base('@user'), null)
t.equal(name.base('@user/'), null)
t.equal(name.base('@user//'), null)
t.end()
})