{"record":{"id":"74bc45b4f30f9046","repo":"evanw/esbuild","slug":"duplicated-test-name-name-in-file","errorCode":null,"errorMessage":"Duplicated test name \"${name}\" in ${file}","messagePattern":"Duplicated test name \"(.+?)\" in (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/terser-tests.js","lineNumber":242,"sourceCode":"function parse_test(file) {\n  var script = fs.readFileSync(file, \"utf8\");\n  // TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348\n  try {\n    var ast = U.parse(script, {\n      filename: file\n    });\n  } catch (e) {\n    console.log(\"Caught error while parsing tests in \" + file + \"\\n\");\n    console.log(e);\n    throw e;\n  }\n  var tests = {};\n  var tw = new U.TreeWalker(function (node, descend) {\n    if (node instanceof U.AST_LabeledStatement\n      && tw.parent() instanceof U.AST_Toplevel) {\n      var name = node.label.name;\n      if (name in tests) {\n        throw new Error('Duplicated test name \"' + name + '\" in ' + file);\n      }\n      tests[name] = get_one_test(name, node.body);\n      return true;\n    }\n    if (!(node instanceof U.AST_Toplevel)) croak(node);\n  });\n  ast.walk(tw);\n  return tests;\n\n  function croak(node) {\n    throw new Error(tmpl(\"Can't understand test file {file} [{line},{col}]\\n{code}\", {\n      file: file,\n      line: node.start.line,\n      col: node.start.col,\n      code: make_code(node, { beautify: false })\n    }));\n  }\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/terser-tests.js#L224-L260","documentation":"In the terser-test parser (scripts/terser-tests.js:241), fixtures are keyed by label names; if two labeled statements at the top level share the same label name, the harness throws 'Duplicated test name'. This prevents ambiguous/overridden tests within a single terser compress fixture file. The quoted name and file identify the collision.","triggerScenarios":"A terser compress fixture file containing two `label_name: { ... }` test cases with the identical label name.","commonSituations":"Copying a test case and forgetting to rename the label; merging fixture files that each used a generic name like `default`; upstream terser adding a name that already exists locally.","solutions":["Rename one of the duplicated labels so each test case in the file is uniquely named.","Regenerate the local `.terser-tests` fixtures from upstream terser to clear stale duplicates."],"exampleFix":"// before — in one fixture file\nfoo_test: { ... }\nfoo_test: { ... }\n// after\nfoo_test: { ... }\nfoo_test_2: { ... }","handlingStrategy":"validation","validationCode":"function assertUniqueTestNames(tests: Record<string, any>, file: string): void {\n  const seen = new Set<string>();\n  for (const name in tests) {\n    if (seen.has(name)) throw new Error(`Duplicated test name \"${name}\" in ${file}`);\n    seen.add(name);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use descriptive, unique label names per fixture file.","Regenerate local fixtures from upstream terser to clear stale duplicates."],"tags":["tests","terser","internal","test-tooling","dedup"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}