Repository: FHIR/sushi (ts)

Issue:
SUSHI should not log errors when it finds non-XML/JSON files in resource folders
See: https://chat.fhir.org/#narrow/stream/215610-shorthand/topic/sushi.20beta.20error

Pull request description:
Only log info (not error) for non-xml/json files in resource folders
Fixes #641

Patch:
diff --git a/src/fhirdefs/load.ts b/src/fhirdefs/load.ts
index e0f7a25..e39946f 100644
--- a/src/fhirdefs/load.ts
+++ b/src/fhirdefs/load.ts
@@ -187,8 +187,8 @@ export function loadCustomResources(resourceDir: string, defs: FHIRDefinitions):
     'examples'
   ];
   const converter = new FHIRConverter();
+  let invalidFileCount = 0;
   for (const pathEnd of pathEnds) {
-    let invalidFile = false;
     let foundSpreadsheets = false;
     const dirPath = path.join(resourceDir, pathEnd);
     if (fs.existsSync(dirPath)) {
@@ -212,7 +212,7 @@ export function loadCustomResources(resourceDir: string, defs: FHIRDefinitions):
             }
             resourceJSON = converter.xmlToObj(xml);
           } else {
-            invalidFile = true;
+            invalidFileCount++;
             continue;
           }
         } catch (e) {
@@ -229,17 +229,19 @@ export function loadCustomResources(resourceDir: string, defs: FHIRDefinitions):
         }
       }
     }
-    if (invalidFile) {
-      logger.error(
-        `Invalid file detected in directory ${dirPath}. Input FHIR definitions must be JSON or XML.`
-      );
-    }
     if (foundSpreadsheets) {
       logger.info(
         `Found spreadsheets in directory ${dirPath}. SUSHI does not support spreadsheets, so any resources in the spreadsheets will be ignored.`
       );
     }
   }
+  if (invalidFileCount > 0) {
+    logger.info(
+      invalidFileCount > 1
+        ? `Found ${invalidFileCount} files in input/* resource folders that were neither XML nor JSON. These files were not processed as resources by SUSHI.`
+        : `Found ${invalidFileCount} file in an input/* resource folder that was neither XML nor JSON. This file was not processed as a resource by SUSHI.`
+    );
+  }
 }
 
 /**


Test patch:
diff --git a/test/fhirdefs/load.test.ts b/test/fhirdefs/load.test.ts
index a236529..fcf477d 100644
--- a/test/fhirdefs/load.test.ts
+++ b/test/fhirdefs/load.test.ts
@@ -316,6 +316,7 @@ describe('#loadDependency()', () => {
 describe('#loadCustomResources', () => {
   let defs: FHIRDefinitions;
   beforeAll(() => {
+    loggerSpy.reset();
     defs = new FHIRDefinitions();
     const fixtures = path.join(
       __dirname,
@@ -367,12 +368,14 @@ describe('#loadCustomResources', () => {
     expect(defs.getPredefinedResource('ValueSet-MyVS.json').id).toBe('MyVS');
   });
 
-  it('should log an error for non JSON or XML input files', () => {
-    expect(loggerSpy.getMessageAtIndex(-1, 'error')).toMatch(/Invalid file.*resources/);
+  it('should log an info message for non JSON or XML input files', () => {
+    expect(loggerSpy.getLastMessage('info')).toMatch(
+      /Found 1 file in an input\/\* resource folder that was neither XML nor JSON/
+    );
   });
 
   it('should log an error for invalid XML files', () => {
-    expect(loggerSpy.getMessageAtIndex(-2, 'error')).toMatch(
+    expect(loggerSpy.getLastMessage('error')).toMatch(
       /Loading InvalidFile.xml failed with the following error:/
     );
   });
@@ -392,11 +395,11 @@ describe('#loadCustomResources', () => {
   });
 
   it('should log an info message when it finds spreadsheets', () => {
-    expect(loggerSpy.getLastMessage('info')).toMatch(/Found spreadsheets in directory/);
+    expect(loggerSpy.getFirstMessage('info')).toMatch(/Found spreadsheets in directory/);
   });
 
   it('should log an error for invalid JSON files', () => {
-    expect(loggerSpy.getMessageAtIndex(-3, 'error')).toMatch(
+    expect(loggerSpy.getMessageAtIndex(-2, 'error')).toMatch(
       /Loading InvalidFile.json failed with the following error:/
     );
   });