@@ -3,42 +3,47 @@ const sh = require('shelljs');
33import test from 'ava' ;
44import fileBytes from './' ;
55
6+ function getRand ( ) {
7+ const min = 0 ;
8+ const max = 99999999999999999999 ;
9+ return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
10+ }
11+
612test ( 'invalid args sync' , t => {
713 t . throws ( ( ) => {
814 fileBytes . sync ( 'invalidFileName.txt' ) ;
9- } , Error ) ;
15+ } , / E N O E N T / ) ;
1016} ) ;
1117
1218test ( 'empty file sync' , t => {
13- sh . touch ( 'empty.txt' ) ;
14- t . is ( fileBytes . sync ( 'empty.txt' ) , 0 ) ;
15- t . is ( typeof fileBytes . sync ( 'empty.txt' ) , 'number' ) ;
16- sh . rm ( 'empty.txt' ) ;
19+ const file = `empty${ getRand ( ) } .txt` ;
20+ sh . touch ( file ) ;
21+ t . is ( fileBytes . sync ( file ) , 0 ) ;
22+ t . is ( typeof fileBytes . sync ( file ) , 'number' ) ;
23+ sh . rm ( file ) ;
1724} ) ;
1825
1926test ( 'small file sync' , t => {
20- fs . writeFileSync ( 'small.txt' , '0123456789' ) ;
21- t . is ( fileBytes . sync ( 'small.txt' ) , 10 ) ;
22- sh . rm ( 'small.txt' ) ;
27+ const file = `small${ getRand ( ) } .txt` ;
28+ fs . writeFileSync ( file , 'four' ) ;
29+ t . is ( fileBytes . sync ( file ) , 4 ) ;
30+ sh . rm ( file ) ;
2331} ) ;
2432
25- test ( 'invalid args promise' , async t => {
26- try {
27- await fileBytes ( 'invalidFileName.txt' ) ;
28- t . fail ( 'Exception was not thrown' ) ;
29- } catch ( err ) {
30- t . truthy ( err ) ;
31- }
33+ test ( 'invalid args promise' , t => {
34+ t . throws ( fileBytes ( 'invalidFileName' ) , / E N O E N T / ) ;
3235} ) ;
3336
3437test ( 'empty file promise' , async t => {
35- sh . touch ( 'empty.txt' ) ;
36- t . is ( await fileBytes ( 'empty.txt' ) , 0 ) ;
37- sh . rm ( 'empty.txt' ) ;
38+ const file = `empty${ getRand ( ) } .txt` ;
39+ sh . touch ( file ) ;
40+ t . is ( await fileBytes ( file ) , 0 ) ;
41+ sh . rm ( file ) ;
3842} ) ;
3943
4044test ( 'small file promise' , async t => {
41- fs . writeFileSync ( 'small.txt' , '0123456789' ) ;
42- t . is ( await fileBytes ( 'small.txt' ) , 10 ) ;
43- sh . rm ( 'small.txt' ) ;
45+ const file = `small${ getRand ( ) } .txt` ;
46+ fs . writeFileSync ( file , 'four' ) ;
47+ t . is ( await fileBytes ( file ) , 4 ) ;
48+ sh . rm ( file ) ;
4449} ) ;
0 commit comments