Skip to content

Flexibility in GithubActionsReporter #8008

@reteps

Description

@reteps

Clear and concise description of the problem

  • Our project runs vitest in CI, and the file paths it reports don't line up with GitHub.

Suggested solution

  • A config option for GithubActionsReporter to customize the path prefix it outputs (maybe a transform function)

Alternative

export class CustomGithubReporter extends GithubActionsReporter {
  override onInit(ctx: Vitest) {
    /**
     * GitHub expects that when formatting an error message, the filename is relative to the project root.
     * Since we run in a Docker container for CI, we need to ensure that the filename matches what GitHub expects.
     * https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
     */
    super.onInit(ctx);
    const origLog = this.ctx.logger.log;
    this.ctx.logger.log = (...args: any[]) => {
      if (args.length === 1) {
        args[0] = args[0].replaceAll(/(file=)\/PrairieLearn\//g, '$1');
      }

      origLog.call(this.ctx.logger, ...args);
    };
  }
}

Additional context

N/A

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    P2 - 2

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions