const utils = require('../../utils')

const load = (files, jsonFiles, jsonContentsDict, annexed, dir) => {
  let issues = []
  const jsonPromises = files.map(function(file) {
    return utils.limit(
      () =>
        new Promise((resolve, reject) => {
          utils.files
            .readFile(file, annexed, dir)
            .then(contents => {
              utils.json.parse(file, contents, function(parseIssues, jsObj) {
                issues = issues.concat(parseIssues)

                // abort further tests if schema test does not pass
                if (issues.some(issue => issue.severity === 'error')) {
                  return reject()
                }

                jsonContentsDict[file.relativePath] = jsObj
                jsonFiles.push(file)
                resolve()
              })
            })
            .catch(issue => {
              issues.push(issue)
              resolve()
            })
        }),
    )
  })
  return new Promise(resolve =>
    Promise.all(jsonPromises)
      .then(() => resolve(issues))
      .catch(() => resolve(issues)),
  )
}

module.exports = load

@@ -31,16 +31,416 @@
 tils')%0A%0A
+function validate(resolve, reject, file, jsonFiles, jsonContentsDict, issues) %7B%0A  return function(parseIssues, jsObj) %7B%0A    issues = issues.concat(parseIssues)%0A%0A    // abort further tests if schema test does not pass%0A    if (issues.some(issue =%3E issue.severity === 'error')) %7B%0A      return reject()%0A    %7D%0A%0A    jsonContentsDict%5Bfile.relativePath%5D = jsObj%0A    jsonFiles.push(file)%0A    resolve()%0A  %7D%0A%7D%0A%0A
 const lo
@@ -778,282 +778,164 @@
 rse(
-file, contents, function(parseIssues, jsObj) %7B%0A                issues = issues.concat(parseIssues)%0A%0A                // abort further tests if schema test does not pass%0A                if (issues.some(issue =%3E issue.severity === 'error')) %7B%0A                  return reject()%0A
+%0A                file,%0A                contents,%0A                validate(%0A                  resolve,%0A                  reject,%0A                  file,%0A    
     
@@ -944,21 +944,29 @@
         
-  %7D%0A%0A
+jsonFiles,%0A  
         
@@ -993,72 +993,35 @@
 Dict
-%5Bfile.relativePath%5D = jsObj%0A                jsonFiles.push(file)
+,%0A                  issues,
 %0A   
@@ -1029,33 +1029,26 @@
             
-resolve(
 )
+,
 %0A           
@@ -1042,33 +1042,32 @@
 ,%0A              
-%7D
 )%0A            %7D)

refactor large function