github-actions-reporter.js 1009 B

123456789101112131415161718192021222324252627282930313233343536
  1. class GithubActionsReporter {
  2. constructor(globalConfig, options) {
  3. this._globalConfig = globalConfig
  4. this._options = options
  5. }
  6. onRunComplete(contexts, results) {
  7. results.testResults.forEach((testResultItem) => {
  8. const testFilePath = testResultItem.testFilePath
  9. testResultItem.testResults.forEach((result) => {
  10. if (result.status !== 'failed') {
  11. return
  12. }
  13. result.failureMessages.forEach((failureMessages) => {
  14. const newLine = '%0A'
  15. const message = failureMessages.replace(/\n/g, newLine)
  16. const captureGroup = message.match(/:([0-9]+):([0-9]+)/)
  17. if (!captureGroup) {
  18. console.log('Unable to extract line number from call stack')
  19. return
  20. }
  21. const [, line, col] = captureGroup
  22. console.log(
  23. `::error file=${testFilePath},line=${line},col=${col}::${message}`,
  24. )
  25. })
  26. })
  27. })
  28. }
  29. }
  30. module.exports = GithubActionsReporter