jest-github-reporter icon indicating copy to clipboard operation
jest-github-reporter copied to clipboard

Create Github Action

Open atifsyedali opened this issue 5 years ago • 16 comments

Would be great if we could use a Github Action instead of the app to push checks.

atifsyedali avatar Nov 21 '19 19:11 atifsyedali

Yes please! I'm playing around with using the built in problem matchers for tsc and eslint, and it works swimmingly: https://github.com/facebook/jest/pull/9223. Would be awesome to just stick an action in for test results as well 👍

SimenB avatar Nov 22 '19 08:11 SimenB

@SimenB are you aware of any existing Problem Matcher for Jest? The Jest output isn't really suitable for parsing using a RegExp or at least not that simple. I was thinking about writing a custom reporter to print a parser friendly output. How does this sound to you?

stefanbuck avatar Jan 07 '20 23:01 stefanbuck

The default jest output is certainly not suited. It should be a separate reporter (an idea might be that GitHub parses junit output?). Could probably reach out to GitHub about it - the js and ts templates they provide use Jest for testing so should be possible to work something out 🙂

SimenB avatar Jan 07 '20 23:01 SimenB

I proposed a similar idea using a json output and xpath https://github.com/actions/toolkit/issues/260.

Internal we use Danger.js to attach the jest output as a PR comment, but using a Problem Matcher would be a much nicer solution

DangerJS screenshot

image

stefanbuck avatar Jan 08 '20 12:01 stefanbuck

Problem matchers are for parsing console output and are run line by line. In you case you want a file and the runner won't when to process the file. One option would be to write an action to process the file and create annotations.

https://github.com/actions/toolkit/issues/260#issuecomment-572807059

Mhhh I'm undecided wether a GitHub Action or a jest reporter that produces a parsable output is the way to go. @SimenB what's your thoughts on this?

stefanbuck avatar Jan 10 '20 11:01 stefanbuck

There shouldn't be an issue to create a reporter that outputs something a problem matcher can parse. I think that's a good idea, as we could ship it by default in Jest and automatically activate it if we detect we're running in github actions? If not, I think GitHub should provide some other built in thing to support lint/test tools etc to just output a file in a given format to a given place, and have GH itself deal with reporting it to the user without having to write a full action

SimenB avatar Jan 10 '20 11:01 SimenB

I tend to prefer a new reporter mainly because it doesn't involve GitHub roadmap prioritization 😉 I'll look into this and keep you updated.

stefanbuck avatar Jan 10 '20 15:01 stefanbuck

I started working on this and the first issue I'm facing is the limitation to a single line for the message field https://github.com/actions/toolkit/issues/319. I guess there is not much we can do from our side to make the output useful in a single line!? Btw, should I raise a feature request in facebook/jest so we can continue the discussion there?

stefanbuck avatar Jan 24 '20 07:01 stefanbuck

@stefanbuck sorry, missed your last message. I still think a dedicated reporter makes more sense than a problem matcher. However, we could probably output some json on a single line per test failure or something - would that be parseable?

SimenB avatar Feb 20 '20 12:02 SimenB

To be honest I think we need both. A reporter which produces a single log line for each failing test and a problem matcher which is able to consume this log format. A problem matcher is just a really slick wrapper around the Checks API which integrates really well into the GitHub UI. What's the alternative to Checks/Problem matchers?

stefanbuck avatar Feb 24 '20 20:02 stefanbuck

@SimenB @atifsyedali @stefanbuck FWIW, I've been using another solution in https://github.com/mattallty/jest-github-action The way it works is:

  • run jest with --testLocationInResults --json --outputFile=jest.results.json
  • then parsing jest.results.json to get failed tests location as well as generating a markdown table of coverage
  • Using the Check API to create annotations, and Issue Comments API to create a comment with coverage data

Seems to work great - I can't just get coverage data when some tests are failing.

mattallty avatar Apr 22 '20 00:04 mattallty

I do something similar with danger.js, but I really want to see this happening with problem matcher so I don't have to maintain another service.

Isn't the check API limited to GitHub Apps?

The Checks API functionality is available exclusively to your GitHub Apps. https://developer.github.com/v3/checks/

stefanbuck avatar Apr 22 '20 06:04 stefanbuck

Any GitHub action has access to an app token so they can make checks. Doesn't that work?

hipstersmoothie avatar Apr 22 '20 06:04 hipstersmoothie

I can confirm it's working

mattallty avatar Apr 22 '20 08:04 mattallty

Looks like the multiline issue I was facing can be solved by url encoding \n https://github.com/actions/toolkit/issues/193#issuecomment-605394935

stefanbuck avatar Apr 22 '20 10:04 stefanbuck

@SimenB I finally made it working

image

I ended up writing a custom reporter which produces an output which is follows a certain pattern. Please checkout this PR for details https://github.com/stefanbuck/jest-matcher/pull/2/files

How should we proceed with this? Do you think it's suitable to make this reporter part of the Jest core and active it whenever a GitHub Action env is detected?

stefanbuck avatar Apr 24 '20 11:04 stefanbuck