Skip to content

Conversation

@sesigl
Copy link
Contributor

@sesigl sesigl commented Oct 21, 2017

Summary

Whenever you run jest --watch in a non git/hq repository you will see the following error:

Determining test suites to run...Error: This promise must be present when running with -o.
    at /path/to/node_modules/jest-cli/build/search_source.js:192:17
    at next (native)
    at step (/path/to/node_modules/jest-cli/build/search_source.js:20:362)
    at /path/to/node_modules/jest-cli/build/search_source.js:20:592
    at /path/to/node_modules/jest-cli/build/search_source.js:20:273
    at SearchSource.getTestPaths (/path/to/node_modules/jest-cli/build/search_source.js:204:10)
    at /path/to/node_modules/jest-cli/build/run_jest.js:45:31
    at next (native)
    at step (/path/to/node_modules/jest-cli/build/run_jest.js:24:380)
    at /path/to/node_modules/jest-cli/build/run_jest.js:24:540

To make it work I would like to do the following:

  1. Warn that there is an issue for non git/hq projects
  2. Execute watchAll instead

Unfortunately the cli/index.js is not tested yet. It's hard to test without restructuring a lot of code to increase testability.

If this solution is not favored I can adapt the change to just update the error message to mention the problem explicit.

There is already a bug report: #4419

Test plan

  1. Create a new node project
  2. Create a simple test file
  3. Run jest --watch
  4. An error occurs

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@SimenB SimenB requested a review from boujeepossum October 21, 2017 08:58
const changedFilesPromise = getChangedFilesPromise(globalConfig, configs);

if (globalConfig.watch && !changedFilesPromise) {
console.log(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually do process.stdout.write, I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

@SimenB
Copy link
Member

SimenB commented Oct 21, 2017

I think this makes sense. Could you add a test? It'd be best to have an integration test, but I don't know if it's possible to write one seeing as the source code is in a repo. A unit test should be possible, though

@sesigl
Copy link
Contributor Author

sesigl commented Oct 21, 2017

I can add some tests using mocks. I don't like to restructure the implementation within this MR.

@boujeepossum
Copy link
Contributor

i'm not sure if we should modify the config, maybe it's better to just crash --watch is not supported without git/hg, please use --watchAll

and yeah, there's no easy way to test watch mode, but you can create an integration test that checks if the process crashes with the correct error.
Unit tests with mocks are usually more trouble than benefit :D

@sesigl
Copy link
Contributor Author

sesigl commented Oct 26, 2017

@aaronabramov thank you for the hint, integration tests makes a lot more sense I think. I also changed the implementation to a simple print out.

import runJest from '../run_jest';
import Runtime from 'jest-runtime';
import TestWatcher from '../test_watcher';
import updateGlobalConfig from '../lib/update_global_config';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint should have yelled at us for leaving this here. It printed it as a warning, not an error

@mjesun
Copy link
Contributor

mjesun commented Nov 7, 2017

📎 hq? Did you mean hg? 😄

@SimenB
Copy link
Member

SimenB commented Nov 8, 2017

@Journerist this breaks the jest repo. ./jest --watch fails. Could you take a look?

@SimenB
Copy link
Member

SimenB commented Nov 8, 2017

This should be reverted or fixed asap, watch is broken in git repos in current beta

@sesigl
Copy link
Contributor Author

sesigl commented Nov 8, 2017

I ll check it right now

@sesigl
Copy link
Contributor Author

sesigl commented Nov 8, 2017

created
sesigl@92da367

But to be honest, it's hard to test in a useful way. I would suggest to revert it for now to avoid hasty mistakes.

@sesigl
Copy link
Contributor Author

sesigl commented Nov 8, 2017

added another MR
#4865

added also some unit tests

@github-actions
Copy link

This pull request 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants