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

improve default command creation and messaging #953

Merged
merged 8 commits into from
Nov 26, 2022

Conversation

connectdotz
Copy link
Collaborator

The current default command is quite "shallow", which only looks for candidates in the current project root. And when it did not find it, it should have failed immediately but did not, which led to the process failure later.

deep search

In this PR, we will expand the existing logic by searching deeply from the workspace to find all possible subfolders (folders with package.json) and look for binary/test-script within. Basically, perform a deep auto-config for jest.rootPath and jest.jestCommandLine.

Note, auto-config is a best-effort, it might still require manual setup sometimes, such as:

  • if this is a multi-root monorepo. From the project root, if we find multiple packages with valid jest commands, it can't be decided which one to use for the project root. This will still require converting to the multi-root workspace.
  • yarn pnp will not work as it doesn't have node_modules. Maybe in the future PR we can provide native support for that.

There might be more, but now when the auto-config fails, users will see a clear message showing why jest command is not found, and has an opportunity to fix them (via the "Fix" button in the error panel), hopefully, easily.

favor test script over direct binary execution

This is a breaking change, if user has a jest test script in their package.json, we will use the script (either npm or yarn) instead of jest binary in node_modules.

overhead

This new feature does take a little bit more time at start-up time, but only for users who don't have a shallow jest command.

Notes for Future PRs

@coveralls
Copy link

coveralls commented Nov 25, 2022

Pull Request Test Coverage Report for Build 3545407489

  • 120 of 120 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 97.005%

Totals Coverage Status
Change from base Build 3536361549: 0.01%
Covered Lines: 3273
Relevant Lines: 3315

💛 - Coveralls

@connectdotz connectdotz merged commit d3865e2 into jest-community:master Nov 26, 2022
@connectdotz connectdotz deleted the better-default-command branch November 26, 2022 19:15
legend1202 pushed a commit to legend1202/vscode-jest that referenced this pull request Jun 18, 2023
* fix test block not displaying sometimes

* enhance default jestCommandLine detection and validation

* adding test for changes

* refactor validation logic to use package.json instead of jest config

not all projects have custom jest config. So use package.json as the root instead.

* adding more messaging during auto config

* removing code no longer used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants