Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Command Hooks to Custom Runners #5212

Closed
azz opened this issue Jan 3, 2018 · 9 comments
Closed

Add Command Hooks to Custom Runners #5212

azz opened this issue Jan 3, 2018 · 9 comments

Comments

@azz
Copy link
Contributor

azz commented Jan 3, 2018

Do you want to request a feature or report a bug?

Feature.


When running Jest with jest-runner-eslint in watch mode, I'm often presented with this:

image

Note that the plugin (via the ESLint default formatter) suggests passing --fix to correct this error. This is true if you are using the ESLint CLI, but as this workflow integrates deeply with Jest, you either need to:

  • Run the runner with a separate configuration for "fixing" code.
    (e.g. jest -c jest.eslint-fix.config.js)
  • Run eslint . --fix separately. (Which may require re-stating CLI flags such as --ignore-path)

Neither of these workflows are particularly nice.

There are two possible solutions that I can think of:

  1. Overload the -u key to update the file instead of the snapshot.
  2. Allow the runner to contribute new commands.

A quick sketch of what the latter might look like follows:

Runner API Sketch

onResult(test, {
  ...testResult,
  commands: [{
    key: 'f',
    description: 'run eslint --fix',
    action: () => {
      fix(test.name);
    }
  }]
});

CLI Usage

jest --executeRunnerCommands f -c jest.eslint.config.js

--watch Usage

› Press f to run eslint --fix

Thoughts on this workflow?

@azz azz changed the title Expose "fix" Hook to Custom Runners Add Command Hooks to Custom Runners Jan 3, 2018
@cpojer
Copy link
Member

cpojer commented Jan 3, 2018

Interesting, we should definitely support this workflow. I think your idea about making it so that runners can extend the watch mode with extra commands (using the watch mode plugin API) is great, we should go for that, and also move u to the jest-runner. This may have some implications to Jest’s config object.

The only things that worry me here is that I’m unsure how we could also support this from the command line using the same API. Do you have any ideas for this?

@azz
Copy link
Contributor Author

azz commented Jan 3, 2018

I'm thinking it would work exactly the same as snapshot updates. If the right CLI flag is specified, and a test result returns an actionable command, then that command is immediately executed.

So the following two commands would be the same:

jest --updateSnapshot
jest --executeRunnerCommands u

One could run --fix and update snapshots with jest --executeRunnerCommands u,f.

Maybe we'd need an API to re-run that test post the command being executed, or to dismiss the failed status of a test?

@cpojer
Copy link
Member

cpojer commented Jan 3, 2018

Yeah, I think that works for me, even though the flag is quite long. I’m fine with —updateSnapshot being special cased as it is a core Jest feature.

@azz
Copy link
Contributor Author

azz commented Jan 3, 2018

Could always add an alias like -x

@cpojer
Copy link
Member

cpojer commented Jan 3, 2018

Yeah this approach sounds good to me.

@azz
Copy link
Contributor Author

azz commented May 31, 2018

I think this is mostly closed off by #5212 🎉

@SimenB
Copy link
Member

SimenB commented Jun 1, 2018

Links to 5212 :p What did you intend to link to?

@azz
Copy link
Contributor Author

azz commented Jun 2, 2018

Oops, #5399.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants