-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file extension handling (#57)
* Add a fileName util to generate a file name from a File object This factorize the 'choosing png or html' logic into one place. Add unit tests as well. * use the fileName util where possible * PR feedback * typo * Bump version number Co-authored-by: Basile Simon <basile@basilesimon.fr>
- Loading branch information
1 parent
eaff96f
commit 6978004
Showing
5 changed files
with
91 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as File from './File'; | ||
|
||
describe('id', () => { | ||
it('should return the file hash', () => { | ||
const hash = 'I should have been a pair of ragged claws'; | ||
expect(File.id({ kind: 'one_file', hash })).toBe(hash); | ||
}); | ||
}); | ||
|
||
describe('fileName', () => { | ||
it('should generate the file name by adding the correct extention to the hash', () => { | ||
const cases: Array<File.File & { expected: string }> = [ | ||
{ hash: 'The gate is straight', kind: 'one_file', expected: 'html' }, | ||
{ hash: 'Deep and wide', kind: 'screenshot', expected: 'png' }, | ||
{ | ||
hash: 'Break on through to the other side', | ||
kind: 'screenshot_thumbnail', | ||
expected: 'png', | ||
}, | ||
]; | ||
|
||
cases.forEach(c => { | ||
expect(File.fileName(c)).toBe(`${c.hash}.${c.expected}`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters