-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.constructor.test.js
70 lines (60 loc) · 1.4 KB
/
index.constructor.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
import tap from 'tap'
import { fileURLToPath } from 'url'
import { dirname as dirnamePath } from 'path'
import CommonESM from './index.js'
const {
__dirname,
__filename,
__isMain,
dirname,
filename,
isMain,
join,
requireJson
} = new CommonESM(import.meta.url)
const ___dirname = dirnamePath(fileURLToPath(import.meta.url))
const ___filename = fileURLToPath(import.meta.url)
tap.test('__dirname', (t) => {
t.equal(
__dirname,
___dirname,
'__dirname should return the current directory'
)
t.end()
})
tap.test('__filename', (t) => {
t.equal(__filename, ___filename, '__filename should return the current file')
t.end()
})
tap.test('__isMain', (t) => {
t.equal(__isMain, true, '__isMain should return true')
t.end()
})
tap.test('dirname()', (t) => {
t.equal(dirname(), ___dirname, 'dirname should return the current directory')
t.end()
})
tap.test('filename()', (t) => {
t.equal(filename(), ___filename, 'filename should return the current file')
t.end()
})
tap.test('isMain()', (t) => {
t.equal(isMain(), true, 'isMain should return true')
t.end()
})
tap.test('join()', (t) => {
t.equal(
join('a', 'b', 'c'),
`${___dirname}/a/b/c`,
'join should join the given paths'
)
t.end()
})
tap.test('requireJson()', (t) => {
t.equal(
requireJson('./package.json').name,
'@uscreen.de/common-esm',
'requireJson should require a JSON file'
)
t.end()
})