-
Notifications
You must be signed in to change notification settings - Fork 10
/
get-sysinternals-du.test.js
88 lines (70 loc) · 2.28 KB
/
get-sysinternals-du.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
if (process.platform !== 'win32') {
// these test cases are only for win32
return
}
const { test, beforeEach } = require('tap')
const path = require('path')
const os = require('os')
const fs = require('fs')
const subject = require('./get-sysinternals-du.js')
const workspace = path.join(os.tmpdir(), 'fast-folder-size-playground')
beforeEach(() => {
if (fs.existsSync(workspace)) fs.rmSync(workspace, { recursive: true })
fs.mkdirSync(workspace)
})
test('it can use local file path as process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION', t => {
t.test('C:\\**\\du.zip', t => {
const dummyDuZipPath = path.join(workspace, 'dummy-du.zip')
fs.writeFileSync(dummyDuZipPath, '')
process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION = dummyDuZipPath
subject.onDuZipDownloaded = function (tempFilePath) {
t.equal(tempFilePath, dummyDuZipPath)
t.end()
}
subject.default(workspace)
})
t.test('C://**/du.zip', t => {
const dummyDuZipPath = path
.join(workspace, 'dummy-du.zip')
.replaceAll('\\', '/')
.replace(':/', '://')
fs.writeFileSync(dummyDuZipPath, '')
process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION = dummyDuZipPath
subject.onDuZipDownloaded = function (tempFilePath) {
t.equal(tempFilePath, dummyDuZipPath)
t.end()
}
subject.default(workspace)
})
t.end()
})
test('it cannot use non-exists local file path as process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION', t => {
process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION = path.join(
workspace,
'non-exists-dummy-du.zip'
)
t.throws(
() => subject.default(workspace),
error => {
return error.message.startsWith('du.zip not found at')
}
)
t.end()
})
test('it can use http(s) url as process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION', t => {
const dummyUrl = 'https://non-exists.localhost/du.zip'
process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION = dummyUrl
subject.downloadDuZip = function (mirror) {
t.equal(mirror, dummyUrl)
t.end()
}
subject.default(workspace)
})
test('when process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION not found, then download it directly', t => {
delete process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION
subject.downloadDuZip = function (mirror) {
t.equal(mirror, undefined)
t.end()
}
subject.default(workspace)
})