-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
51 lines (42 loc) · 1.18 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
const { test } = require('tap')
const crypto = require('crypto')
const fastFolderSize = require('.')
const fastFolderSizeSync = require('./sync')
test('folder size is larger than 0', t => {
fastFolderSize('.', (err, bytes) => {
t.error(err)
t.ok(Number.isFinite(bytes))
t.ok(bytes > 0)
t.end()
})
})
test('folder size is correct', t => {
const writtenBytes = 8 * 1024
const testdirName = t.testdir({
whatever: crypto.randomBytes(writtenBytes),
})
fastFolderSize(testdirName, (err, bytes) => {
t.error(err)
console.log('real size:', writtenBytes, 'found size:', bytes)
t.ok(bytes >= writtenBytes)
t.ok(bytes <= writtenBytes * 1.5)
t.end()
})
})
test('sync: folder size is larger than 0', t => {
const bytes = fastFolderSizeSync('.')
t.ok(Number.isFinite(bytes))
t.ok(bytes > 0)
t.end()
})
test('sync: folder size is correct', t => {
const writtenBytes = 8 * 1024
const testdirName = t.testdir({
whatever: crypto.randomBytes(writtenBytes),
})
const bytes = fastFolderSizeSync(testdirName)
console.log('real size:', writtenBytes, 'found size:', bytes)
t.ok(bytes >= writtenBytes)
t.ok(bytes <= writtenBytes * 1.5)
t.end()
})