Skip to content

Add Command Hooks to Custom Runners #5212

@azz

Description

@azz

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions