import path from 'path'
import utils from '../../utils'
const Issue = utils.issues.Issue
import isNode from '../../utils/isNode'

/*
 * Generates an error for quickTest failures
 */
const quickTestError = function(dir) {
  let filename
  if (isNode) {
    // For Node, grab the path from the dir string
    filename = path.basename(dir)
  } else {
    filename = constructFileName(dir)
  }
  const issue = new Issue({
    code: 61,
    file: {
      name: filename,
      path: path.join('.', filename),
      relativePath: path.join('', filename),
    },
  })
  return issue
}

const constructFileName = dir => {
  let filename
  // Browser side we need to look it up more carefully
  if (dir.length && 'webkitRelativePath' in dir[0]) {
    let wrp = dir[0].webkitRelativePath
    while (wrp.indexOf(path.sep) !== -1) {
      wrp = path.dirname(wrp)
    }
    filename = wrp
  } else {
    // Fallback for non-standard webkitRelativePath
    filename = 'uploaded-directory'
  }
  return filename
}

export default quickTestError

@@ -613,143 +613,24 @@
 %7B%0A  
-let filename%0A  // Browser side we need to look it up more carefully%0A  if (dir.length && 'webkitRelativePath' in dir%5B0%5D)
+try
  %7B%0A    
-let wrp =
+return
  dir
@@ -655,184 +655,59 @@
 Path
-%0A    while (wrp.indexOf(path.sep) !== -1) %7B%0A      wrp = path.dirname(wrp)%0A    %7D%0A    filename = wrp%0A  %7D else %7B%0A    // Fallback for non-standard webkitRelativePath%0A    filename =
+.split(path.sep).pop()%0A  %7D catch (err) %7B%0A    return
  'up
@@ -732,26 +732,8 @@
   %7D%0A
-  return filename%0A
 %7D%0A%0Ae

Fix quickTestError infinite loop when browser variant has unexpected filename structure