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

Error when do jest --watch in project with no git or hg #5049

Closed
artiebits opened this issue Dec 11, 2017 · 3 comments
Closed

Error when do jest --watch in project with no git or hg #5049

artiebits opened this issue Dec 11, 2017 · 3 comments

Comments

@artiebits
Copy link
Contributor

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

bug

What is the current behavior?

I created an app using create-react-native-app and ran yarn test that uses jest --watch. And It threw the error:

Determining test suites to run...Error: This promise must be present when running with -o.
    at /Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/search_source.js:202:17
    at Generator.next (<anonymous>)
    at step (/Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/search_source.js:19:362)
    at /Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/search_source.js:19:592
    at new Promise (<anonymous>)
    at /Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/search_source.js:19:273
    at SearchSource.getTestPaths (/Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/search_source.js:216:10)
    at /Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/run_jest.js:44:29
    at Generator.next (<anonymous>)
    at step (/Users/arthurkhusaenov/Codes/AwesomeProject/node_modules/jest-cli/build/run_jest.js:23:380)

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

rm –rf .git in some project that uses Jest. Then jest --watch

What is the expected behavior?

I saw docs https://facebook.github.io/jest/docs/en/cli.html#running-from-the-command-line and found jest --watch runs jest -o by default. So I tried jest -o and I’ve got the clear message:

Jest can only find uncommitted changed files in a git or hg repository. If you make your project a git or hg repository (`git init` or `hg init`), Jest will be able to only run tests related to files changed since the last commit.
No tests found related to files changed since last commit. 

If jest --watch runs jest -o by default then should jest --watch shows the same message in this case?

It happens here https://github.com/facebook/jest/blob/master/packages/jest-cli/src/run_jest.js#L45

if (!data.tests.length && globalConfig.onlyChanged && data.noSCM) {
  if (globalConfig.watch) {
    data = await source.getTestPaths(globalConfig);
  } else {
    new Console(outputStream, outputStream).log(
      'Jest can only find uncommitted changed files in a git or hg ' +
        'repository. If you make your project a git or hg ' +
        'repository (`git init` or `hg init`), Jest will be able ' +
        'to only run tests related to files changed since the last ' +
        'commit.',
    );
  }
}

In first if statement it's true && true && true and here if (globalConfig.watch) it’s also true because I use --watch. So I think it should be:

if (!data.tests.length && globalConfig.onlyChanged && data.noSCM) {
  new Console(outputStream, outputStream).log(
    'Jest can only find uncommitted changed files in a git or hg ' +
      'repository. If you make your project a git or hg ' +
      'repository (`git init` or `hg init`), Jest will be able ' +
      'to only run tests related to files changed since the last ' +
      'commit.',
  );
}

But what do you think guys, can I change that or I missed something?

@thymikee
Copy link
Collaborator

IMO we should remove this branch, as we don't support --watch inside non-version-controlled environments. Feel free to send a PR fixing that :)

@thymikee
Copy link
Collaborator

Closed via #5060

@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants