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

Regression: Jest 26 spec tests - runner process never stops after test exception #3973

Closed
ubergeoff opened this issue Oct 26, 2020 · 19 comments
Assignees
Labels
blocked: repro needed outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@ubergeoff
Copy link

ubergeoff commented Oct 26, 2020

Current Behavior

Previously - before the update that introduced Jest 26 - missing dependency were outlined within the spec tests very nicely/clearly.

But now: Post - Jest 26 update:

  1. After the test fails: The process never stop running - and you now have to force kill the tests.
  2. We now get these "unclear" errors. I.e. errors provided have become very opaque. Example:
[DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:28824) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'element' -> object with constructor 'Object'
    |     property 'componentProvider' -> object with constructor 'Object'
    --- property 'parent' closes the circle

Expected Behavior

In the versions prior to Jest 26 - the error was much, much clearer - and pointed to the exact issue at hand:

NullInjectorError: StaticInjectorError(DynamicTestModule)[HttpClient]:
      StaticInjectorError(Platform: core)[HttpClient]:
        NullInjectorError: No provider for HttpClient!

I feel this is regression as we now - have to "guess" what is missing from the tests - this leads to a much worse DX :(

Steps to Reproduce

Create a simple service that has a simple dependency on something. Example: ensure your service has DI of: HttpClient in it.

Example:

export class NetflixService implements MovieProvider {
  constructor(private http: HttpClient) {

Inject this "new" service into your component.

Run your component spec test - without mocking out any of your dependency.

Failure Logs

(node:25892) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will termin
ate the Node.js process with a non-zero exit code.
(node:28824) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'element' -> object with constructor 'Object'
    |     property 'componentProvider' -> object with constructor 'Object'
    --- property 'parent' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (internal/child_process/serialization.js:117:20)
    at process.target._send (internal/child_process.js:779:17)
    at process.target.send (internal/child_process.js:677:19)
    at reportSuccess (C:\nrwl_10\node_modules\jest-runner\node_modules\jest-worker\build\workers\processChild.js:67:11)
(node:28824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a
 catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI fla
g `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will termin
ate the Node.js process with a non-zero exit code.

However - this should actually show me something like:

NullInjectorError: StaticInjectorError(DynamicTestModule)[HttpClient]:
      StaticInjectorError(Platform: core)[HttpClient]:
        NullInjectorError: No provider for HttpClient!

Environment

"dependencies": {
    "@angular/animations": "^10.1.3",
    "@angular/common": "^10.1.3",
    "@angular/compiler": "^10.1.3",
    "@angular/core": "^10.1.3",
    "@angular/forms": "^10.1.3",
    "@angular/platform-browser": "^10.1.3",
    "@angular/platform-browser-dynamic": "^10.1.3",
    "@angular/router": "^10.1.3",
    "@nrwl/angular": "10.3.1",
    "core-js": "^2.5.4",
    "rxjs": "~6.5.5",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.3",
    "@angular-devkit/build-ng-packagr": "~0.1001.3",
    "@angular/cli": "~10.1.3",
    "@angular/compiler-cli": "^10.1.3",
    "@angular/language-service": "^10.1.3",
    "@nrwl/cli": "10.3.1",
    "@nrwl/cypress": "10.3.1",
    "@nrwl/jest": "10.3.1",
    "@nrwl/workspace": "10.3.1",
    "@types/jest": "26.0.8",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "cypress": "4.12.1",
    "dotenv": "6.2.0",
    "jest": "26.2.2",
    "jest-preset-angular": "8.3.1",
    "ng-packagr": "^10.1.0",
    "prettier": "2.1.2",
    "ts-jest": "26.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.3"
  }
@ubergeoff ubergeoff changed the title Regression: Jest 26 spec tests - Dependency injection errors/warnings Regression: Jest 26 spec tests - Dependency injection errors no longer descriptive Oct 26, 2020
@ubergeoff
Copy link
Author

ubergeoff commented Oct 28, 2020

I can confirm that by adding --detectOpenHandles this will stop the test and display the correct error at hand (as described above).

Example: ng test some-lib --detectOpenHandles

However - this "extra" flag was not required before 10.3.0

@nrwl team: Please could you let us know your thoughts on this issue..? As this adds complications to the testing DX.

@willydee
Copy link

willydee commented Nov 2, 2020

--detectOpenHandles is usable when debugging; however, it implies --runInBand and therefore has a huge performance impact.

@ubergeoff
Copy link
Author

@willydee - agreed - furthermore I'm just curious what the @nrwl team thinks about this "issue" - if they think it is a serious issue or not.

As I feel it is quite problematic - as testing is super critical to any organization.

@ubergeoff ubergeoff changed the title Regression: Jest 26 spec tests - Dependency injection errors no longer descriptive Regression: Jest 26 spec tests - runner process never stops after test exception Nov 3, 2020
@ranemloc
Copy link

ranemloc commented Nov 4, 2020

Agree with @ubergeoff

We are experiencing this same issue for a while in our project with 100+ libraries and it is really doing our lives a bit more miserable. Not just the real error is hidden, but also the tests will continue running forever, what leads to many builds hanging until the Jenkins job times out and gets killed.

@ubergeoff
Copy link
Author

Hi there @FrozenPandaz - any thoughts on the above issues..?

@FrozenPandaz FrozenPandaz added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Nov 6, 2020
@Lonli-Lokli
Copy link

I believe that's related to jestjs/jest#10577

@Lonli-Lokli
Copy link

@FrozenPandaz Related Jest issue has been closed, does it make sense to check and pin to the latest Jest?
If so, can it be done for both v10 and v11?

@Cammisuli
Copy link
Member

If the Jest fix is part of the 26 release, you should just be able to update the workspace version of Jest and that's it.

If something related to Nx doesn't work (like not being to run nx test <project>) then we would need to update the dependencies everywhere.

@ubergeoff
Copy link
Author

ubergeoff commented Jan 15, 2021

Just an update: I updated to latest Jest dependencies:

"jest": "26.6.3",
"ts-jest": "26.4.4",
"jest-preset-angular": "8.3.2",

The test runner process still does not stop. i.e. Process does not end when error is found.

Still getting:

(node:23408) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'element' -> object with constructor 'Object'
    |     property 'componentProvider' -> object with constructor 'Object'
    --- property 'parent' closes the circle

@JamesHenry
Copy link
Collaborator

JamesHenry commented Feb 4, 2021

FYI if it is down to that same jest issue you linked to above (jestjs/jest#10577) then it's worth noting that there has not been a single Jest release since the fix for that was merged - I don't know why that is the case.

Therefore there is currently no version of Jest on npm that has the fix available

@ubergeoff
Copy link
Author

Thanks @JamesHenry - might be that Jest team are a bit too busy with Jest 27..?

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Mar 29, 2021
@Lonli-Lokli
Copy link

Its not stale, bot.

@github-actions github-actions bot removed the stale label Mar 29, 2021
@TicTak21
Copy link

This also happens with jest v27:

TypeError: Converting circular structure to JSON
        --> starting at object with constructor 'Object'
        |     property 'element' -> object with constructor 'Object'
        |     property 'componentProvider' -> object with constructor 'Object'
        --- property 'parent' closes the circle
        at stringify (<anonymous>)
"@nrwl/angular": "12.9.0",
"jest": "27.0.3",
"jest-preset-angular": "9.0.7",
"ts-jest": "27.0.3",
"typescript": "4.3.5"

@barbados-clemens
Copy link
Contributor

Hi there is this still an issue with the latest version of nx? I see the related jest issue is still open as well but wanted to see we can close this issue or not 😄

@barbados-clemens barbados-clemens self-assigned this Feb 18, 2022
@barbados-clemens
Copy link
Contributor

if this is still an issue please provide a minimal git repo with the issue thanks!

@ubergeoff
Copy link
Author

ubergeoff commented May 23, 2022

Much has changed since I first posted this issue.

I have no longer come across this this issue and I am unable to reproduce using:

"jest": "27.5.1",
"jest-preset-angular": "11.1.1",
"ts-jest": "27.1.4",

On my side - I am happy to close...

@JamesHenry
Copy link
Collaborator

Thanks for confirming @ubergeoff!

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: repro needed outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

9 participants