GetEmitOutput And Testfiles

You should determine result code  = Succeeded | JSGeneratedWithSemanticErrors | Declaration not generated when you determine shouldEmitDeclarations itself. Only Update the result = hadEmitErrors when  !!diagnostics.length