@@ -411,20 +411,20 @@ describe('Test importing files from hex.', () => {
411411 addIntelHexFileSpy . mockReset ( ) ;
412412 } ) ;
413413
414- const hexStrWithFiles = ( ) : string => {
414+ const createHexStrWithFiles = ( ) : string => {
415415 const fullUpyFsMemMap = MemoryMap . fromHex ( uPyHexFile ) ;
416416 const filesMap = MemoryMap . fromHex ( extraFilesHex ) ;
417417 filesMap . forEach ( ( value : Uint8Array , index : number ) => {
418418 fullUpyFsMemMap . set ( index , value ) ;
419419 } ) ;
420420 return fullUpyFsMemMap . asHexString ( ) ;
421421 } ;
422+ const hexStrWithFiles : string = createHexStrWithFiles ( ) ;
422423
423424 it ( 'Correctly read files from a hex.' , ( ) => {
424- const hexWithFiles = hexStrWithFiles ( ) ;
425425 const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
426426
427- const fileList = micropythonFs . importFilesFromIntelHex ( hexWithFiles ) ;
427+ const fileList = micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
428428
429429 Object . keys ( extraFiles ) . forEach ( ( filename ) => {
430430 expect ( fileList ) . toContain ( filename ) ;
@@ -433,53 +433,55 @@ describe('Test importing files from hex.', () => {
433433 } ) ;
434434
435435 it ( 'Disabled overwrite flag throws an error when file exists.' , ( ) => {
436- const hexWithFiles = hexStrWithFiles ( ) ;
437436 const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
438437 const originalFileContent = 'Original file content.' ;
439438 micropythonFs . write ( 'a.py' , originalFileContent ) ;
440439
441440 const failCase = ( ) => {
442- micropythonFs . importFilesFromIntelHex ( hexWithFiles , false ) ;
441+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles , false ) ;
443442 } ;
444443
445444 expect ( failCase ) . toThrow ( Error ) ;
446445 expect ( micropythonFs . read ( 'a.py' ) ) . toEqual ( originalFileContent ) ;
447446 } ) ;
448447
449448 it ( 'Enabled overwrite flag replaces the file.' , ( ) => {
450- const hexWithFiles = hexStrWithFiles ( ) ;
451449 const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
452450 const originalFileContent = 'Original file content.' ;
453451 micropythonFs . write ( 'a.py' , originalFileContent ) ;
454452
455- micropythonFs . importFilesFromIntelHex ( hexWithFiles , true ) ;
453+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles , true ) ;
456454
457455 expect ( micropythonFs . read ( 'a.py' ) ) . not . toEqual ( originalFileContent ) ;
458456 expect ( micropythonFs . read ( 'a.py' ) ) . toEqual ( extraFiles [ 'a.py' ] ) ;
459457 } ) ;
460458
461459 it ( 'By default it throws an error if a filename already exists.' , ( ) => {
462- const hexWithFiles = hexStrWithFiles ( ) ;
463460 const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
464461 micropythonFs . write ( 'a.py' , 'some content' ) ;
465462
466463 const failCase = ( ) => {
467- micropythonFs . importFilesFromIntelHex ( hexWithFiles ) ;
464+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
468465 } ;
469466
470467 expect ( failCase ) . toThrow ( Error ) ;
471468 } ) ;
472469
473470 it ( 'When files are imported it still uses the constructor hex file.' , ( ) => {
474- const hexWithFiles = hexStrWithFiles ( ) ;
475471 const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
476472
477- micropythonFs . importFilesFromIntelHex ( hexWithFiles ) ;
473+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
478474 const returnedIntelHex = micropythonFs . getIntelHex ( ) ;
479475
480476 expect ( addIntelHexFileSpy . mock . calls . length ) . toEqual ( 3 ) ;
481477 expect ( addIntelHexFileSpy . mock . calls [ 0 ] [ 0 ] ) . toBe ( uPyHexFile ) ;
482478 } ) ;
479+
480+ it ( 'Constructor hex file with files to import thorws an error.' , ( ) => {
481+ const failCase = ( ) => new MicropythonFsHex ( hexStrWithFiles ) ;
482+
483+ expect ( failCase ) . toThrow ( Error ) ;
484+ } ) ;
483485} ) ;
484486
485487/*
0 commit comments