Skip to content

Commit

Permalink
fix(bytesToSize): Change it to return "0 Bytes" if bytes is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
abetomo committed Sep 29, 2021
1 parent b682de6 commit 2640d95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/__tests__/google-drive-cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('GoogleDriveCleaner', () => {

test('bytesToSize()', () => {
const tests = [{
expected: 'n/a',
expected: '0 Bytes',
actual: 0
}, {
expected: '10 Bytes',
Expand All @@ -97,6 +97,12 @@ describe('GoogleDriveCleaner', () => {
}, {
expected: '10.3 TB',
actual: 1024 * 1024 * 1024 * 1024 * 10.3
}, {
expected: '0 Bytes',
actual: '0' // string
}, {
expected: '10 Bytes',
actual: '10' // string
}]
tests.forEach(test => {
expect(googleDriveCleaner.bytesToSize(test.actual)).toBe(test.expected)
Expand Down
2 changes: 1 addition & 1 deletion lib/google-drive-cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GoogleDriveCleaner {
bytesToSize (bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
bytes = Number(bytes)
if (bytes === 0) return 'n/a'
if (bytes === 0) return '0 Bytes'
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
if (Number.isNaN(i)) return i
if (i === 0) return `${bytes} ${sizes[i]}`
Expand Down

0 comments on commit 2640d95

Please sign in to comment.