@@ -536,6 +536,14 @@ describe('Test importing files from hex.', () => {
536
536
} ) ;
537
537
} ) ;
538
538
539
+ it ( 'Throws and error if there are no files to import.' , ( ) => {
540
+ const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
541
+
542
+ const failCase = ( ) => micropythonFs . importFilesFromIntelHex ( uPyHexFile ) ;
543
+
544
+ expect ( failCase ) . toThrow ( 'Hex does not have any files to import' ) ;
545
+ } ) ;
546
+
539
547
it ( 'Disabled overwrite flag throws an error when file exists.' , ( ) => {
540
548
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
541
549
const originalFileContent = 'Original file content.' ;
@@ -573,15 +581,6 @@ describe('Test importing files from hex.', () => {
573
581
expect ( failCase ) . toThrow ( Error ) ;
574
582
} ) ;
575
583
576
- it ( 'When files are imported it still uses the constructor hex file.' , ( ) => {
577
- const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
578
-
579
- micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
580
- const returnedIntelHex = micropythonFs . getIntelHex ( ) ;
581
-
582
- expect ( generateHexWithFilesSpy . mock . calls . length ) . toEqual ( 1 ) ;
583
- } ) ;
584
-
585
584
it ( 'Constructor hex file with files to import throws an error.' , ( ) => {
586
585
const failCase = ( ) => new MicropythonFsHex ( hexStrWithFiles ) ;
587
586
@@ -606,6 +605,23 @@ describe('Test importing files from hex.', () => {
606
605
expect ( micropythonFs . ls ( ) ) . not . toContain ( 'old_file.py' ) ;
607
606
} ) ;
608
607
608
+ it ( 'Enabling formatFirst flag only formats if there are files to import.' , ( ) => {
609
+ const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
610
+ micropythonFs . write ( 'old_file.py' , 'Some content.' ) ;
611
+
612
+ try {
613
+ const fileList = micropythonFs . importFilesFromIntelHex ( uPyHexFile , {
614
+ overwrite : false ,
615
+ formatFirst : true ,
616
+ } ) ;
617
+ } catch ( e ) {
618
+ // Not having files to import should raise an error
619
+ }
620
+
621
+ expect ( micropythonFs . ls ( ) ) . toContain ( 'old_file.py' ) ;
622
+ expect ( micropythonFs . read ( 'old_file.py' ) ) . toContain ( 'Some content.' ) ;
623
+ } ) ;
624
+
609
625
it ( 'Disabling formatFirst flag, and by default, keeps old files.' , ( ) => {
610
626
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
611
627
micropythonFs . write ( 'old_file.py' , 'Some content.' ) ;
0 commit comments