-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: reuse local du.zip #56
Changes from 9 commits
afc6e40
794083b
fb7fb82
945f07c
3116217
4b6b599
f6dfbb8
c74c55d
6e8c3ac
a22c520
b476aa4
09cd0fb
549abbf
8e5a3e0
becab99
b71e1e3
cd746c8
c3a48d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
node_modules/ | ||
bin/ | ||
.nyc_output/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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') | ||
|
||
let workspace = path.join(os.tmpdir(), 'fast-folder-size-playground') | ||
beforeEach(() => { | ||
if (fs.existsSync(workspace)) fs.rmSync(workspace, { recursive: true }) | ||
fs.mkdirSync(workspace) | ||
subject.workspace = workspace | ||
}) | ||
|
||
test('it can use local file path as process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION', t => { | ||
let 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(dummyDuZipPath, tempFilePath) | ||
t.end() | ||
} | ||
|
||
subject.default() | ||
}) | ||
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, error => { | ||
return error.message.startsWith('du.zip not found at') | ||
}) | ||
t.end() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when you don't need to assert asynchronously in callbacks, please write the test function as an async function so you don't have to remember calling t.end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once I added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably just an eslint configuration to support esm, should be easy to address |
||
}) | ||
|
||
test('it can use http(s) url as process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION', t => { | ||
let dummyUrl = 'https://non-exists.localhost/du.zip' | ||
process.env.FAST_FOLDER_SIZE_DU_ZIP_LOCATION = dummyUrl | ||
|
||
subject.downloadDuZip = function (mirror) { | ||
t.equal(dummyUrl, mirror) | ||
DevDengChao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.end() | ||
} | ||
|
||
subject.default() | ||
}) | ||
|
||
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(undefined, mirror) | ||
t.end() | ||
} | ||
|
||
subject.default() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why double slash after the drive name? I assume we're targeting Windows in this case, so shouldn't the path separator be backslash instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's personal habit. I tested the
C://**/du.zip
andC:\**\du.zip
, they both pass the test.Should we add another example like:
or just replace "D://download/du.zip" with "D:\download\du.zip" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just make sure this works on the windows terminal and not an emulator