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

[Bug]: reporter onRunComplete not triggered when jest runner crashed in watch mode #13187

Closed
connectdotz opened this issue Aug 28, 2022 · 5 comments · Fixed by #13203
Closed

Comments

@connectdotz
Copy link
Contributor

Version

28.1.3

Steps to reproduce

  1. clone https://github.com/marr/jest-async-fail
    2. run yarn install
    3. create a simple reporter with onRunComplete and onRunStart methods if you are not using vscode-jest extension in vscode
    4. run jest command: with the custom reporter. For example, with the vscode-jest extension:
    yarn test --watchAll --no-coverage --reporters default --reporters "/your-vscode-extension-path/vscode-jest/out/reporter.js"

you should see something like this:


  ● Test suite failed to run

    Cannot find module 'vue-template-compiler'
    Require stack:
    - /jest-async-fail-main/node_modules/@vue/vue2-jest/lib/process.js
    - /jest-async-fail-main/node_modules/@vue/vue2-jest/lib/index.js
    - /jest-async-fail-main/node_modules/jest-util/build/requireOrImportModule.js
    - /jest-async-fail-main/node_modules/jest-util/build/index.js
    - /jest-async-fail-main/node_modules/jest-config/build/getCacheDirectory.js
    - /jest-async-fail-main/node_modules/jest-config/build/Defaults.js
    - /jest-async-fail-main/node_modules/jest-config/build/normalize.js
    - /jest-async-fail-main/node_modules/jest-config/build/index.js
    - /jest-async-fail-main/node_modules/jest-cli/build/init/index.js
    - /jest-async-fail-main/node_modules/jest-cli/build/cli/index.js
    - /jest-async-fail-main/node_modules/jest-cli/build/index.js
    - /jest-async-fail-main/node_modules/jest-cli/bin/jest.js
    - /jest-async-fail-main/node_modules/jest/bin/jest.js

      at Object.<anonymous> (node_modules/@vue/vue2-jest/lib/process.js:1:29)

onRunStart


Test Suites: 0 of 2 total
Tests:       0 total
Snapshots:   0 total

The onRunComplete, which should output "onRunComplete", is never invoked.

Expected behavior

the reporter should receive onRunComplete callback with at least testResult.testExecError populated.

Actual behavior

reporter onRunComplete was never called.

Additional context

We discovered this issue during the investigation of jest-community/vscode-jest#894. The culprit seems to be in TestScheduler where it catches runner exception and rethrow if it's in watch mode and not interrupted.

It didn't seem right as this resulted in reporters not knowing what is happening: it received the onRunStart but nothing else afterward. It is also inconsistent that other watch mode runs that are always reported with (onRunStart, onRunComplete) pair. It seems we could capture this error in TestResult.testExecError and report it via onRunComplete.

I could write a PR if you agree with the fix.

Environment

System:
    OS: macOS 12.5.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  npmPackages:
    jest: ^28.1.3 => 28.1.3
@connectdotz
Copy link
Contributor Author

After further investigation, the crash occurred even earlier than I originally thought: in createScriptTransformer, right after we dispatched onRunStart...

Basically, there is a situation when runner failed due to any runtime/execError within or prior, it will fail to notify reporters. Does anybody know if that was the intended behavior? If not, I think we can capture those exceptions and report back with the onRunComplete, plus an additional attribute like AggregatedResult.execError, similar to the TestResult.testExecError. Or to be safe and abundantly clear, we can even create a new API Reporter.onRunFail if desired...

Does that make sense? Is there any reason we don't want to do this?

@connectdotz
Copy link
Contributor Author

This issue has prevented us to know that jest run has failed and no results will ever be produced. Since in watch mode, the process will not exit in this situation, our result processing code and reporters will be waiting indefinitely.

@SimenB will you consider accepting a PR for this issue?

@SimenB
Copy link
Member

SimenB commented Aug 30, 2022

Definitely!

@SimenB
Copy link
Member

SimenB commented Sep 10, 2022

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

Successfully merging a pull request may close this issue.

2 participants