Skip to content

Let stdin be passed through to jest-cli #5017

@seanpoulter

Description

@seanpoulter

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

What is the current behavior?
When Jest runs in watch mode, jest-cli only listens for input from text terminals that send characters one at a time in "raw mode". This dependency on tty.ReadStream#setReadMode in jest/packages/jest-cli/src/watch.js prevents anyone who's spawned Jest as a child process from interacting with the watcher (e.g.: IDE extensions like vscode-jest).

What is the expected behaviour?
How do you feel about using setRawMode when it's available, and letting whatever data through if a feature toggle is set (e.g.: a CLI arg or process.env)? Any thoughts on the feature toggle?

Suggested change:
From:

  if (typeof stdin.setRawMode === 'function') {
    stdin.setRawMode(true);
    stdin.resume();
    stdin.setEncoding('hex');
    stdin.on('data', onKeypress);
  }

To:

  const useRawInput = typeof stdin.setRawMode === 'function';

  if (useRawInput) {
    stdin.setRawMode(true);
  }
  if (useRawInput || roughEdgeFeatureToggle) {
    stdin.resume();
    stdin.setEncoding('hex');
    stdin.on('data', onKeypress);
  }

On my end it's the lowest overhead of:

  • using stdin that's piped in
  • kill/respawn Jest processes when things in the "globalConfig" change
  • refactor watch.js to extract the dependency on input method

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions